|
|
|
|
@ -4,13 +4,55 @@ import LocalNode from '@/components/FlowEditor/node/localNode/LocalNode';
|
|
|
|
|
/**
|
|
|
|
|
* 将提供的数据结构转换为适用于 flow editor 的 nodes 和 edges
|
|
|
|
|
* @param flowData - 原始数据结构
|
|
|
|
|
* @param useDefault - 当flowData为空时是否返回默认的开始和结束节点
|
|
|
|
|
* @returns 包含 nodes 和 edges 的对象
|
|
|
|
|
*/
|
|
|
|
|
export const convertFlowData = (flowData: any) => {
|
|
|
|
|
export const convertFlowData = (flowData: any, useDefault = true) => {
|
|
|
|
|
const nodes: any[] = [];
|
|
|
|
|
const edges: any[] = [];
|
|
|
|
|
|
|
|
|
|
if (!flowData || Object.keys(flowData).length === 0) return { nodes, edges };
|
|
|
|
|
if (!flowData || Object.keys(flowData).length === 0) {
|
|
|
|
|
// 如果useDefault为true且flowData为空,则返回默认的开始和结束节点
|
|
|
|
|
if (useDefault) {
|
|
|
|
|
return {
|
|
|
|
|
nodes: [
|
|
|
|
|
{
|
|
|
|
|
id: 'start',
|
|
|
|
|
type: 'start',
|
|
|
|
|
position: { x: 200, y: 200 },
|
|
|
|
|
data: {
|
|
|
|
|
title: '开始',
|
|
|
|
|
parameters: {
|
|
|
|
|
apiIns: [],
|
|
|
|
|
apiOuts: [{ name: 'start', desc: '', dataType: '', defaultValue: '' }],
|
|
|
|
|
dataIns: [],
|
|
|
|
|
dataOuts: []
|
|
|
|
|
},
|
|
|
|
|
type: 'start'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'end',
|
|
|
|
|
type: 'end',
|
|
|
|
|
position: { x: 1200, y: 200 },
|
|
|
|
|
data: {
|
|
|
|
|
title: '结束',
|
|
|
|
|
parameters: {
|
|
|
|
|
apiIns: [{ name: 'end', desc: '', dataType: '', defaultValue: '' }],
|
|
|
|
|
apiOuts: [],
|
|
|
|
|
dataIns: [],
|
|
|
|
|
dataOuts: []
|
|
|
|
|
},
|
|
|
|
|
type: 'end'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
edges: []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// 否则返回空数组
|
|
|
|
|
return { nodes, edges };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理节点配置
|
|
|
|
|
const nodeConfigs = flowData.main?.nodeConfigs || [];
|
|
|
|
|
|