Parcourir la source

条件判断值

CzRger il y a 2 semaines
Parent
commit
052670c466

+ 14 - 6
src/views/workflow/instance/component/condition/condition-item.vue

@@ -9,11 +9,7 @@
         <selectPopover
           class="w-[60px]"
           v-model:value="item.method"
-          :options="
-            item.source.type === 'Number'
-              ? OptionsConditionNumber
-              : OptionsConditionString
-          "
+          :options="getOptions(item.source.type)"
         />
       </div>
       <div
@@ -64,9 +60,11 @@ import { getCurrentInstance, reactive, watch } from 'vue'
 import {
   ConditionMode,
   ConditionNumber,
+  ConditionOther,
   ConditionString,
   ConditionType,
   OptionsConditionNumber,
+  OptionsConditionOther,
   OptionsConditionString,
   OptionsConditionType,
 } from '@/views/workflow/types'
@@ -84,8 +82,10 @@ watch(
   (n) => {
     if (n.type === 'Number') {
       props.item.method = ConditionNumber.Equals
-    } else {
+    } else if (n.type === 'String') {
       props.item.method = ConditionString.Includes
+    } else {
+      props.item.method = ConditionOther.NotEmpty
     }
     props.item.type = ConditionType.Constant
     props.item.target = ''
@@ -107,6 +107,14 @@ watch(
   },
   { deep: true },
 )
+const getOptions = (type) => {
+  if (type === 'Number') {
+    return OptionsConditionNumber
+  } else if (type === 'String') {
+    return OptionsConditionString
+  }
+  return OptionsConditionOther
+}
 </script>
 
 <style lang="scss" scoped>

+ 5 - 2
src/views/workflow/instance/if-else/panel/index.vue

@@ -63,7 +63,7 @@
 </template>
 
 <script setup lang="ts">
-import { getCurrentInstance, inject, reactive, ref, watch } from 'vue'
+import { getCurrentInstance, reactive, watch } from 'vue'
 import { v4 } from 'uuid'
 import { useWorkflowStore } from '@/stores'
 import ifElseNodeDefault from '../default'
@@ -72,6 +72,7 @@ import varsPopover from '@/views/workflow/instance/component/vars/vars-popover.v
 import conditionIndex from '@/views/workflow/instance/component/condition/condition-index.vue'
 import {
   ConditionNumber,
+  ConditionOther,
   ConditionString,
   ConditionType,
 } from '@/views/workflow/types'
@@ -127,7 +128,9 @@ const onAddCondition = (caseIndex, vars) => {
     method:
       vars.type === 'Number'
         ? ConditionNumber.Equals
-        : ConditionString.Includes,
+        : vars.type === 'String'
+          ? ConditionString.Includes
+          : ConditionOther.NotEmpty,
     type: ConditionType.Constant,
     target: '',
   })

+ 10 - 0
src/views/workflow/types.ts

@@ -87,6 +87,11 @@ export enum ConditionNumber {
   NotEmpty = 'not empty',
 }
 
+export enum ConditionOther {
+  Empty = 'empty',
+  NotEmpty = 'not empty',
+}
+
 export const OptionsConditionString = [
   { value: ConditionString.Includes, label: '包含' },
   { value: ConditionString.NotIncludes, label: '不包含' },
@@ -109,6 +114,11 @@ export const OptionsConditionNumber = [
   { value: ConditionNumber.NotEmpty, label: '不为空' },
 ]
 
+export const OptionsConditionOther = [
+  { value: ConditionOther.Empty, label: '为空' },
+  { value: ConditionOther.NotEmpty, label: '不为空' },
+]
+
 export enum ConditionType {
   Constant = 'constant',
   Variable = 'variable',