ElementMultiInstance.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 setup lang="ts" name="ElementMultiInstance">
  69. const props = defineProps({
  70. businessObject: Object,
  71. type: String
  72. })
  73. const prefix = inject('prefix')
  74. const loopCharacteristics = ref('')
  75. //默认配置,用来覆盖原始不存在的选项,避免报错
  76. const defaultLoopInstanceForm = ref({
  77. completionCondition: '',
  78. loopCardinality: '',
  79. extensionElements: [],
  80. asyncAfter: false,
  81. asyncBefore: false,
  82. exclusive: false
  83. })
  84. const loopInstanceForm = ref<any>({})
  85. const bpmnElement = ref(null)
  86. const multiLoopInstance = ref(null)
  87. const bpmnInstances = () => (window as any)?.bpmnInstances
  88. const getElementLoop = (businessObject) => {
  89. if (!businessObject.loopCharacteristics) {
  90. loopCharacteristics.value = 'Null'
  91. loopInstanceForm.value = {}
  92. return
  93. }
  94. if (businessObject.loopCharacteristics.$type === 'bpmn:StandardLoopCharacteristics') {
  95. loopCharacteristics.value = 'StandardLoop'
  96. loopInstanceForm.value = {}
  97. return
  98. }
  99. if (businessObject.loopCharacteristics.isSequential) {
  100. loopCharacteristics.value = 'SequentialMultiInstance'
  101. } else {
  102. loopCharacteristics.value = 'ParallelMultiInstance'
  103. }
  104. // 合并配置
  105. loopInstanceForm.value = {
  106. ...defaultLoopInstanceForm.value,
  107. ...businessObject.loopCharacteristics,
  108. completionCondition: businessObject.loopCharacteristics?.completionCondition?.body ?? '',
  109. loopCardinality: businessObject.loopCharacteristics?.loopCardinality?.body ?? ''
  110. }
  111. // 保留当前元素 businessObject 上的 loopCharacteristics 实例
  112. multiLoopInstance.value = bpmnInstances().bpmnElement.businessObject.loopCharacteristics
  113. // 更新表单
  114. if (
  115. businessObject.loopCharacteristics.extensionElements &&
  116. businessObject.loopCharacteristics.extensionElements.values &&
  117. businessObject.loopCharacteristics.extensionElements.values.length
  118. ) {
  119. loopInstanceForm.value['timeCycle'] =
  120. businessObject.loopCharacteristics.extensionElements.values[0].body
  121. }
  122. }
  123. const changeLoopCharacteristicsType = (type) => {
  124. // this.loopInstanceForm = { ...this.defaultLoopInstanceForm }; // 切换类型取消原表单配置
  125. // 取消多实例配置
  126. if (type === 'Null') {
  127. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  128. loopCharacteristics: null
  129. })
  130. return
  131. }
  132. // 配置循环
  133. if (type === 'StandardLoop') {
  134. const loopCharacteristicsObject = bpmnInstances().moddle.create(
  135. 'bpmn:StandardLoopCharacteristics'
  136. )
  137. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  138. loopCharacteristics: loopCharacteristicsObject
  139. })
  140. multiLoopInstance.value = null
  141. return
  142. }
  143. // 时序
  144. if (type === 'SequentialMultiInstance') {
  145. multiLoopInstance.value = bpmnInstances().moddle.create(
  146. 'bpmn:MultiInstanceLoopCharacteristics',
  147. { isSequential: true }
  148. )
  149. } else {
  150. multiLoopInstance.value = bpmnInstances().moddle.create(
  151. 'bpmn:MultiInstanceLoopCharacteristics',
  152. { collection: '${coll_userList}' }
  153. )
  154. }
  155. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  156. loopCharacteristics: toRaw(multiLoopInstance.value)
  157. })
  158. }
  159. // 循环基数
  160. const updateLoopCardinality = (cardinality) => {
  161. let loopCardinality = null
  162. if (cardinality && cardinality.length) {
  163. loopCardinality = bpmnInstances().moddle.create('bpmn:FormalExpression', {
  164. body: cardinality
  165. })
  166. }
  167. bpmnInstances().modeling.updateModdleProperties(
  168. toRaw(bpmnElement.value),
  169. multiLoopInstance.value,
  170. {
  171. loopCardinality
  172. }
  173. )
  174. }
  175. // 完成条件
  176. const updateLoopCondition = (condition) => {
  177. let completionCondition = null
  178. if (condition && condition.length) {
  179. completionCondition = bpmnInstances().moddle.create('bpmn:FormalExpression', {
  180. body: condition
  181. })
  182. }
  183. bpmnInstances().modeling.updateModdleProperties(
  184. toRaw(bpmnElement.value),
  185. multiLoopInstance.value,
  186. {
  187. completionCondition
  188. }
  189. )
  190. }
  191. // 重试周期
  192. const updateLoopTimeCycle = (timeCycle) => {
  193. const extensionElements = bpmnInstances().moddle.create('bpmn:ExtensionElements', {
  194. values: [
  195. bpmnInstances().moddle.create(`${prefix}:FailedJobRetryTimeCycle`, {
  196. body: timeCycle
  197. })
  198. ]
  199. })
  200. bpmnInstances().modeling.updateModdleProperties(
  201. toRaw(bpmnElement.value),
  202. multiLoopInstance.value,
  203. {
  204. extensionElements
  205. }
  206. )
  207. }
  208. // 直接更新的基础信息
  209. const updateLoopBase = () => {
  210. bpmnInstances().modeling.updateModdleProperties(
  211. toRaw(bpmnElement.value),
  212. multiLoopInstance.value,
  213. {
  214. collection: loopInstanceForm.value.collection || null,
  215. elementVariable: loopInstanceForm.value.elementVariable || null
  216. }
  217. )
  218. }
  219. // 各异步状态
  220. const updateLoopAsync = (key) => {
  221. const { asyncBefore, asyncAfter } = loopInstanceForm.value
  222. let asyncAttr = Object.create(null)
  223. if (!asyncBefore && !asyncAfter) {
  224. // this.$set(this.loopInstanceForm, "exclusive", false);
  225. loopInstanceForm.value['exclusive'] = false
  226. asyncAttr = { asyncBefore: false, asyncAfter: false, exclusive: false, extensionElements: null }
  227. } else {
  228. asyncAttr[key] = loopInstanceForm.value[key]
  229. }
  230. bpmnInstances().modeling.updateModdleProperties(
  231. toRaw(bpmnElement.value),
  232. multiLoopInstance.value,
  233. asyncAttr
  234. )
  235. }
  236. onBeforeUnmount(() => {
  237. multiLoopInstance.value = null
  238. bpmnElement.value = null
  239. })
  240. watch(
  241. () => props.businessObject,
  242. (val) => {
  243. bpmnElement.value = bpmnInstances().bpmnElement
  244. getElementLoop(val)
  245. },
  246. { immediate: true }
  247. )
  248. </script>