ElementMultiInstance.vue 8.0 KB

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