FlowCondition.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 setup lang="ts" name="FlowCondition">
  65. const props = defineProps({
  66. businessObject: Object,
  67. type: String
  68. })
  69. const flowConditionForm = ref<any>({})
  70. const bpmnElement = ref()
  71. const bpmnElementSource = ref()
  72. const bpmnElementSourceRef = ref()
  73. const flowConditionRef = ref()
  74. const bpmnInstances = () => (window as any)?.bpmnInstances
  75. const resetFlowCondition = () => {
  76. bpmnElement.value = bpmnInstances().bpmnElement
  77. bpmnElementSource.value = bpmnElement.value.source
  78. bpmnElementSourceRef.value = bpmnElement.value.businessObject.sourceRef
  79. if (
  80. bpmnElementSourceRef.value &&
  81. bpmnElementSourceRef.value.default &&
  82. bpmnElementSourceRef.value.default.id === bpmnElement.value.id
  83. ) {
  84. // 默认
  85. flowConditionForm.value = { type: 'default' }
  86. } else if (!bpmnElement.value.businessObject.conditionExpression) {
  87. // 普通
  88. flowConditionForm.value = { type: 'normal' }
  89. } else {
  90. // 带条件
  91. const conditionExpression = bpmnElement.value.businessObject.conditionExpression
  92. flowConditionForm.value = { ...conditionExpression, type: 'condition' }
  93. // resource 可直接标识 是否是外部资源脚本
  94. if (flowConditionForm.value.resource) {
  95. // this.$set(this.flowConditionForm, "conditionType", "script");
  96. // this.$set(this.flowConditionForm, "scriptType", "externalScript");
  97. flowConditionForm.value['conditionType'] = 'script'
  98. flowConditionForm.value['scriptType'] = 'externalScript'
  99. return
  100. }
  101. if (conditionExpression.language) {
  102. // this.$set(this.flowConditionForm, "conditionType", "script");
  103. // this.$set(this.flowConditionForm, "scriptType", "inlineScript");
  104. flowConditionForm.value['conditionType'] = 'script'
  105. flowConditionForm.value['scriptType'] = 'inlineScript'
  106. return
  107. }
  108. // this.$set(this.flowConditionForm, "conditionType", "expression");
  109. flowConditionForm.value['conditionType'] = 'expression'
  110. }
  111. }
  112. const updateFlowType = (flowType) => {
  113. // 正常条件类
  114. if (flowType === 'condition') {
  115. flowConditionRef.value = bpmnInstances().moddle.create('bpmn:FormalExpression')
  116. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  117. conditionExpression: flowConditionRef.value
  118. })
  119. return
  120. }
  121. // 默认路径
  122. if (flowType === 'default') {
  123. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  124. conditionExpression: null
  125. })
  126. bpmnInstances().modeling.updateProperties(toRaw(bpmnElementSource.value), {
  127. default: bpmnElement.value
  128. })
  129. return
  130. }
  131. // 正常路径,如果来源节点的默认路径是当前连线时,清除父元素的默认路径配置
  132. if (
  133. bpmnElementSourceRef.value.default &&
  134. bpmnElementSourceRef.value.default.id === bpmnElement.value.id
  135. ) {
  136. bpmnInstances().modeling.updateProperties(toRaw(bpmnElementSource.value), {
  137. default: null
  138. })
  139. }
  140. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  141. conditionExpression: null
  142. })
  143. }
  144. const updateFlowCondition = () => {
  145. let { conditionType, scriptType, body, resource, language } = flowConditionForm.value
  146. let condition
  147. if (conditionType === 'expression') {
  148. condition = bpmnInstances().moddle.create('bpmn:FormalExpression', { body })
  149. } else {
  150. if (scriptType === 'inlineScript') {
  151. condition = bpmnInstances().moddle.create('bpmn:FormalExpression', { body, language })
  152. // this.$set(this.flowConditionForm, "resource", "");
  153. flowConditionForm.value['resource'] = ''
  154. } else {
  155. // this.$set(this.flowConditionForm, "body", "");
  156. flowConditionForm.value['body'] = ''
  157. condition = bpmnInstances().moddle.create('bpmn:FormalExpression', {
  158. resource,
  159. language
  160. })
  161. }
  162. }
  163. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  164. conditionExpression: condition
  165. })
  166. }
  167. onBeforeUnmount(() => {
  168. bpmnElement.value = null
  169. bpmnElementSource.value = null
  170. bpmnElementSourceRef.value = null
  171. })
  172. watch(
  173. () => props.businessObject,
  174. (val) => {
  175. if (val) {
  176. nextTick(() => {
  177. resetFlowCondition()
  178. })
  179. }
  180. }
  181. )
  182. </script>