FlowCondition.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="panel-tab__content">
  3. <el-form :model="flowConditionForm" label-width="90px" size="small">
  4. <el-form-item label="流转类型">
  5. <el-select v-model="flowConditionForm.type" @change="updateFlowType">
  6. <el-option label="普通流转路径" value="normal" />
  7. <el-option label="默认流转路径" value="default" />
  8. <el-option label="条件流转路径" value="condition" />
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="条件格式" v-if="flowConditionForm.type === 'condition'" key="condition">
  12. <el-select v-model="flowConditionForm.conditionType">
  13. <el-option label="表达式" value="expression" />
  14. <el-option label="脚本" value="script" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item
  18. label="表达式"
  19. v-if="flowConditionForm.conditionType && flowConditionForm.conditionType === 'expression'"
  20. key="express"
  21. >
  22. <el-input
  23. v-model="flowConditionForm.body"
  24. style="width: 192px"
  25. clearable
  26. @change="updateFlowCondition"
  27. />
  28. </el-form-item>
  29. <template
  30. v-if="flowConditionForm.conditionType && flowConditionForm.conditionType === 'script'"
  31. >
  32. <el-form-item label="脚本语言" key="language">
  33. <el-input v-model="flowConditionForm.language" clearable @change="updateFlowCondition" />
  34. </el-form-item>
  35. <el-form-item label="脚本类型" key="scriptType">
  36. <el-select v-model="flowConditionForm.scriptType">
  37. <el-option label="内联脚本" value="inlineScript" />
  38. <el-option label="外部脚本" value="externalScript" />
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item
  42. label="脚本"
  43. v-if="flowConditionForm.scriptType === 'inlineScript'"
  44. key="body"
  45. >
  46. <el-input
  47. v-model="flowConditionForm.body"
  48. type="textarea"
  49. clearable
  50. @change="updateFlowCondition"
  51. />
  52. </el-form-item>
  53. <el-form-item
  54. label="资源地址"
  55. v-if="flowConditionForm.scriptType === 'externalScript'"
  56. key="resource"
  57. >
  58. <el-input v-model="flowConditionForm.resource" clearable @change="updateFlowCondition" />
  59. </el-form-item>
  60. </template>
  61. </el-form>
  62. </div>
  63. </template>
  64. <script lang="ts" setup>
  65. defineOptions({ name: 'FlowCondition' })
  66. const props = defineProps({
  67. businessObject: Object,
  68. type: String
  69. })
  70. const flowConditionForm = ref<any>({})
  71. const bpmnElement = ref()
  72. const bpmnElementSource = ref()
  73. const bpmnElementSourceRef = ref()
  74. const flowConditionRef = ref()
  75. const bpmnInstances = () => (window as any)?.bpmnInstances
  76. const resetFlowCondition = () => {
  77. bpmnElement.value = bpmnInstances().bpmnElement
  78. bpmnElementSource.value = bpmnElement.value.source
  79. bpmnElementSourceRef.value = bpmnElement.value.businessObject.sourceRef
  80. // 初始化默认type为default
  81. flowConditionForm.value = { type: 'default' }
  82. if (
  83. bpmnElementSourceRef.value &&
  84. bpmnElementSourceRef.value.default &&
  85. bpmnElementSourceRef.value.default.id === bpmnElement.value.id
  86. ) {
  87. flowConditionForm.value = { type: 'default' }
  88. } else if (!bpmnElement.value.businessObject.conditionExpression) {
  89. // 普通
  90. flowConditionForm.value = { type: 'normal' }
  91. } else {
  92. // 带条件
  93. const conditionExpression = bpmnElement.value.businessObject.conditionExpression
  94. flowConditionForm.value = { ...conditionExpression, type: 'condition' }
  95. // resource 可直接标识 是否是外部资源脚本
  96. if (flowConditionForm.value.resource) {
  97. // this.$set(this.flowConditionForm, "conditionType", "script");
  98. // this.$set(this.flowConditionForm, "scriptType", "externalScript");
  99. flowConditionForm.value['conditionType'] = 'script'
  100. flowConditionForm.value['scriptType'] = 'externalScript'
  101. return
  102. }
  103. if (conditionExpression.language) {
  104. // this.$set(this.flowConditionForm, "conditionType", "script");
  105. // this.$set(this.flowConditionForm, "scriptType", "inlineScript");
  106. flowConditionForm.value['conditionType'] = 'script'
  107. flowConditionForm.value['scriptType'] = 'inlineScript'
  108. return
  109. }
  110. // this.$set(this.flowConditionForm, "conditionType", "expression");
  111. flowConditionForm.value['conditionType'] = 'expression'
  112. }
  113. }
  114. const updateFlowType = (flowType) => {
  115. // 正常条件类
  116. if (flowType === 'condition') {
  117. flowConditionRef.value = bpmnInstances().moddle.create('bpmn:FormalExpression')
  118. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  119. conditionExpression: flowConditionRef.value
  120. })
  121. return
  122. }
  123. // 默认路径
  124. if (flowType === 'default') {
  125. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  126. conditionExpression: null
  127. })
  128. bpmnInstances().modeling.updateProperties(toRaw(bpmnElementSource.value), {
  129. default: toRaw(bpmnElement.value)
  130. })
  131. return
  132. }
  133. // 正常路径,如果来源节点的默认路径是当前连线时,清除父元素的默认路径配置
  134. if (
  135. bpmnElementSourceRef.value.default &&
  136. bpmnElementSourceRef.value.default.id === bpmnElement.value.id
  137. ) {
  138. bpmnInstances().modeling.updateProperties(toRaw(bpmnElementSource.value), {
  139. default: null
  140. })
  141. }
  142. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  143. conditionExpression: null
  144. })
  145. }
  146. const updateFlowCondition = () => {
  147. let { conditionType, scriptType, body, resource, language } = flowConditionForm.value
  148. let condition
  149. if (conditionType === 'expression') {
  150. condition = bpmnInstances().moddle.create('bpmn:FormalExpression', { body })
  151. } else {
  152. if (scriptType === 'inlineScript') {
  153. condition = bpmnInstances().moddle.create('bpmn:FormalExpression', { body, language })
  154. // this.$set(this.flowConditionForm, "resource", "");
  155. flowConditionForm.value['resource'] = ''
  156. } else {
  157. // this.$set(this.flowConditionForm, "body", "");
  158. flowConditionForm.value['body'] = ''
  159. condition = bpmnInstances().moddle.create('bpmn:FormalExpression', {
  160. resource,
  161. language
  162. })
  163. }
  164. }
  165. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  166. conditionExpression: condition
  167. })
  168. }
  169. onBeforeUnmount(() => {
  170. bpmnElement.value = null
  171. bpmnElementSource.value = null
  172. bpmnElementSourceRef.value = null
  173. })
  174. watch(
  175. () => props.businessObject,
  176. (val) => {
  177. console.log(val, 'val')
  178. nextTick(() => {
  179. resetFlowCondition()
  180. })
  181. },
  182. {
  183. immediate: true
  184. }
  185. )
  186. </script>