|
|
|
|
@ -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 };
|
|
|
|
|
};
|