|
|
|
|
@ -468,6 +468,121 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
|
return flowData;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将 React Flow 的 nodes 和 edges 数据结构反向转换为 convertFlowData 可以处理的格式
|
|
|
|
|
* @param nodes - React Flow 节点数组
|
|
|
|
|
* @param edges - React Flow 边数组
|
|
|
|
|
* @returns 可用于 convertFlowData 的数据结构
|
|
|
|
|
*/
|
|
|
|
|
export const reverseConvertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
|
// 初始化返回的数据结构
|
|
|
|
|
const flowData: any = {};
|
|
|
|
|
|
|
|
|
|
// 转换节点数据
|
|
|
|
|
if (nodes && nodes.length > 0) {
|
|
|
|
|
nodes.forEach(node => {
|
|
|
|
|
const nodeId = node.id;
|
|
|
|
|
|
|
|
|
|
// 构造节点配置对象
|
|
|
|
|
const nodeConfig: any = {
|
|
|
|
|
id: nodeId,
|
|
|
|
|
componentName: node.data?.title || nodeId,
|
|
|
|
|
position: node.position || { x: 0, y: 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 处理 component 信息
|
|
|
|
|
if (node.data?.component) {
|
|
|
|
|
nodeConfig.component = { ...node.data.component };
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nodeConfig.component = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理参数信息
|
|
|
|
|
const parameters = node.data?.parameters || {};
|
|
|
|
|
|
|
|
|
|
// 处理 apiIns(输入API)
|
|
|
|
|
if (parameters.apiIns && parameters.apiIns.length > 0) {
|
|
|
|
|
nodeConfig.apiIns = parameters.apiIns;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nodeConfig.apiIns = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理 apiOuts(输出API)
|
|
|
|
|
if (parameters.apiOuts && parameters.apiOuts.length > 0) {
|
|
|
|
|
nodeConfig.apiOuts = parameters.apiOuts;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nodeConfig.apiOuts = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理 dataIns(输入数据)
|
|
|
|
|
if (parameters.dataIns && parameters.dataIns.length > 0) {
|
|
|
|
|
nodeConfig.dataIns = parameters.dataIns;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nodeConfig.dataIns = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理 dataOuts(输出数据)
|
|
|
|
|
if (parameters.dataOuts && parameters.dataOuts.length > 0) {
|
|
|
|
|
nodeConfig.dataOuts = parameters.dataOuts;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nodeConfig.dataOuts = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化连接数组
|
|
|
|
|
nodeConfig.apiDownstream = [];
|
|
|
|
|
nodeConfig.apiUpstream = [];
|
|
|
|
|
nodeConfig.dataDownstream = [];
|
|
|
|
|
nodeConfig.dataUpstream = [];
|
|
|
|
|
|
|
|
|
|
// 将节点配置添加到 flowData 对象中
|
|
|
|
|
flowData[nodeId] = nodeConfig;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理连接关系
|
|
|
|
|
if (edges && edges.length > 0) {
|
|
|
|
|
// 分析边的连接关系
|
|
|
|
|
edges.forEach(edge => {
|
|
|
|
|
const sourceNode = edge.source;
|
|
|
|
|
const targetNode = edge.target;
|
|
|
|
|
const sourceHandle = edge.sourceHandle || 'done';
|
|
|
|
|
const targetHandle = edge.targetHandle || 'start';
|
|
|
|
|
|
|
|
|
|
// 确定连接类型(API 还是 DATA)
|
|
|
|
|
const sourceNodeData = nodes.find(n => n.id === sourceNode);
|
|
|
|
|
const targetNodeData = nodes.find(n => n.id === targetNode);
|
|
|
|
|
|
|
|
|
|
const isApiConnection =
|
|
|
|
|
(sourceNodeData?.data?.parameters?.apiOuts?.some((out: any) => out.name === sourceHandle)) ||
|
|
|
|
|
(targetNodeData?.data?.parameters?.apiIns?.some((inp: any) => inp.name === targetHandle)) ||
|
|
|
|
|
sourceHandle === 'start' || targetHandle === 'end' ||
|
|
|
|
|
sourceHandle === 'end' || targetHandle === 'start';
|
|
|
|
|
|
|
|
|
|
if (isApiConnection) {
|
|
|
|
|
// API 连接
|
|
|
|
|
// 添加下游连接
|
|
|
|
|
flowData[sourceNode].apiDownstream.push([`${targetNode}$$${targetHandle}`]);
|
|
|
|
|
|
|
|
|
|
// 添加上游连接
|
|
|
|
|
flowData[targetNode].apiUpstream.push([`${sourceNode}$$${sourceHandle}`]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// 数据连接
|
|
|
|
|
const dataConnection = [`${sourceNode}@@${sourceHandle}`, `${targetNode}@@${targetHandle}`];
|
|
|
|
|
flowData[sourceNode].dataDownstream.push(dataConnection);
|
|
|
|
|
flowData[targetNode].dataUpstream.push(dataConnection);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flowData;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 获取节点的API输入参数
|
|
|
|
|
const getNodeApiIns = (nodeId: string, nodeConfig: any, currentProjectCompData: any[]) => {
|
|
|
|
|
// 对于特定类型的节点使用预定义值
|
|
|
|
|
@ -562,6 +677,9 @@ const getNodeApiOuts = (nodeId: string, nodeConfig: any, currentProjectCompData:
|
|
|
|
|
else if (nodeId === 'start') {
|
|
|
|
|
return [{ name: 'start', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
|
}
|
|
|
|
|
else if (nodeId === 'end') {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const comp = currentProjectCompData.filter(item => item.id === nodeConfig?.component?.compId);
|
|
|
|
|
if (comp && comp.length > 0) {
|
|
|
|
|
|