ElementMultiInstance.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 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 = window.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. window.bpmnInstances.modeling.updateProperties(toRaw(bpmnElement.value), {
  129. loopCharacteristics: null
  130. })
  131. return
  132. }
  133. // 配置循环
  134. if (type === 'StandardLoop') {
  135. const loopCharacteristicsObject = window.bpmnInstances.moddle.create(
  136. 'bpmn:StandardLoopCharacteristics'
  137. )
  138. window.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 = window.bpmnInstances.moddle.create(
  147. 'bpmn:MultiInstanceLoopCharacteristics',
  148. { isSequential: true }
  149. )
  150. } else {
  151. multiLoopInstance.value = window.bpmnInstances.moddle.create(
  152. 'bpmn:MultiInstanceLoopCharacteristics',
  153. { collection: '${coll_userList}' }
  154. )
  155. }
  156. window.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 = window.bpmnInstances.moddle.create('bpmn:FormalExpression', {
  165. body: cardinality
  166. })
  167. }
  168. window.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 = window.bpmnInstances.moddle.create('bpmn:FormalExpression', {
  181. body: condition
  182. })
  183. }
  184. window.bpmnInstances.modeling.updateModdleProperties(
  185. toRaw(bpmnElement.value),
  186. multiLoopInstance.value,
  187. {
  188. completionCondition
  189. }
  190. )
  191. }
  192. // 重试周期
  193. const updateLoopTimeCycle = (timeCycle) => {
  194. const extensionElements = window.bpmnInstances.moddle.create('bpmn:ExtensionElements', {
  195. values: [
  196. window.bpmnInstances.moddle.create(`${prefix}:FailedJobRetryTimeCycle`, {
  197. body: timeCycle
  198. })
  199. ]
  200. })
  201. window.bpmnInstances.modeling.updateModdleProperties(
  202. toRaw(bpmnElement.value),
  203. multiLoopInstance.value,
  204. {
  205. extensionElements
  206. }
  207. )
  208. }
  209. // 直接更新的基础信息
  210. const updateLoopBase = () => {
  211. window.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. window.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 = window.bpmnInstances.bpmnElement
  245. getElementLoop(val)
  246. },
  247. { immediate: true }
  248. )
  249. </script>