ElementMultiInstance.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="panel-tab__content">
  3. <el-form label-width="90px">
  4. <el-form-item label="回路特性">
  5. <el-select v-model="loopCharacteristics" @change="changeLoopCharacteristicsType">
  6. <!--bpmn:MultiInstanceLoopCharacteristics-->
  7. <el-option label="并行多重事件" value="ParallelMultiInstance" />
  8. <el-option label="时序多重事件" value="SequentialMultiInstance" />
  9. <!--bpmn:StandardLoopCharacteristics-->
  10. <el-option label="循环事件" value="StandardLoop" />
  11. <el-option label="无" value="Null" />
  12. </el-select>
  13. </el-form-item>
  14. <template
  15. v-if="
  16. loopCharacteristics === 'ParallelMultiInstance' ||
  17. loopCharacteristics === 'SequentialMultiInstance'
  18. "
  19. >
  20. <el-form-item label="循环基数" key="loopCardinality">
  21. <el-input
  22. v-model="loopInstanceForm.loopCardinality"
  23. clearable
  24. @change="updateLoopCardinality"
  25. />
  26. </el-form-item>
  27. <el-form-item label="集合" key="collection" v-show="false">
  28. <el-input v-model="loopInstanceForm.collection" clearable @change="updateLoopBase" />
  29. </el-form-item>
  30. <el-form-item label="元素变量" key="elementVariable">
  31. <el-input v-model="loopInstanceForm.elementVariable" clearable @change="updateLoopBase" />
  32. </el-form-item>
  33. <el-form-item label="完成条件" key="completionCondition">
  34. <el-input
  35. v-model="loopInstanceForm.completionCondition"
  36. clearable
  37. @change="updateLoopCondition"
  38. />
  39. </el-form-item>
  40. <el-form-item label="异步状态" key="async">
  41. <el-checkbox
  42. v-model="loopInstanceForm.asyncBefore"
  43. label="异步前"
  44. @change="updateLoopAsync('asyncBefore')"
  45. />
  46. <el-checkbox
  47. v-model="loopInstanceForm.asyncAfter"
  48. label="异步后"
  49. @change="updateLoopAsync('asyncAfter')"
  50. />
  51. <el-checkbox
  52. v-model="loopInstanceForm.exclusive"
  53. v-if="loopInstanceForm.asyncAfter || loopInstanceForm.asyncBefore"
  54. label="排除"
  55. @change="updateLoopAsync('exclusive')"
  56. />
  57. </el-form-item>
  58. <el-form-item
  59. label="重试周期"
  60. prop="timeCycle"
  61. v-if="loopInstanceForm.asyncAfter || loopInstanceForm.asyncBefore"
  62. key="timeCycle"
  63. >
  64. <el-input v-model="loopInstanceForm.timeCycle" clearable @change="updateLoopTimeCycle" />
  65. </el-form-item>
  66. </template>
  67. </el-form>
  68. </div>
  69. </template>
  70. <script setup lang="ts" name="ElementMultiInstance">
  71. import { inject, ref, onBeforeUnmount, watch, toRaw } from 'vue'
  72. import { ElForm, ElFormItem, ElSelect, ElOption, ElCheckbox, ElInput } from 'element-plus'
  73. const props = defineProps({
  74. businessObject: Object,
  75. type: String
  76. })
  77. const prefix = inject('prefix')
  78. const loopCharacteristics = ref('')
  79. //默认配置,用来覆盖原始不存在的选项,避免报错
  80. const defaultLoopInstanceForm = ref({
  81. completionCondition: '',
  82. loopCardinality: '',
  83. extensionElements: [],
  84. asyncAfter: false,
  85. asyncBefore: false,
  86. exclusive: false
  87. })
  88. const loopInstanceForm = ref({})
  89. const bpmnElement = ref(null)
  90. const multiLoopInstance = ref(null)
  91. const getElementLoop = (businessObject) => {
  92. if (!businessObject.loopCharacteristics) {
  93. loopCharacteristics.value = 'Null'
  94. loopInstanceForm.value = {}
  95. return
  96. }
  97. if (businessObject.loopCharacteristics.$type === 'bpmn:StandardLoopCharacteristics') {
  98. loopCharacteristics.value = 'StandardLoop'
  99. loopInstanceForm.value = {}
  100. return
  101. }
  102. if (businessObject.loopCharacteristics.isSequential) {
  103. loopCharacteristics.value = 'SequentialMultiInstance'
  104. } else {
  105. loopCharacteristics.value = 'ParallelMultiInstance'
  106. }
  107. // 合并配置
  108. loopInstanceForm.value = {
  109. ...defaultLoopInstanceForm.value,
  110. ...businessObject.loopCharacteristics,
  111. completionCondition: businessObject.loopCharacteristics?.completionCondition?.body ?? '',
  112. loopCardinality: businessObject.loopCharacteristics?.loopCardinality?.body ?? ''
  113. }
  114. // 保留当前元素 businessObject 上的 loopCharacteristics 实例
  115. multiLoopInstance.value = window.bpmnInstances.bpmnElement.businessObject.loopCharacteristics
  116. // 更新表单
  117. if (
  118. businessObject.loopCharacteristics.extensionElements &&
  119. businessObject.loopCharacteristics.extensionElements.values &&
  120. businessObject.loopCharacteristics.extensionElements.values.length
  121. ) {
  122. loopInstanceForm.value['timeCycle'] =
  123. businessObject.loopCharacteristics.extensionElements.values[0].body
  124. }
  125. }
  126. const changeLoopCharacteristicsType = (type) => {
  127. // this.loopInstanceForm = { ...this.defaultLoopInstanceForm }; // 切换类型取消原表单配置
  128. // 取消多实例配置
  129. if (type === 'Null') {
  130. window.bpmnInstances.modeling.updateProperties(toRaw(bpmnElement.value), {
  131. loopCharacteristics: null
  132. })
  133. return
  134. }
  135. // 配置循环
  136. if (type === 'StandardLoop') {
  137. const loopCharacteristicsObject = window.bpmnInstances.moddle.create(
  138. 'bpmn:StandardLoopCharacteristics'
  139. )
  140. window.bpmnInstances.modeling.updateProperties(toRaw(bpmnElement.value), {
  141. loopCharacteristics: loopCharacteristicsObject
  142. })
  143. multiLoopInstance.value = null
  144. return
  145. }
  146. // 时序
  147. if (type === 'SequentialMultiInstance') {
  148. multiLoopInstance.value = window.bpmnInstances.moddle.create(
  149. 'bpmn:MultiInstanceLoopCharacteristics',
  150. { isSequential: true }
  151. )
  152. } else {
  153. multiLoopInstance.value = window.bpmnInstances.moddle.create(
  154. 'bpmn:MultiInstanceLoopCharacteristics',
  155. { collection: '${coll_userList}' }
  156. )
  157. }
  158. window.bpmnInstances.modeling.updateProperties(toRaw(bpmnElement.value), {
  159. loopCharacteristics: toRaw(multiLoopInstance.value)
  160. })
  161. }
  162. // 循环基数
  163. const updateLoopCardinality = (cardinality) => {
  164. let loopCardinality = null
  165. if (cardinality && cardinality.length) {
  166. loopCardinality = window.bpmnInstances.moddle.create('bpmn:FormalExpression', {
  167. body: cardinality
  168. })
  169. }
  170. window.bpmnInstances.modeling.updateModdleProperties(
  171. toRaw(bpmnElement.value),
  172. multiLoopInstance.value,
  173. {
  174. loopCardinality
  175. }
  176. )
  177. }
  178. // 完成条件
  179. const updateLoopCondition = (condition) => {
  180. let completionCondition = null
  181. if (condition && condition.length) {
  182. completionCondition = window.bpmnInstances.moddle.create('bpmn:FormalExpression', {
  183. body: condition
  184. })
  185. }
  186. window.bpmnInstances.modeling.updateModdleProperties(
  187. toRaw(bpmnElement.value),
  188. multiLoopInstance.value,
  189. {
  190. completionCondition
  191. }
  192. )
  193. }
  194. // 重试周期
  195. const updateLoopTimeCycle = (timeCycle) => {
  196. const extensionElements = window.bpmnInstances.moddle.create('bpmn:ExtensionElements', {
  197. values: [
  198. window.bpmnInstances.moddle.create(`${prefix}:FailedJobRetryTimeCycle`, {
  199. body: timeCycle
  200. })
  201. ]
  202. })
  203. window.bpmnInstances.modeling.updateModdleProperties(
  204. toRaw(bpmnElement.value),
  205. multiLoopInstance.value,
  206. {
  207. extensionElements
  208. }
  209. )
  210. }
  211. // 直接更新的基础信息
  212. const updateLoopBase = () => {
  213. window.bpmnInstances.modeling.updateModdleProperties(
  214. toRaw(bpmnElement.value),
  215. multiLoopInstance.value,
  216. {
  217. collection: loopInstanceForm.value.collection || null,
  218. elementVariable: loopInstanceForm.value.elementVariable || null
  219. }
  220. )
  221. }
  222. // 各异步状态
  223. const updateLoopAsync = (key) => {
  224. const { asyncBefore, asyncAfter } = loopInstanceForm.value
  225. let asyncAttr = Object.create(null)
  226. if (!asyncBefore && !asyncAfter) {
  227. // this.$set(this.loopInstanceForm, "exclusive", false);
  228. loopInstanceForm.value['exclusive'] = false
  229. asyncAttr = { asyncBefore: false, asyncAfter: false, exclusive: false, extensionElements: null }
  230. } else {
  231. asyncAttr[key] = loopInstanceForm.value[key]
  232. }
  233. window.bpmnInstances.modeling.updateModdleProperties(
  234. toRaw(bpmnElement.value),
  235. multiLoopInstance.value,
  236. asyncAttr
  237. )
  238. }
  239. onBeforeUnmount(() => {
  240. multiLoopInstance.value = null
  241. bpmnElement.value = null
  242. })
  243. watch(
  244. () => props.businessObject,
  245. (val) => {
  246. bpmnElement.value = window.bpmnInstances.bpmnElement
  247. getElementLoop(val)
  248. },
  249. { immediate: true }
  250. )
  251. </script>