ElementMultiInstance.vue 9.1 KB

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