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