From 9bb142e40348697620a67ae2d68230878083f4a1 Mon Sep 17 00:00:00 2001 From: ZLY Date: Tue, 23 Sep 2025 16:03:13 +0800 Subject: [PATCH] =?UTF-8?q?pref(ideContainer)=EF=BC=9A=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96tab=E7=BB=84=E4=BB=B6=E5=92=8CmenuData=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AF=B9=E4=BA=8Ekey=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/flowEditor/utils/convertFlowData.ts | 81 ------------------- src/pages/ideContainer/index.tsx | 15 ++-- src/pages/ideContainer/sideBar.tsx | 2 +- src/utils/convertFlowData.ts | 2 - 4 files changed, 8 insertions(+), 92 deletions(-) delete mode 100644 src/pages/flowEditor/utils/convertFlowData.ts diff --git a/src/pages/flowEditor/utils/convertFlowData.ts b/src/pages/flowEditor/utils/convertFlowData.ts deleted file mode 100644 index 7501f4b..0000000 --- a/src/pages/flowEditor/utils/convertFlowData.ts +++ /dev/null @@ -1,81 +0,0 @@ -/** - * 将提供的数据结构转换为适用于 flow editor 的 nodes 和 edges - * @param flowData - 原始数据结构 - * @returns 包含 nodes 和 edges 的对象 - */ -export const convertFlowData = (flowData: any) => { - const nodes: any[] = []; - const edges: any[] = []; - - // 处理节点配置 - const nodeConfigs = flowData.main?.nodeConfigs || []; - for (const nodeConfig of nodeConfigs) { - // 确定节点类型 - let nodeType = 'draggable'; - if (nodeConfig.nodeId === 'start') { - nodeType = 'start'; - } else if (nodeConfig.nodeId === 'end') { - nodeType = 'end'; - } - - // 解析位置信息 - let position = { x: 0, y: 0 }; - try { - const x6Data = JSON.parse(nodeConfig.x6); - position = x6Data.position || { x: 0, y: 0 }; - } catch (e) { - console.warn('Failed to parse position for node:', nodeConfig.nodeId); - } - - // 构造节点数据 - const node: any = { - id: nodeConfig.nodeId, - type: nodeType, - position, - data: { - title: nodeConfig.nodeName || nodeConfig.nodeId, - type: nodeType, // 添加节点类型到data中,供NodeContent使用 - parameters: { - inputs: nodeConfig.dataIns?.map((input: any) => ({ - name: input.id, - desc: input.desc, - dataType: input.dataType, - defaultValue: input.defaultValue - })) || [], - outputs: nodeConfig.dataOuts?.map((output: any) => ({ - name: output.id, - desc: output.desc, - dataType: output.dataType, - defaultValue: output.defaultValue - })) || [] - } - } - }; - - // 如果是机械臂节点,添加组件标识信息 - if (nodeConfig.component) { - node.data.component = { - compIdentifier: nodeConfig.component.compIdentifier, - compInstanceIdentifier: nodeConfig.component.compInstanceIdentifier - }; - } - - nodes.push(node); - } - - // 处理连线配置 - const lineConfigs = flowData.main?.lineConfigs || []; - for (const lineConfig of lineConfigs) { - const edge: any = { - id: lineConfig.id, - source: lineConfig.prev.nodeId, - target: lineConfig.next.nodeId, - sourceHandle: lineConfig.prev.endpointId, - targetHandle: lineConfig.next.endpointId - }; - - edges.push(edge); - } - - return { nodes, edges }; -}; \ No newline at end of file diff --git a/src/pages/ideContainer/index.tsx b/src/pages/ideContainer/index.tsx index 090426b..3f6eb54 100644 --- a/src/pages/ideContainer/index.tsx +++ b/src/pages/ideContainer/index.tsx @@ -38,7 +38,6 @@ const ALL_PATHS = [ ]; function IDEContainer() { - const [selected, setSelected] = useState({}); const [urlParams, setUrlParams] = useState({}); const [subMenuWidth, setSubMenuWidth] = useState(200); // 子菜单宽度状态 @@ -69,25 +68,25 @@ function IDEContainer() { // 当selected.path变化时,添加到已打开的tab集合中 useEffect(() => { - if (selected.path) { - setOpenedTabs(prev => new Set(prev).add(selected.path!)); + if (selected.key) { + setOpenedTabs(prev => new Set(prev).add(selected.key!)); } - }, [selected.path]); + }, [selected.key]); // 根据选中的菜单项渲染对应组件 const renderContent = () => { return (
- {ALL_PATHS.map(path => { + {ALL_PATHS.map((path, i) => { // 检查该路径的组件是否已打开 - const isOpened = openedTabs.has(path); + const isOpened = openedTabs.has(selected.key); // 检查是否是当前选中的路径 const isSelected = selected.path === path; // 只有已打开的组件才渲染,通过CSS控制显示/隐藏 return isOpened ? (
= ({ selectedKey, identity, subMenuData, o v.title = v.name; v.key = `compFlow-${v.id}`; v.path = 'compFlow'; - v.parentKey = selectedKey; + v.parentKey = menu[activeKey]?.key; v.children = null; }); menuData[menuIndex]['children'] = subMenuValue; diff --git a/src/utils/convertFlowData.ts b/src/utils/convertFlowData.ts index 9ed23eb..593e8a9 100644 --- a/src/utils/convertFlowData.ts +++ b/src/utils/convertFlowData.ts @@ -93,7 +93,5 @@ export const convertFlowData = (flowData: any) => { edges.push(edge); } - console.log('nodes, edges:', nodes, edges); - return { nodes, edges }; }; \ No newline at end of file