From d7ca2dbd3b1df4f12eda435e6f8e4b0939fbba5a Mon Sep 17 00:00:00 2001 From: ZLY Date: Tue, 4 Nov 2025 09:32:03 +0800 Subject: [PATCH] =?UTF-8?q?pref(flow):=20=E4=BC=98=E5=8C=96=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E4=BF=9D=E5=AD=98=E5=90=8E=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=E5=92=8C=E5=AD=90=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E7=9A=84=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useFlowCallbacks.ts | 70 +++++++++++++++++++++++++++-------- src/utils/convertFlowData.ts | 2 +- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/hooks/useFlowCallbacks.ts b/src/hooks/useFlowCallbacks.ts index 71f938d..8d8b294 100644 --- a/src/hooks/useFlowCallbacks.ts +++ b/src/hooks/useFlowCallbacks.ts @@ -7,7 +7,7 @@ import { Node, Edge } from '@xyflow/react'; -import { refPublish, setMainFlow, setMainFlowNew, setSubFlowNew } from '@/api/appRes'; +import { getAppInfoNew, setMainFlowNew, setSubFlowNew } from '@/api/appRes'; import { Message } from '@arco-design/web-react'; import { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node'; import { convertFlowData, reverseConvertFlowData, revertFlowData } from '@/utils/convertFlowData'; @@ -22,7 +22,7 @@ import { updateEventListOld, addRuntimeLog, clearRuntimeLogs, - updateRuntimeId + updateRuntimeId, updateFlowData } from '@/store/ideContainer'; import { validateAllNodes, @@ -912,18 +912,24 @@ export const useFlowCallbacks = ( }; } else if (nodeType === 'SUB') { - const flowMainData = flowData[currentAppData.id]?.main?.components; - const sameData: any = Object.values(flowMainData).filter((item: any) => { - if (item?.component?.compId === newNode.data.compId) return item; - }); - if (sameData.length) { + const flowSubMap = flowData[currentAppData.id]?.subMap || {}; + const sameData: any = flowSubMap[newNode.data.compId]; + if (sameData) { newNode.data.component = { - ...sameData[0].component + type: nodeType, + compId: newNode.data.compId, + customDef: JSON.stringify({ + dataIns: newNode.data.parameters.dataIns, + dataOuts: newNode.data.parameters.dataOuts, + subflowId: sameData, + name: newNode.data.title + }) }; } else { newNode.data.component = { - type: nodeType + type: nodeType, + compId: newNode.data.compId }; } } @@ -1061,18 +1067,24 @@ export const useFlowCallbacks = ( }; } else if (nodeType === 'SUB') { - const flowMainData = flowData[currentAppData.id]?.main?.components; - const sameData: any = Object.values(flowMainData).filter((item: any) => { - if (item?.component?.compId === newNode.data.compId) return item; - }); - if (sameData.length) { + const flowSubMap = flowData[currentAppData.id]?.subMap || {}; + const sameData: any = flowSubMap[newNode.data.compId]; + if (sameData) { newNode.data.component = { - ...sameData[0].component + type: nodeType, + compId: newNode.data.compId, + customDef: JSON.stringify({ + dataIns: newNode.data.parameters.dataIns, + dataOuts: newNode.data.parameters.dataOuts, + subflowId: sameData, + name: newNode.data.title + }) }; } else { newNode.data.component = { - type: nodeType + type: nodeType, + compId: newNode.data.compId }; } } @@ -1174,6 +1186,19 @@ export const useFlowCallbacks = ( ...canvasDataMap, [currentAppData.id]: { nodes, edges } })); + const appRes: any = await getAppInfoNew(currentAppData.id); + // 更新 flowData 中的数据 + dispatch(updateFlowData({ [currentAppData.id]: appRes.data })); + // 同步更新到 canvasDataMap + if (appRes.data.main?.components) { + const { nodes, edges } = convertFlowData(appRes.data.main.components, true); + setNodes(nodes); + setEdges(edges); + dispatch(updateCanvasDataMap({ + ...canvasDataMap, + [currentAppData.id]: { nodes, edges } + })); + } } else { Message.error(res.message); @@ -1200,6 +1225,19 @@ export const useFlowCallbacks = ( ...canvasDataMap, [currentAppData.id]: { nodes, edges } })); + const appRes: any = await getAppInfoNew(currentAppData.id); + // 更新 flowData 中的数据 + dispatch(updateFlowData({ [currentAppData.id]: appRes.data })); + // 同步更新到 canvasDataMap + if (appRes.data.main?.components) { + const { nodes, edges } = convertFlowData(appRes.data.main.components, true); + setNodes(nodes); + setEdges(edges); + dispatch(updateCanvasDataMap({ + ...canvasDataMap, + [currentAppData.id]: { nodes, edges } + })); + } } else { Message.error(res.message); diff --git a/src/utils/convertFlowData.ts b/src/utils/convertFlowData.ts index 142e5ba..1ee4ab4 100644 --- a/src/utils/convertFlowData.ts +++ b/src/utils/convertFlowData.ts @@ -536,7 +536,7 @@ export const reverseConvertFlowData = (nodes: any[], edges: any[], complexKV: an }; // 处理 component 信息 - if (node.type === 'SUB' && !node.customDef) { + if (node.type === 'SUB' && !node.data.component.customDef) { nodeConfig.component = { type: 'SUB', compId: node.data.compId,