From f23d0774f82661e2906405abaea77c4fd9315522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B1=BC=E6=98=9F?= <1772580802@qq.com> Date: Tue, 2 Jun 2026 14:01:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sideBar/config/localNodeData.ts | 1 + src/utils/convertFlowData.ts | 44 +++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/pages/flowEditor/sideBar/config/localNodeData.ts b/src/pages/flowEditor/sideBar/config/localNodeData.ts index 265c3e8..88bb984 100644 --- a/src/pages/flowEditor/sideBar/config/localNodeData.ts +++ b/src/pages/flowEditor/sideBar/config/localNodeData.ts @@ -84,6 +84,7 @@ const imageParameters = { defaultValue: '' }], dataIns: [{ + id: 'in', name: 'in', desc: 'url', dataType: 'STRING', diff --git a/src/utils/convertFlowData.ts b/src/utils/convertFlowData.ts index f650169..0e1a3bf 100644 --- a/src/utils/convertFlowData.ts +++ b/src/utils/convertFlowData.ts @@ -4,6 +4,28 @@ import LoopNode from '@/components/FlowEditor/node/loopNode/LoopNode'; import { updateEventNodeList } from '@/store/ideContainer'; import { resolveNodeComponent } from '@/utils/flow/nodeRegistry'; +const runtimeToEditorNodeTypeMap: Record = { + SHOW_IMAGE: 'IMAGE', + SHOW_RESULT: 'RESULT', + JSON_CONVERT: 'JSONCONVERT', +}; + +const editorToRuntimeNodeTypeMap: Record = { + IMAGE: 'SHOW_IMAGE', + RESULT: 'SHOW_RESULT', + JSONCONVERT: 'JSON_CONVERT', +}; + +export const toEditorNodeType = (type?: string) => { + if (!type) return type; + return runtimeToEditorNodeTypeMap[type] || type; +}; + +export const toRuntimeComponentType = (type?: string) => { + if (!type) return type; + return editorToRuntimeNodeTypeMap[type] || type; +}; + /** * 将提供的数据结构转换为适用于 flow editor 的 nodes 和 edges * @param flowData - 原始数据结构 @@ -117,17 +139,18 @@ export const convertFlowData = (flowData: any, useDefault = true) => { // 确定节点类型 let nodeType = 'BASIC'; + const componentType = toEditorNodeType(nodeConfig.component?.type); if (nodeId.includes('start')) { nodeType = 'start'; } else if (nodeId.includes('end')) { nodeType = 'end'; } else if ( - nodeConfig.component?.type === 'LOOP_START' || - nodeConfig.component?.type === 'LOOP_END' + componentType === 'LOOP_START' || + componentType === 'LOOP_END' ) { nodeType = 'LOOP'; } else { - nodeType = nodeConfig.component?.type || 'BASIC'; + nodeType = componentType || 'BASIC'; } // 解析位置信息 const position = nodeConfig.position || { x: 0, y: 0 }; @@ -145,13 +168,13 @@ export const convertFlowData = (flowData: any, useDefault = true) => { dataIns: getNodeDataIns(nodeConfig), dataOuts: nodeConfig.dataOuts || [], }, - type: nodeConfig.component?.type || nodeType, + type: componentType || nodeType, }, }; // 添加组件标识信息 if (nodeConfig.component) { - node.data.component = { ...nodeConfig.component }; + node.data.component = { ...nodeConfig.component, type: componentType }; node.data.compId = nodeConfig.component.compId; } @@ -470,7 +493,7 @@ export const revertFlowData = (nodes: any[], edges: any[]) => { // 处理 component 信息 if (node.data?.component) { nodeConfig.component = { - type: nodeType, + type: toRuntimeComponentType(nodeType), compIdentifier: node.data.component.compIdentifier || '', compInstanceIdentifier: node.data.component.compInstanceIdentifier || '', @@ -481,7 +504,7 @@ export const revertFlowData = (nodes: any[], edges: any[]) => { } else if (nodeType !== 'start' && nodeType !== 'end') { // 对于非 start/end 节点,添加基本的 component 信息 nodeConfig.component = { - type: nodeType, + type: toRuntimeComponentType(nodeType), }; } if (['BASIC', 'SUB'].includes(nodeType)) @@ -624,10 +647,13 @@ export const reverseConvertFlowData = ( }), }; } else if (node.data?.component) { - nodeConfig.component = { ...node.data.component }; + nodeConfig.component = { + ...node.data.component, + type: toRuntimeComponentType(node.data.component.type || node.type), + }; } else { nodeConfig.component = { - type: node.type, + type: toRuntimeComponentType(node.type), }; }