浏览代码

条件分支

CzRger 1 天之前
父节点
当前提交
1966b8db67
共有 1 个文件被更改,包括 37 次插入27 次删除
  1. 37 27
      src/views/workflow/handle.ts

+ 37 - 27
src/views/workflow/handle.ts

@@ -275,33 +275,43 @@ export const handleNodeSubmit = (no) => {
       break
     case NodeType.IfElse:
       {
-        no.cases = no.__ports.map((v) => {
-          const obj = {
-            id: v.id,
-            case_id: v.id,
-            logical_operator: v.mode,
-            conditions:
-              v.cases?.map((c) => {
-                const cObj = {
-                  id: c.id,
-                  varType: c.source.type.toLowerCase(),
-                  variable_selector:
-                    c.source.source === VarsSource.Root
-                      ? [c.source.key.split('.')[0], c.source.key.split('.')[1]]
-                      : [c.source.nodeId, c.source.key],
-                  comparison_operator: c.method,
-                  value:
-                    c.type === ConditionType.Constant
-                      ? c.target
-                      : c.target.source === VarsSource.Root
-                        ? `{{#${c.target.key.split('.')[0]}.${c.target.key.split('.')[1]}#}}`
-                        : `{{#${c.target.nodeId}.${c.target.key}#}}`,
-                }
-                return cObj
-              }) || [],
-          }
-          return obj
-        })
+        no.cases = no.__ports
+          .filter((v) => !v.isElse)
+          .map((v) => {
+            const obj = {
+              id: v.id,
+              case_id: v.id,
+              logical_operator: v.mode,
+              conditions:
+                v.cases?.map((c) => {
+                  const cObj = {
+                    id: c.id,
+                    varType: c.source.type.toLowerCase(),
+                    variable_selector:
+                      c.source.source === VarsSource.Root
+                        ? [
+                            c.source.key.split('.')[0],
+                            c.source.key.split('.')[1],
+                          ]
+                        : [c.source.nodeId, c.source.key],
+                    comparison_operator: c.method,
+                    value:
+                      c.type === ConditionType.Constant
+                        ? c.target
+                        : c.target.source === VarsSource.Root
+                          ? `{{#${c.target.key.split('.')[0]}.${c.target.key.split('.')[1]}#}}`
+                          : `{{#${c.target.nodeId}.${c.target.key}#}}`,
+                  }
+                  if (cObj.varType === 'number') {
+                    cObj.numberVarType = c.type
+                  } else if (cObj.varType === 'string') {
+                    cObj.stringVarType = c.type
+                  }
+                  return cObj
+                }) || [],
+            }
+            return obj
+          })
       }
       break
   }