addNode.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="add-node-btn-box">
  3. <div class="add-node-btn">
  4. <a-popover v-model:visible="visible" placement="rightTop" trigger="click" :width="270">
  5. <template #content>
  6. <div class="add-node-popover-body">
  7. <ul style="height: 80px">
  8. <li>
  9. <a-button shape="circle" size="large" @click="addType('userTask')">
  10. <template #icon>
  11. <user-outlined style="color: #ff943e; font-size: 18px"/>
  12. </template>
  13. </a-button>
  14. <p>审批节点</p>
  15. </li>
  16. <li>
  17. <a-button shape="circle" size="large" @click="addType('serviceTask')">
  18. <template #icon>
  19. <send-outlined style="color: #3296fa; font-size: 18px"/>
  20. </template>
  21. </a-button>
  22. <p>抄送节点</p>
  23. </li>
  24. <li v-if="addExclusiveGateway">
  25. <a-button shape="circle" size="large" @click="addType('exclusiveGateway')">
  26. <template #icon>
  27. <share-alt-outlined style="color: #15bc83; font-size: 18px"/>
  28. </template>
  29. </a-button>
  30. <p>条件分支</p>
  31. </li>
  32. <li v-if="addParallelGateway">
  33. <a-button shape="circle" size="large" @click="addType('parallelGateway')">
  34. <template #icon>
  35. <partition-outlined :rotate="180" style="color: #ac28f5; font-size: 18px"/>
  36. </template>
  37. </a-button>
  38. <p>并行分支</p>
  39. </li>
  40. </ul>
  41. </div>
  42. </template>
  43. <a-button type="primary" shape="circle">
  44. <!-- @click="addNodeButton" -->
  45. <template #icon>
  46. <plus-outlined/>
  47. </template>
  48. </a-button>
  49. </a-popover>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import {cloneDeep} from 'lodash-es'
  55. import config from '@/components/XnWorkflow/nodes/config/config'
  56. const NodeTitleMap = {
  57. userTask: '审核人',
  58. serviceTask: '抄送人',
  59. exclusiveGateway: '条件路由',
  60. parallelGateway: '并行路由'
  61. }
  62. export default {
  63. props: {
  64. modelValue: {
  65. type: Object, default: () => {
  66. }
  67. },
  68. parentData: {
  69. type: Object, default: () => {
  70. }
  71. },
  72. nodeItem: {
  73. type: Object, default: () => {
  74. }
  75. }
  76. },
  77. emits: ['update:modelValue'],
  78. data() {
  79. return {
  80. visible: false,
  81. addExclusiveGateway: true,
  82. addParallelGateway: true
  83. }
  84. },
  85. mounted() {
  86. },
  87. methods: {
  88. addNodeButton() {
  89. // 他的上级是条件分支或并行分支,将其不在添加 // 控制节点下面
  90. if (!this.parentData) {
  91. this.disabledChildren()
  92. } else {
  93. if (this.parentData.type === 'exclusiveGateway' || this.parentData.type === 'parallelGateway') {
  94. this.addExclusiveGateway = false
  95. this.addParallelGateway = false
  96. }
  97. }
  98. },
  99. disabledChildren() {
  100. // 如果下级是条件分支或并行分支,将其不在添加 // 控制节点上面
  101. if (this.modelValue && this.modelValue.type) {
  102. if (this.modelValue.type === 'exclusiveGateway' || this.modelValue.type === 'parallelGateway') {
  103. this.addExclusiveGateway = false
  104. this.addParallelGateway = false
  105. }
  106. }
  107. // 不管其他的,如果是条件分支的项,那么他的下面无法添加条件
  108. if (this.nodeItem) {
  109. this.addExclusiveGateway = false
  110. }
  111. },
  112. getBaseCondition(type, title) {
  113. const condition = cloneDeep(config.nodeModel.node)
  114. condition.id = this.$TOOL.snowyUuid()
  115. condition.type = type
  116. condition.title = title
  117. return condition
  118. },
  119. addType(type) {
  120. const nodeModel = this.getBaseCondition(type, NodeTitleMap[type]) || {}
  121. nodeModel.childNode = this.modelValue
  122. if (type === 'userTask') {
  123. // 创建 configInfo
  124. const configInfo = cloneDeep(config.nodeConfigInfo.userTaskConfigInfo)
  125. nodeModel.properties.configInfo = configInfo
  126. } else if (type === 'exclusiveGateway') {
  127. nodeModel.dataLegal = true
  128. // 创建分支节点1
  129. const condition1 = this.getBaseCondition('sequenceFlow', '条件1')
  130. // 创建分支节点1 configInfo
  131. const condition1ConfigInfo1 = cloneDeep(config.nodeConfigInfo.conditionConfigInfo)
  132. condition1ConfigInfo1.priorityLevel = 1
  133. condition1.properties.configInfo = condition1ConfigInfo1
  134. // 创建分支节点2
  135. const condition2 = this.getBaseCondition('sequenceFlow', '条件2')
  136. // 创建分支节点2 configInfo
  137. const condition1ConfigInfo2 = cloneDeep(config.nodeConfigInfo.conditionConfigInfo)
  138. condition1ConfigInfo2.priorityLevel = 2
  139. condition2.properties.configInfo = condition1ConfigInfo2
  140. // 装进去
  141. nodeModel.conditionNodeList.push(condition1)
  142. nodeModel.conditionNodeList.push(condition2)
  143. } else if (type === 'parallelGateway') {
  144. // 创建主节点
  145. nodeModel.dataLegal = true
  146. // 创建分支节点1
  147. const condition1 = this.getBaseCondition('userTask', '审批人1')
  148. condition1.properties.configInfo = cloneDeep(config.nodeConfigInfo.userTaskConfigInfo)
  149. condition1.dataLegal = true
  150. // 创建分支节点2
  151. const condition2 = this.getBaseCondition('userTask', '审批人2')
  152. condition2.properties.configInfo = cloneDeep(config.nodeConfigInfo.userTaskConfigInfo)
  153. condition2.dataLegal = true
  154. // 装进去
  155. nodeModel.conditionNodeList.push(condition1)
  156. nodeModel.conditionNodeList.push(condition2)
  157. }
  158. this.visible = false
  159. this.$emit('update:modelValue', nodeModel)
  160. }
  161. }
  162. }
  163. </script>