From b784cb158b83e865971eb33db729903404f51b27 Mon Sep 17 00:00:00 2001 From: ZLY Date: Wed, 27 Aug 2025 10:44:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(flowEditor):=20=E6=B7=BB=E5=8A=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 开始节点和结束节点 --- src/pages/flowEditor/index.tsx | 8 +- src/pages/flowEditor/node/endNode/EndNode.tsx | 94 +++++++++++++++++-- .../flowEditor/node/startNode/StartNode.tsx | 94 +++++++++++++++++-- .../flowEditor/node/style/base.module.less | 47 ++++++++++ 4 files changed, 219 insertions(+), 24 deletions(-) create mode 100644 src/pages/flowEditor/node/style/base.module.less diff --git a/src/pages/flowEditor/index.tsx b/src/pages/flowEditor/index.tsx index be985b3..c774e29 100644 --- a/src/pages/flowEditor/index.tsx +++ b/src/pages/flowEditor/index.tsx @@ -36,14 +36,14 @@ const initialNodes: Node[] = [ }, { id: 'end-node', - position: { x: 300, y: 200 }, + position: { x: 1000, y: 0 }, data: { label: '结束' }, type: 'end' }, { id: 'node-1', type: 'textUpdater', - position: { x: 150, y: 0 }, + position: { x: 400, y: 0 }, data: { value: 123 } } ]; @@ -111,14 +111,14 @@ const FlowEditor: React.FC = () => { const position = reactFlowInstance.screenToFlowPosition({ x: event.clientX, - y: event.clientY, + y: event.clientY }); const newNode = { id: `${type}-${Date.now()}`, type, position, - data: { label: `${type} node` }, + data: { label: `${type} node` } }; setNodes((nds) => nds.concat(newNode)); diff --git a/src/pages/flowEditor/node/endNode/EndNode.tsx b/src/pages/flowEditor/node/endNode/EndNode.tsx index 4f21b88..ea7d654 100644 --- a/src/pages/flowEditor/node/endNode/EndNode.tsx +++ b/src/pages/flowEditor/node/endNode/EndNode.tsx @@ -1,22 +1,96 @@ import React from 'react'; import { Handle, Position } from '@xyflow/react'; +import styles from '@/pages/flowEditor/node/style/base.module.less'; + +interface EndNodeData { + title?: string; + parameters?: { + inputs?: any[]; + outputs?: any[]; + }; + showFooter?: boolean; + + [key: string]: any; +} + +const EndNode = ({ data }: { data: EndNodeData }) => { + const title = data.title || '结束'; + const inputs = data.parameters?.inputs || []; + const outputs = data.parameters?.outputs || []; + const showFooter = data.showFooter || false; -const EndNode = ({ data }: { data: any }) => { return ( -
-
结束
+
+
+ {title} +
+ +
+ {inputs.length > 0 && ( +
+ {inputs.map((input, index) => ( +
+ {input.name || `输入${index + 1}`} +
+ ))} +
+ )} + + {outputs.length > 0 && ( +
+ {outputs.map((output, index) => ( +
+ {output.name || `输出${index + 1}`} +
+ ))} +
+ )} +
+ + {showFooter && ( +
+ 暂定的footer +
+ )} + + {/* Dynamic handles based on parameters */} + + {/* Add additional handles based on parameters */} + {inputs.map((_, index) => ( + + ))} + + {outputs.map((_, index) => ( + + ))}
); }; diff --git a/src/pages/flowEditor/node/startNode/StartNode.tsx b/src/pages/flowEditor/node/startNode/StartNode.tsx index 8e55995..1c92f1a 100644 --- a/src/pages/flowEditor/node/startNode/StartNode.tsx +++ b/src/pages/flowEditor/node/startNode/StartNode.tsx @@ -1,22 +1,96 @@ import React from 'react'; import { Handle, Position } from '@xyflow/react'; +import styles from '@/pages/flowEditor/node/style/base.module.less'; -const StartNode = ({ data }: { data: any }) => { +interface StartNodeData { + title?: string; + parameters?: { + inputs?: any[]; + outputs?: any[]; + }; + showFooter?: boolean; + + [key: string]: any; +} + +const StartNode = ({ data }: { data: StartNodeData }) => { + const title = data.title || '开始'; + const inputs = data.parameters?.inputs || []; + const outputs = data.parameters?.outputs || []; + const showFooter = data.showFooter || false; return ( -
-
开始
+
+
+ {title} +
+ +
+ + {inputs.length > 0 && ( +
+ {inputs.map((input, index) => ( +
+ {input.name || `输入${index + 1}`} +
+ ))} +
+ )} + + {outputs.length > 0 && ( +
+ {outputs.map((output, index) => ( +
+ {output.name || `输出${index + 1}`} +
+ ))} +
+ )} +
+ + {showFooter && ( +
+ 暂定的footer +
+ )} + + {/* Dynamic handles based on parameters */} + + {/* Add additional handles based on parameters */} + {inputs.map((_, index) => ( + + ))} + + {outputs.map((_, index) => ( + + ))}
); }; diff --git a/src/pages/flowEditor/node/style/base.module.less b/src/pages/flowEditor/node/style/base.module.less new file mode 100644 index 0000000..611bcb4 --- /dev/null +++ b/src/pages/flowEditor/node/style/base.module.less @@ -0,0 +1,47 @@ +.node-container { + border-radius: 10px; + overflow: hidden; + color: white; + min-width: 150px; + font-size: 14px; + + .node-header { + padding: 5px 15px; + border-bottom: 1px solid rgba(255, 255, 255, 0.2); + } + + .node-content { + display: flex; + background-color: #ffffff; + color: #000000; + padding: 15px 5px; + min-height: 10px; + + .node-inputs, + .node-outputs { + flex: 1; + + .node-input-label { + font-size: 12px; + padding: 2px 0; + } + } + + .node-inputs { + margin-bottom: 5px; + margin-right: 30px; + } + + .node-outputs { + text-align: right; + } + } + + .node-footer { + background-color: #ffffff; + color: #000000; + padding: 5px 20px; + border-top: 1px solid rgba(204, 204, 204, 0.18); + min-height: 20px; + } +} \ No newline at end of file