FlowCondition.vue 6.6 KB

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