@@ -25,72 +22,7 @@ const EndNode = ({ data }: { data: EndNodeData }) => {
{title}
-
- {inputs.length > 0 && (
-
- {inputs.map((input, index) => (
-
- {input.name || `输入${index + 1}`}
-
- ))}
-
- )}
-
- {outputs.length > 0 && (
-
- {outputs.map((output, index) => (
-
- {output.name || `输出${index + 1}`}
-
- ))}
-
- )}
-
-
- {showFooter && (
-
{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/test/exampleFlowData.ts b/src/pages/flowEditor/test/exampleFlowData.ts
new file mode 100644
index 0000000..68da610
--- /dev/null
+++ b/src/pages/flowEditor/test/exampleFlowData.ts
@@ -0,0 +1,288 @@
+export const exampleFlowData = {
+ 'main': {
+ 'id': 'main',
+ 'lineConfigs': [
+ {
+ 'id': '437d6a3c-ae8f-4a34-a195-33dcfa9747cf',
+ 'lineType': 'API',
+ 'next': {
+ 'endpointId': 'move',
+ 'nodeId': 'node_34'
+ },
+ 'prev': {
+ 'endpointId': 'start',
+ 'nodeId': 'start'
+ },
+ 'x6': '{"vertices":[]}'
+ },
+ {
+ 'id': '7f9b61cd-eb12-4914-af90-85ec73bf1fec',
+ 'lineType': 'API',
+ 'next': {
+ 'endpointId': 'controlClaw',
+ 'nodeId': 'node_43'
+ },
+ 'prev': {
+ 'endpointId': 'done',
+ 'nodeId': 'node_34'
+ },
+ 'x6': '{"vertices":[]}'
+ },
+ {
+ 'id': '6f670427-d8a5-494e-ae25-ffa1491014bf',
+ 'lineType': 'API',
+ 'next': {
+ 'endpointId': 'move',
+ 'nodeId': 'node_17'
+ },
+ 'prev': {
+ 'endpointId': 'done',
+ 'nodeId': 'node_43'
+ },
+ 'x6': '{"vertices":[]}'
+ },
+ {
+ 'id': '621f19c1-8d7c-48f7-8158-17418b118fa2',
+ 'lineType': 'API',
+ 'next': {
+ 'endpointId': 'end',
+ 'nodeId': 'end'
+ },
+ 'prev': {
+ 'endpointId': 'done',
+ 'nodeId': 'node_17'
+ },
+ 'x6': '{"vertices":[]}'
+ }
+ ],
+ 'name': '',
+ 'nodeConfigs': [
+ {
+ 'apiId': '',
+ 'component': null,
+ 'dataIns': [],
+ 'dataOfPrevNodeMap': {},
+ 'dataOuts': [],
+ 'defaultValues': [],
+ 'description': '',
+ 'joinLines': {},
+ 'nodeId': 'start',
+ 'nodeName': '',
+ 'x6': '{"position":{"x":-550,"y":-25}}'
+ },
+ {
+ 'apiId': '',
+ 'component': {
+ 'compIdentifier': 'admin_dazu-mechanical-arm',
+ 'compInstanceIdentifier': 'admin_dazu-mechanical-arm',
+ 'customDef': '',
+ 'type': 'BASIC'
+ },
+ 'dataIns': [
+ {
+ 'arrayType': null,
+ 'dataType': null,
+ 'defaultValue': null,
+ 'desc': '',
+ 'id': 'input'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 50,
+ 'desc': '力值(百分比:20-100)',
+ 'id': 'force'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 850,
+ 'desc': '位置(千分比:0-1000)',
+ 'id': 'location'
+ },
+ {
+ 'arrayType': 'DOUBLE',
+ 'dataType': 'ARRAY',
+ 'defaultValue': [
+ 64.018,
+ 912.91,
+ 373.288,
+ -171.439,
+ 75.154,
+ -81.128
+ ],
+ 'desc': '六位坐标',
+ 'id': 'position'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 20,
+ 'desc': '速度(百分比:1-100)',
+ 'id': 'speed'
+ }
+ ],
+ 'dataOfPrevNodeMap': {},
+ 'dataOuts': [
+ {
+ 'arrayType': null,
+ 'dataType': null,
+ 'defaultValue': null,
+ 'desc': '',
+ 'id': 'output'
+ }
+ ],
+ 'defaultValues': [],
+ 'description': '',
+ 'joinLines': {},
+ 'nodeId': 'node_34',
+ 'nodeName': 'mechanical-arm',
+ 'x6': '{"position":{"x":-360,"y":-120}}'
+ },
+ {
+ 'apiId': '',
+ 'component': {
+ 'compIdentifier': 'admin_dazu-mechanical-arm',
+ 'compInstanceIdentifier': 'admin_dazu-mechanical-arm',
+ 'customDef': '',
+ 'type': 'BASIC'
+ },
+ 'dataIns': [
+ {
+ 'arrayType': null,
+ 'dataType': null,
+ 'defaultValue': null,
+ 'desc': '',
+ 'id': 'input'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 50,
+ 'desc': '力值(百分比:20-100)',
+ 'id': 'force'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 950,
+ 'desc': '位置(千分比:0-1000)',
+ 'id': 'location'
+ },
+ {
+ 'arrayType': 'DOUBLE',
+ 'dataType': 'ARRAY',
+ 'defaultValue': null,
+ 'desc': '六位坐标',
+ 'id': 'position'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 20,
+ 'desc': '速度(百分比:1-100)',
+ 'id': 'speed'
+ }
+ ],
+ 'dataOfPrevNodeMap': {},
+ 'dataOuts': [
+ {
+ 'arrayType': null,
+ 'dataType': null,
+ 'defaultValue': null,
+ 'desc': '',
+ 'id': 'output'
+ }
+ ],
+ 'defaultValues': [],
+ 'description': '',
+ 'joinLines': {},
+ 'nodeId': 'node_43',
+ 'nodeName': 'mechanical-arm',
+ 'x6': '{"position":{"x":-120,"y":-145}}'
+ },
+ {
+ 'apiId': '',
+ 'component': {
+ 'compIdentifier': 'admin_dazu-mechanical-arm',
+ 'compInstanceIdentifier': 'admin_dazu-mechanical-arm',
+ 'customDef': '',
+ 'type': 'BASIC'
+ },
+ 'dataIns': [
+ {
+ 'arrayType': null,
+ 'dataType': null,
+ 'defaultValue': null,
+ 'desc': '',
+ 'id': 'input'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 50,
+ 'desc': '力值(百分比:20-100)',
+ 'id': 'force'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 850,
+ 'desc': '位置(千分比:0-1000)',
+ 'id': 'location'
+ },
+ {
+ 'arrayType': 'DOUBLE',
+ 'dataType': 'ARRAY',
+ 'defaultValue': [
+ -224.639,
+ 216.57,
+ 574.605,
+ -156,
+ 81.787,
+ -74.001
+ ],
+ 'desc': '六位坐标',
+ 'id': 'position'
+ },
+ {
+ 'arrayType': null,
+ 'dataType': 'INTEGER',
+ 'defaultValue': 20,
+ 'desc': '速度(百分比:1-100)',
+ 'id': 'speed'
+ }
+ ],
+ 'dataOfPrevNodeMap': {},
+ 'dataOuts': [
+ {
+ 'arrayType': null,
+ 'dataType': null,
+ 'defaultValue': null,
+ 'desc': '',
+ 'id': 'output'
+ }
+ ],
+ 'defaultValues': [],
+ 'description': '',
+ 'joinLines': {},
+ 'nodeId': 'node_17',
+ 'nodeName': 'mechanical-arm',
+ 'x6': '{"position":{"x":120,"y":-120}}'
+ },
+ {
+ 'apiId': '',
+ 'component': null,
+ 'dataIns': [],
+ 'dataOfPrevNodeMap': {},
+ 'dataOuts': [],
+ 'defaultValues': [],
+ 'description': '',
+ 'joinLines': {},
+ 'nodeId': 'end',
+ 'nodeName': '',
+ 'x6': '{"position":{"x":370,"y":0}}'
+ }
+ ]
+ }
+};
\ No newline at end of file
diff --git a/src/utils/convertFlowData.ts b/src/utils/convertFlowData.ts
new file mode 100644
index 0000000..f5f5de7
--- /dev/null
+++ b/src/utils/convertFlowData.ts
@@ -0,0 +1,86 @@
+/**
+ * 将提供的数据结构转换为适用于 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 = 'BASIC';
+ if (nodeConfig.nodeId === 'start') {
+ nodeType = 'start';
+ }
+ else if (nodeConfig.nodeId === 'end') {
+ nodeType = 'end';
+ }
+ else {
+ nodeType = nodeConfig.component.type;
+ }
+
+ // 解析位置信息
+ 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,
+ 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);
+ }
+
+ console.log('nodes, edges:', nodes, edges);
+
+ return { nodes, edges };
+};
\ No newline at end of file