From 692a6030ebbf3a626df7301ed3e2ccd10aa15eca Mon Sep 17 00:00:00 2001 From: dengqichen Date: Fri, 13 Dec 2024 16:25:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=85=B7=E6=A0=8F?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Workflow/Definition/Design/index.tsx | 12 ++++---- .../Definition/Design/utils/nodeUtils.ts | 30 +++++-------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/frontend/src/pages/Workflow/Definition/Design/index.tsx b/frontend/src/pages/Workflow/Definition/Design/index.tsx index 0c1062a4..29f81897 100644 --- a/frontend/src/pages/Workflow/Definition/Design/index.tsx +++ b/frontend/src/pages/Workflow/Definition/Design/index.tsx @@ -97,11 +97,12 @@ const WorkflowDesign: React.FC = () => { // 节点双击事件 graph.on('node:dblclick', ({ node }) => { const nodeType = node.getProp('type'); + console.log(nodeType) // 从节点定义列表中找到对应的定义 - const definition = nodeDefinitions.find(def => def.type === nodeType); - if (definition) { + const nodeDefinition = nodeDefinitions.find(def => def.type === nodeType); + if (nodeDefinition) { setSelectedNode(node); - setSelectedNodeDefinition(definition); + setSelectedNodeDefinition(nodeDefinition); setConfigModalVisible(true); } }); @@ -129,7 +130,7 @@ const WorkflowDesign: React.FC = () => { const nodeMap = new Map(); // 创建节点 - response.graph.nodes.forEach((workflowDefinitionNode: any) => { + response.graph?.nodes?.forEach((workflowDefinitionNode: any) => { console.log('Creating node with data:', workflowDefinitionNode); // 添加日志 const node = addNodeToGraph(false, graphInstance, workflowDefinitionNode, nodeDefinitions); @@ -139,7 +140,7 @@ const WorkflowDesign: React.FC = () => { }); // 创建边 - response.graph.edges.forEach((edge: any) => { + response.graph?.edges?.forEach((edge: any) => { const sourceNode = nodeMap.get(edge.from); const targetNode = nodeMap.get(edge.to); if (sourceNode && targetNode) { @@ -190,7 +191,6 @@ const WorkflowDesign: React.FC = () => { const handleNodeConfigUpdate = (values: any) => { if (!selectedNode) return; - // 更新节点配置 selectedNode.setProp('config', values); // 更新节点显示名称 diff --git a/frontend/src/pages/Workflow/Definition/Design/utils/nodeUtils.ts b/frontend/src/pages/Workflow/Definition/Design/utils/nodeUtils.ts index 741b5076..276291d8 100644 --- a/frontend/src/pages/Workflow/Definition/Design/utils/nodeUtils.ts +++ b/frontend/src/pages/Workflow/Definition/Design/utils/nodeUtils.ts @@ -1,18 +1,6 @@ import {Graph} from '@antv/x6'; import {convertPortConfig} from '../constants'; - -/** - * 创建节点配置 - */ -const createNodeConfig = (uiGraph: any) => { - return { - inherit: 'rect', // 默认使用矩形 - - - }; -}; - /** * 添加节点到图形 * @param graph X6 Graph实例 @@ -37,34 +25,32 @@ export const addNodeToGraph = ( } else if (uiGraph.shape === 'diamond') { shape = 'polygon'; } - const nodeConfig = createNodeConfig(uiGraph); + console.log(nodeDefinition.type, workflowDefinitionNode.type) // 创建节点 return graph.addNode({ - ...nodeConfig, + inherit: 'rect', width: uiGraph.size.width, height: uiGraph.size.height, - label: { - text: isNew ? workflowDefinitionNode.name : nodeDefinition.name, - fill: '#000000', - fontSize: 12, - }, attrs: { body: { ...uiGraph.style, - // 如果是菱形,添加多边形的点 ...(uiGraph.shape === 'diamond' ? { refPoints: '0,10 10,0 20,10 10,20', } : {}) - } + }, + label: { + text: isNew ? nodeDefinition.name : workflowDefinitionNode.name + }, }, shape, // 使用映射后的形状 ...(position && {x: position.x, y: position.y}), // 如果是已保存的节点,使用其ID和位置 ...(uiGraph.id && {id: uiGraph.id}), ...(uiGraph.graph?.position && {position: uiGraph.graph.position}), - type: uiGraph.type, + type: isNew ? nodeDefinition.type : workflowDefinitionNode.type, code: uiGraph.code, ports: convertPortConfig(uiGraph.ports), nodeDefinition: nodeDefinition, + aaaaaa: "dasdasdsadasdd" }); }; \ No newline at end of file