multiInstance.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="多实例配置"
  5. :visible.sync="dialogVisible"
  6. width="600px"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. class="muti-instance"
  10. @closed="$emit('close')"
  11. >
  12. <el-descriptions :column="1" size="mini" border>
  13. <el-descriptions-item label="使用说明">按照BPMN2.0规范的要求,用于为每个实例创建执行的父执行,会提供下列变量:</el-descriptions-item>
  14. <el-descriptions-item label="nrOfInstances">实例总数。</el-descriptions-item>
  15. <el-descriptions-item label="nrOfActiveInstances">当前活动的(即未完成的),实例数量。对于顺序多实例,这个值总为1。</el-descriptions-item>
  16. <el-descriptions-item label="nrOfCompletedInstances">已完成的实例数量。</el-descriptions-item>
  17. <el-descriptions-item label="loopCounter">给定实例在for-each循环中的index。</el-descriptions-item>
  18. </el-descriptions>
  19. <div class="app-container">
  20. <x-form ref="xForm" v-model="formData" :config="formConfig" />
  21. </div>
  22. </el-dialog>
  23. </div>
  24. </template>
  25. <script>
  26. import mixinPanel from '@/components/Process/common/mixinPanel'
  27. import { formatJsonKeyValue } from '@/components/Process/common/parseElement'
  28. export default {
  29. mixins: [mixinPanel],
  30. data() {
  31. return {
  32. dialogVisible: true,
  33. formData: {},
  34. prefix: 'flowable:'
  35. }
  36. },
  37. computed: {
  38. formConfig() {
  39. const _this = this
  40. return {
  41. inline: false,
  42. item: [
  43. {
  44. xType: 'input',
  45. name: 'collection',
  46. label: '集合',
  47. tooltip: 'collection: 属性会作为表达式进行解析。如果表达式解析为字符串而不是一个集合,<br />不论是因为本身配置的就是静态字符串值,还是表达式计算结果为字符串,<br />这个字符串都会被当做变量名,并从流程变量中用于获取实际的集合。'
  48. // rules: [{ required: true, message: '请输入集合名称', trigger: ['blur', 'change'] }]
  49. },
  50. {
  51. xType: 'input',
  52. name: 'elementVariable',
  53. label: '元素变量',
  54. tooltip: 'elementVariable: 每创建一个用户任务前,先以该元素变量为label,集合中的一项为value,<br />创建(局部)流程变量,该局部流程变量被用于指派用户任务。<br />一般来说,该字符串应与指定人员变量相同。'
  55. // rules: [{ required: true, message: '请输入元素变量', trigger: ['blur', 'change'] }]
  56. },
  57. {
  58. xType: 'select',
  59. name: 'isSequential',
  60. label: '执行方式',
  61. tooltip: '并行会签(parallel)、串行会签(sequential),其中并行会签的意思是 多个人同时执行任务。串行会签是按顺序执行任务。',
  62. dic: [{ label: '串行', value: true }, { label: '并行', value: false }]
  63. // rules: [{ required: true, message: '请选择执行方式', trigger: ['blur', 'change'] }]
  64. },
  65. {
  66. xType: 'input',
  67. name: 'completionCondition',
  68. label: '完成条件',
  69. tooltip: 'completionCondition: 多实例活动在所有实例都完成时结束,然而也可以指定一个表达式,在每个实例<br />结束时进行计算。当表达式计算为true时,将销毁所有剩余的实例,并结束多实例<br />活动,继续执行流程。例如 ${nrOfCompletedInstances/nrOfInstances >= 0.6 },<br />表示当任务完成60%时,该节点就算完成'
  70. // rules: [{ required: true, message: '请输入完成条件', trigger: ['blur', 'change'] }]
  71. }
  72. ],
  73. operate: [
  74. { text: '确定', show: true, click: _this.save },
  75. { text: '清空', show: true, click: () => { _this.formData = {} } }
  76. ]
  77. }
  78. }
  79. },
  80. mounted() {
  81. const loopCharacteristics = this.element.businessObject.loopCharacteristics
  82. const cache = JSON.parse(JSON.stringify(loopCharacteristics || {}))
  83. cache.completionCondition = cache.completionCondition ? cache.completionCondition.body : undefined
  84. // 拼接多实例对象
  85. if (this.element.businessObject.loopCharacteristics) {
  86. Object.assign(cache, this.element.businessObject.loopCharacteristics.$attrs)
  87. }
  88. this.formData = formatJsonKeyValue(cache)
  89. },
  90. methods: {
  91. updateElement() {
  92. if (this.formData.isSequential !== null && this.formData.isSequential !== undefined) {
  93. // const model = this.modeler.get('moddle');
  94. let loopCharacteristics = this.element.businessObject.get('loopCharacteristics')
  95. if (!loopCharacteristics) {
  96. loopCharacteristics = this.modeler.get('moddle').create('bpmn:MultiInstanceLoopCharacteristics')
  97. }
  98. loopCharacteristics['isSequential'] = this.formData.isSequential
  99. loopCharacteristics['collection'] = this.formData.collection
  100. loopCharacteristics['elementVariable'] = this.formData.elementVariable
  101. // let loopCardinality = model.create("bpmn:Expression",{
  102. // body: "4"
  103. // });
  104. // loopCharacteristics['loopCardinality'] = loopCardinality
  105. loopCharacteristics.$attrs['isSequential'] = this.formData.isSequential
  106. loopCharacteristics.$attrs[this.prefix + 'collection'] = this.formData.collection
  107. loopCharacteristics.$attrs[this.prefix + 'elementVariable'] = this.formData.elementVariable
  108. if (this.formData.completionCondition) {
  109. loopCharacteristics['completionCondition'] = this.modeler.get('moddle').create('bpmn:Expression', { body: this.formData.completionCondition })
  110. }
  111. this.updateProperties({ loopCharacteristics: loopCharacteristics })
  112. } else {
  113. delete this.element.businessObject.loopCharacteristics
  114. }
  115. },
  116. save() {
  117. this.$refs['xForm'].validate().then(() => {
  118. this.updateElement()
  119. this.dialogVisible = false
  120. }).catch(e => console.error(e))
  121. }
  122. }
  123. }
  124. </script>
  125. <style>
  126. .muti-instance .el-form-item {
  127. margin-bottom: 22px;
  128. }
  129. </style>