当前位置:   article > 正文

ruoyi-nbcio-plus基于vue3的flowable的流程条件的升级修改_flowable vue3

flowable vue3

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统 http://122.227.135.243:9666/

更多nbcio-boot功能请看演示系统 

gitee源代码地址

后端代码: https://gitee.com/nbacheng/nbcio-boot

前端代码:https://gitee.com/nbacheng/nbcio-vue.git

在线演示(包括H5) : http://122.227.135.243:9888

1、原先vue2代码如下:

  1. <template>
  2. <div class="panel-tab__content">
  3. <el-form :model="flowConditionForm" label-width="90px" size="small" @submit.prevent>
  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 label="表达式" v-if="flowConditionForm.conditionType && flowConditionForm.conditionType === 'expression'" key="express">
  18. <el-input v-model="flowConditionForm.body" clearable @change="updateFlowCondition" />
  19. </el-form-item>
  20. <template v-if="flowConditionForm.conditionType && flowConditionForm.conditionType === 'script'">
  21. <el-form-item label="脚本语言" key="language">
  22. <el-input v-model="flowConditionForm.language" clearable @change="updateFlowCondition" />
  23. </el-form-item>
  24. <el-form-item label="脚本类型" key="scriptType">
  25. <el-select v-model="flowConditionForm.scriptType">
  26. <el-option label="内联脚本" value="inlineScript" />
  27. <el-option label="外部脚本" value="externalScript" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="脚本" v-if="flowConditionForm.scriptType === 'inlineScript'" key="body">
  31. <el-input v-model="flowConditionForm.body" type="textarea" clearable @change="updateFlowCondition" />
  32. </el-form-item>
  33. <el-form-item label="资源地址" v-if="flowConditionForm.scriptType === 'externalScript'" key="resource">
  34. <el-input v-model="flowConditionForm.resource" clearable @change="updateFlowCondition" />
  35. </el-form-item>
  36. </template>
  37. </el-form>
  38. </div>
  39. </template>
  40. <script>
  41. export default {
  42. name: 'FlowCondition',
  43. props: {
  44. businessObject: Object,
  45. type: String
  46. },
  47. data() {
  48. return {
  49. flowConditionForm: {}
  50. };
  51. },
  52. watch: {
  53. businessObject: {
  54. immediate: true,
  55. handler() {
  56. this.$nextTick(() => this.resetFlowCondition());
  57. }
  58. }
  59. },
  60. methods: {
  61. resetFlowCondition() {
  62. this.bpmnElement = window.bpmnInstances.bpmnElement;
  63. this.bpmnElementSource = this.bpmnElement.source;
  64. this.bpmnElementSourceRef = this.bpmnElement.businessObject.sourceRef;
  65. if (this.bpmnElementSourceRef && this.bpmnElementSourceRef.default && this.bpmnElementSourceRef.default.id === this.bpmnElement.id) {
  66. // 默认
  67. this.flowConditionForm = { type: 'default' };
  68. } else if (!this.bpmnElement.businessObject.conditionExpression) {
  69. // 普通
  70. this.flowConditionForm = { type: 'normal' };
  71. } else {
  72. // 带条件
  73. const conditionExpression = this.bpmnElement.businessObject.conditionExpression;
  74. this.flowConditionForm = { ...conditionExpression, type: 'condition' };
  75. // resource 可直接标识 是否是外部资源脚本
  76. if (this.flowConditionForm.resource) {
  77. this.flowConditionForm['conditionType'] = 'script'
  78. this.flowConditionForm['scriptType'] = 'externalScript'
  79. return;
  80. }
  81. if (conditionExpression.language) {
  82. this.flowConditionForm['conditionType'] = 'script'
  83. this.flowConditionForm['scriptType'] = 'inlineScript'
  84. return;
  85. }
  86. this.flowConditionForm['conditionType'] = 'expression'
  87. }
  88. },
  89. updateFlowType(flowType) {
  90. // 正常条件类
  91. if (flowType === 'condition') {
  92. this.flowConditionRef = window.bpmnInstances.moddle.create('bpmn:FormalExpression');
  93. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  94. conditionExpression: this.flowConditionRef
  95. });
  96. return;
  97. }
  98. // 默认路径
  99. if (flowType === 'default') {
  100. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  101. conditionExpression: null
  102. });
  103. window.bpmnInstances.modeling.updateProperties(this.bpmnElementSource, {
  104. default: this.bpmnElement
  105. });
  106. return;
  107. }
  108. // 正常路径,如果来源节点的默认路径是当前连线时,清除父元素的默认路径配置
  109. if (this.bpmnElementSourceRef.default && this.bpmnElementSourceRef.default.id === this.bpmnElement.id) {
  110. window.bpmnInstances.modeling.updateProperties(this.bpmnElementSource, {
  111. default: null
  112. });
  113. }
  114. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  115. conditionExpression: null
  116. });
  117. },
  118. updateFlowCondition() {
  119. const { conditionType, scriptType, body, resource, language } = this.flowConditionForm;
  120. let condition;
  121. if (conditionType === 'expression') {
  122. condition = window.bpmnInstances.moddle.create('bpmn:FormalExpression', { body });
  123. } else {
  124. if (scriptType === 'inlineScript') {
  125. condition = window.bpmnInstances.moddle.create('bpmn:FormalExpression', { body, language });
  126. this.flowConditionForm['resource'] = ''
  127. } else {
  128. this.flowConditionForm['body'] = ''
  129. condition = window.bpmnInstances.moddle.create('bpmn:FormalExpression', { resource, language });
  130. }
  131. }
  132. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, { conditionExpression: condition });
  133. }
  134. },
  135. beforeUnmount() {
  136. this.bpmnElement = null;
  137. this.bpmnElementSource = null;
  138. this.bpmnElementSourceRef = null;
  139. }
  140. };
  141. </script>

2、修改成vue3的代码如下:

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

3、效果图如下:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/418049
推荐阅读
相关标签
  

闽ICP备14008679号