ElementMultiInstance.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="panel-tab__content">
  3. <el-form size="mini" label-width="90px" @submit.native.prevent>
  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 v-if="loopCharacteristics === 'ParallelMultiInstance' || loopCharacteristics === 'SequentialMultiInstance'">
  15. <el-form-item label="循环基数" key="loopCardinality">
  16. <el-input v-model="loopInstanceForm.loopCardinality" clearable @change="updateLoopCardinality" />
  17. </el-form-item>
  18. <el-form-item label="集合" key="collection" v-show="false">
  19. <el-input v-model="loopInstanceForm.collection" clearable @change="updateLoopBase" />
  20. </el-form-item>
  21. <el-form-item label="元素变量" key="elementVariable">
  22. <el-input v-model="loopInstanceForm.elementVariable" clearable @change="updateLoopBase" />
  23. </el-form-item>
  24. <el-form-item label="完成条件" key="completionCondition">
  25. <el-input v-model="loopInstanceForm.completionCondition" clearable @change="updateLoopCondition" />
  26. </el-form-item>
  27. <el-form-item label="异步状态" key="async">
  28. <el-checkbox v-model="loopInstanceForm.asyncBefore" label="异步前" @change="updateLoopAsync('asyncBefore')" />
  29. <el-checkbox v-model="loopInstanceForm.asyncAfter" label="异步后" @change="updateLoopAsync('asyncAfter')" />
  30. <el-checkbox
  31. v-model="loopInstanceForm.exclusive"
  32. v-if="loopInstanceForm.asyncAfter || loopInstanceForm.asyncBefore"
  33. label="排除"
  34. @change="updateLoopAsync('exclusive')"
  35. />
  36. </el-form-item>
  37. <el-form-item label="重试周期" prop="timeCycle" v-if="loopInstanceForm.asyncAfter || loopInstanceForm.asyncBefore" key="timeCycle">
  38. <el-input v-model="loopInstanceForm.timeCycle" clearable @change="updateLoopTimeCycle" />
  39. </el-form-item>
  40. </template>
  41. </el-form>
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. name: "ElementMultiInstance",
  47. props: {
  48. businessObject: Object,
  49. type: String
  50. },
  51. inject: {
  52. prefix: "prefix"
  53. },
  54. data() {
  55. return {
  56. loopCharacteristics: "",
  57. //默认配置,用来覆盖原始不存在的选项,避免报错
  58. defaultLoopInstanceForm: {
  59. completionCondition: "",
  60. loopCardinality: "",
  61. extensionElements: [],
  62. asyncAfter: false,
  63. asyncBefore: false,
  64. exclusive: false
  65. },
  66. loopInstanceForm: {}
  67. };
  68. },
  69. watch: {
  70. businessObject: {
  71. immediate: true,
  72. handler(val) {
  73. this.bpmnElement = window.bpmnInstances.bpmnElement;
  74. this.getElementLoop(val);
  75. }
  76. }
  77. },
  78. methods: {
  79. getElementLoop(businessObject) {
  80. if (!businessObject.loopCharacteristics) {
  81. this.loopCharacteristics = "Null";
  82. this.loopInstanceForm = {};
  83. return;
  84. }
  85. if (businessObject.loopCharacteristics.$type === "bpmn:StandardLoopCharacteristics") {
  86. this.loopCharacteristics = "StandardLoop";
  87. this.loopInstanceForm = {};
  88. return;
  89. }
  90. if (businessObject.loopCharacteristics.isSequential) {
  91. this.loopCharacteristics = "SequentialMultiInstance";
  92. } else {
  93. this.loopCharacteristics = "ParallelMultiInstance";
  94. }
  95. // 合并配置
  96. this.loopInstanceForm = {
  97. ...this.defaultLoopInstanceForm,
  98. ...businessObject.loopCharacteristics,
  99. completionCondition: businessObject.loopCharacteristics?.completionCondition?.body ?? "",
  100. loopCardinality: businessObject.loopCharacteristics?.loopCardinality?.body ?? ""
  101. };
  102. // 保留当前元素 businessObject 上的 loopCharacteristics 实例
  103. this.multiLoopInstance = window.bpmnInstances.bpmnElement.businessObject.loopCharacteristics;
  104. // 更新表单
  105. if (
  106. businessObject.loopCharacteristics.extensionElements &&
  107. businessObject.loopCharacteristics.extensionElements.values &&
  108. businessObject.loopCharacteristics.extensionElements.values.length
  109. ) {
  110. this.$set(this.loopInstanceForm, "timeCycle", businessObject.loopCharacteristics.extensionElements.values[0].body);
  111. }
  112. },
  113. changeLoopCharacteristicsType(type) {
  114. // this.loopInstanceForm = { ...this.defaultLoopInstanceForm }; // 切换类型取消原表单配置
  115. // 取消多实例配置
  116. if (type === "Null") {
  117. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, { loopCharacteristics: null });
  118. return;
  119. }
  120. // 配置循环
  121. if (type === "StandardLoop") {
  122. const loopCharacteristicsObject = window.bpmnInstances.moddle.create("bpmn:StandardLoopCharacteristics");
  123. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  124. loopCharacteristics: loopCharacteristicsObject
  125. });
  126. this.multiLoopInstance = null;
  127. return;
  128. }
  129. // 时序
  130. if (type === "SequentialMultiInstance") {
  131. this.multiLoopInstance = window.bpmnInstances.moddle.create("bpmn:MultiInstanceLoopCharacteristics", { isSequential: true });
  132. } else {
  133. this.multiLoopInstance = window.bpmnInstances.moddle.create("bpmn:MultiInstanceLoopCharacteristics", { collection: "${coll_userList}" });
  134. }
  135. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  136. loopCharacteristics: this.multiLoopInstance
  137. });
  138. },
  139. // 循环基数
  140. updateLoopCardinality(cardinality) {
  141. let loopCardinality = null;
  142. if (cardinality && cardinality.length) {
  143. loopCardinality = window.bpmnInstances.moddle.create("bpmn:FormalExpression", { body: cardinality });
  144. }
  145. window.bpmnInstances.modeling.updateModdleProperties(this.bpmnElement, this.multiLoopInstance, { loopCardinality });
  146. },
  147. // 完成条件
  148. updateLoopCondition(condition) {
  149. let completionCondition = null;
  150. if (condition && condition.length) {
  151. completionCondition = window.bpmnInstances.moddle.create("bpmn:FormalExpression", { body: condition });
  152. }
  153. window.bpmnInstances.modeling.updateModdleProperties(this.bpmnElement, this.multiLoopInstance, { completionCondition });
  154. },
  155. // 重试周期
  156. updateLoopTimeCycle(timeCycle) {
  157. const extensionElements = window.bpmnInstances.moddle.create("bpmn:ExtensionElements", {
  158. values: [
  159. window.bpmnInstances.moddle.create(`${this.prefix}:FailedJobRetryTimeCycle`, {
  160. body: timeCycle
  161. })
  162. ]
  163. });
  164. window.bpmnInstances.modeling.updateModdleProperties(this.bpmnElement, this.multiLoopInstance, { extensionElements });
  165. },
  166. // 直接更新的基础信息
  167. updateLoopBase() {
  168. window.bpmnInstances.modeling.updateModdleProperties(this.bpmnElement, this.multiLoopInstance, {
  169. collection: this.loopInstanceForm.collection || null,
  170. elementVariable: this.loopInstanceForm.elementVariable || null
  171. });
  172. },
  173. // 各异步状态
  174. updateLoopAsync(key) {
  175. const { asyncBefore, asyncAfter } = this.loopInstanceForm;
  176. let asyncAttr = Object.create(null);
  177. if (!asyncBefore && !asyncAfter) {
  178. this.$set(this.loopInstanceForm, "exclusive", false);
  179. asyncAttr = { asyncBefore: false, asyncAfter: false, exclusive: false, extensionElements: null };
  180. } else {
  181. asyncAttr[key] = this.loopInstanceForm[key];
  182. }
  183. window.bpmnInstances.modeling.updateModdleProperties(this.bpmnElement, this.multiLoopInstance, asyncAttr);
  184. }
  185. },
  186. beforeDestroy() {
  187. this.multiLoopInstance = null;
  188. this.bpmnElement = null;
  189. }
  190. };
  191. </script>