feat(utils): 为 convertFlowData 添加 useDefault 参数以支持返回默认节点

master
钟良源 4 months ago
parent feae6798d6
commit ec2400aa60

@ -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 || [];

Loading…
Cancel
Save