FlowCondition.vue 6.5 KB

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