|
|
|
@ -1,6 +1,7 @@
|
|
|
|
import { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node';
|
|
|
|
import { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node';
|
|
|
|
import LocalNode from '@/components/FlowEditor/node/localNode/LocalNode';
|
|
|
|
import LocalNode from '@/components/FlowEditor/node/localNode/LocalNode';
|
|
|
|
import LoopNode from '@/components/FlowEditor/node/loopNode/LoopNode';
|
|
|
|
import LoopNode from '@/components/FlowEditor/node/loopNode/LoopNode';
|
|
|
|
|
|
|
|
import store from '@/store/index';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 将提供的数据结构转换为适用于 flow editor 的 nodes 和 edges
|
|
|
|
* 将提供的数据结构转换为适用于 flow editor 的 nodes 和 edges
|
|
|
|
@ -11,8 +12,9 @@ import LoopNode from '@/components/FlowEditor/node/loopNode/LoopNode';
|
|
|
|
export const convertFlowData = (flowData: any, useDefault = true) => {
|
|
|
|
export const convertFlowData = (flowData: any, useDefault = true) => {
|
|
|
|
const nodes: any[] = [];
|
|
|
|
const nodes: any[] = [];
|
|
|
|
const edges: any[] = [];
|
|
|
|
const edges: any[] = [];
|
|
|
|
|
|
|
|
const currentProjectCompData = getCurrentProjectStoreData();
|
|
|
|
|
|
|
|
|
|
|
|
if (!flowData || Object.keys(flowData).length === 0 || flowData.main.nodeConfigs.length === 0) {
|
|
|
|
if (!flowData || Object.keys(flowData).length === 0) {
|
|
|
|
// 如果useDefault为true且flowData为空,则返回默认的开始和结束节点
|
|
|
|
// 如果useDefault为true且flowData为空,则返回默认的开始和结束节点
|
|
|
|
if (useDefault) {
|
|
|
|
if (useDefault) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
@ -55,167 +57,157 @@ export const convertFlowData = (flowData: any, useDefault = true) => {
|
|
|
|
return { nodes, edges };
|
|
|
|
return { nodes, edges };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理节点配置
|
|
|
|
// 处理新格式的数据结构
|
|
|
|
const nodeConfigs = flowData.main?.nodeConfigs || [];
|
|
|
|
// 先处理所有节点
|
|
|
|
for (const nodeConfig of nodeConfigs) {
|
|
|
|
const nodeEntries = Object.entries(flowData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const entry of nodeEntries) {
|
|
|
|
|
|
|
|
const nodeId: string = entry[0];
|
|
|
|
|
|
|
|
const nodeConfig: any = entry[1];
|
|
|
|
|
|
|
|
|
|
|
|
// 确定节点类型
|
|
|
|
// 确定节点类型
|
|
|
|
let nodeType = 'BASIC';
|
|
|
|
let nodeType = 'BASIC';
|
|
|
|
if (nodeConfig.nodeId === 'start') {
|
|
|
|
if (nodeId === 'start') {
|
|
|
|
nodeType = 'start';
|
|
|
|
nodeType = 'start';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nodeConfig.nodeId === 'end') {
|
|
|
|
else if (nodeId === 'end') {
|
|
|
|
nodeType = 'end';
|
|
|
|
nodeType = 'end';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nodeConfig.component.type === 'LOOP_START' || nodeConfig.component.type === 'LOOP_END') {
|
|
|
|
else if (nodeConfig.component?.type === 'LOOP_START' || nodeConfig.component?.type === 'LOOP_END') {
|
|
|
|
nodeType = 'LOOP';
|
|
|
|
nodeType = 'LOOP';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
nodeType = nodeConfig.component.type;
|
|
|
|
nodeType = nodeConfig.component?.type || 'BASIC';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析位置信息
|
|
|
|
// 解析位置信息
|
|
|
|
let position = { x: 0, y: 0 };
|
|
|
|
const position = nodeConfig.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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建循环节点的默认参数和外壳
|
|
|
|
|
|
|
|
if (nodeType === 'LOOP') {
|
|
|
|
|
|
|
|
// 创建循环开始节点
|
|
|
|
|
|
|
|
const loopStartNode = {
|
|
|
|
|
|
|
|
id: `LOOP_START-${Date.now()}`,
|
|
|
|
|
|
|
|
type: 'LOOP', // 使用本地节点类型
|
|
|
|
|
|
|
|
position: { x: position.x, y: position.y },
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
title: '循环开始',
|
|
|
|
|
|
|
|
type: 'LOOP_START',
|
|
|
|
|
|
|
|
parameters: {
|
|
|
|
|
|
|
|
apiIns: [{ name: 'start', desc: '', dataType: '', defaultValue: '' }],
|
|
|
|
|
|
|
|
apiOuts: [{ name: 'done', desc: '', dataType: '', defaultValue: '' }],
|
|
|
|
|
|
|
|
dataIns: [],
|
|
|
|
|
|
|
|
dataOuts: []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
component: {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建循环结束节点
|
|
|
|
|
|
|
|
const loopEndNode = {
|
|
|
|
|
|
|
|
id: `LOOP_END-${Date.now()}`,
|
|
|
|
|
|
|
|
type: 'LOOP', // 使用本地节点类型
|
|
|
|
|
|
|
|
position: { x: position.x + 400, y: position.y },
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
title: '循环结束',
|
|
|
|
|
|
|
|
type: 'LOOP_END',
|
|
|
|
|
|
|
|
parameters: {
|
|
|
|
|
|
|
|
apiIns: [{ name: 'continue', desc: '', dataType: '', defaultValue: '' }],
|
|
|
|
|
|
|
|
apiOuts: [{ name: 'break', desc: '', dataType: '', defaultValue: '' }],
|
|
|
|
|
|
|
|
dataIns: [{
|
|
|
|
|
|
|
|
'arrayType': null,
|
|
|
|
|
|
|
|
'dataType': 'INTEGER',
|
|
|
|
|
|
|
|
'defaultValue': 10,
|
|
|
|
|
|
|
|
'desc': '最大循环次数',
|
|
|
|
|
|
|
|
'id': 'maxTime'
|
|
|
|
|
|
|
|
}],
|
|
|
|
|
|
|
|
dataOuts: []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
component: {
|
|
|
|
|
|
|
|
type: 'LOOP_END',
|
|
|
|
|
|
|
|
customDef: '',
|
|
|
|
|
|
|
|
loopStartNodeId: loopStartNode.id // 这里的参数是为了提供在组件内部处理数据是使用,最后这个字段要序列化后放进customDef
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loopStartNode.data.component = {
|
|
|
|
|
|
|
|
type: 'LOOP_START',
|
|
|
|
|
|
|
|
customDef: JSON.stringify({ loopEndNodeId: loopEndNode.id })
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将未定义的节点动态追加进nodeTypes
|
|
|
|
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
|
|
|
|
if (!nodeMap.includes('LOOP')) {
|
|
|
|
|
|
|
|
registerNodeType('LOOP', LoopNode, '循环');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('nodeConfig:', nodeConfig);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构造节点数据
|
|
|
|
// 构造节点数据
|
|
|
|
const node: any = {
|
|
|
|
const node: any = {
|
|
|
|
id: nodeConfig.nodeId,
|
|
|
|
id: nodeId,
|
|
|
|
type: nodeType,
|
|
|
|
type: nodeType,
|
|
|
|
position,
|
|
|
|
position,
|
|
|
|
data: {
|
|
|
|
data: {
|
|
|
|
title: nodeConfig.nodeName || nodeConfig.nodeId,
|
|
|
|
title: nodeConfig.componentName || nodeId,
|
|
|
|
parameters: {
|
|
|
|
parameters: {
|
|
|
|
apiIns: [{
|
|
|
|
apiIns: getNodeApiIns(nodeId, nodeConfig, currentProjectCompData),
|
|
|
|
name: buildNodeId(nodeConfig.nodeId,'in'),
|
|
|
|
apiOuts: getNodeApiOuts(nodeId, nodeConfig, currentProjectCompData),
|
|
|
|
id: buildNodeId(nodeConfig.nodeId,'in'),
|
|
|
|
dataIns: nodeConfig.dataIns || [],
|
|
|
|
desc: '',
|
|
|
|
dataOuts: nodeConfig.dataOuts || []
|
|
|
|
dataType: '',
|
|
|
|
|
|
|
|
defaultValue: ''
|
|
|
|
|
|
|
|
}],
|
|
|
|
|
|
|
|
apiOuts: [{
|
|
|
|
|
|
|
|
name: buildNodeId(nodeConfig.nodeId,'out'),
|
|
|
|
|
|
|
|
id: buildNodeId(nodeConfig.nodeId,'out'),
|
|
|
|
|
|
|
|
desc: '',
|
|
|
|
|
|
|
|
dataType: '',
|
|
|
|
|
|
|
|
defaultValue: ''
|
|
|
|
|
|
|
|
}],
|
|
|
|
|
|
|
|
dataIns: nodeConfig.dataIns?.map((input: any) => ({
|
|
|
|
|
|
|
|
name: input.id,
|
|
|
|
|
|
|
|
id: input.id,
|
|
|
|
|
|
|
|
desc: input.desc,
|
|
|
|
|
|
|
|
dataType: input.dataType,
|
|
|
|
|
|
|
|
defaultValue: input.defaultValue
|
|
|
|
|
|
|
|
})) || [],
|
|
|
|
|
|
|
|
dataOuts: nodeConfig.dataOuts?.map((output: any) => ({
|
|
|
|
|
|
|
|
name: output.id,
|
|
|
|
|
|
|
|
id: output.id,
|
|
|
|
|
|
|
|
desc: output.desc,
|
|
|
|
|
|
|
|
dataType: output.dataType,
|
|
|
|
|
|
|
|
defaultValue: output.defaultValue
|
|
|
|
|
|
|
|
})) || []
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
type: nodeType === 'LOOP' ? nodeConfig.component.type : nodeType
|
|
|
|
type: nodeConfig.component?.type || nodeType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 添加组件标识信息
|
|
|
|
// 添加组件标识信息
|
|
|
|
if (nodeConfig.component) {
|
|
|
|
if (nodeConfig.component) {
|
|
|
|
node.data.component = {
|
|
|
|
node.data.component = { ...nodeConfig.component };
|
|
|
|
compIdentifier: nodeConfig.component.compIdentifier,
|
|
|
|
node.data.compId = nodeConfig.component.compId;
|
|
|
|
compInstanceIdentifier: nodeConfig.component.compInstanceIdentifier,
|
|
|
|
|
|
|
|
customDef: nodeConfig.component?.customDef,
|
|
|
|
|
|
|
|
type: nodeConfig.component.type
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将未定义的节点动态追加进nodeTypes
|
|
|
|
// 注册循环节点类型
|
|
|
|
|
|
|
|
if (nodeType === 'LOOP') {
|
|
|
|
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
|
|
|
|
if (!nodeMap.includes('LOOP')) {
|
|
|
|
|
|
|
|
registerNodeType('LOOP', LoopNode, '循环');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 注册其他节点类型
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
// 目前默认添加的都是系统组件/本地组件
|
|
|
|
if (!nodeMap.includes(nodeType) && nodeType !== 'start' && nodeType !== 'end' && nodeType !== 'LOOP') {
|
|
|
|
if (!nodeMap.includes(nodeType)) registerNodeType(nodeType, LocalNode, nodeConfig.nodeName);
|
|
|
|
registerNodeType(nodeType, LocalNode, nodeConfig.componentName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nodes.push(node);
|
|
|
|
nodes.push(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理连线配置
|
|
|
|
// 用于存储已添加的边,避免重复
|
|
|
|
const lineConfigs = flowData.main?.lineConfigs || [];
|
|
|
|
const addedEdges = new Set<string>();
|
|
|
|
for (const lineConfig of lineConfigs) {
|
|
|
|
|
|
|
|
const edge: any = {
|
|
|
|
// 处理连接关系 - 只处理下游连接,避免重复创建连接线
|
|
|
|
id: lineConfig.id,
|
|
|
|
for (const entry of nodeEntries) {
|
|
|
|
source: lineConfig.prev.nodeId,
|
|
|
|
const nodeId: string = entry[0];
|
|
|
|
target: lineConfig.next.nodeId,
|
|
|
|
const nodeConfig: any = entry[1];
|
|
|
|
sourceHandle: lineConfig.prev.endpointId,
|
|
|
|
|
|
|
|
targetHandle: lineConfig.next.endpointId
|
|
|
|
// 处理 API 下游连接
|
|
|
|
};
|
|
|
|
if (nodeConfig.apiDownstream && Array.isArray(nodeConfig.apiDownstream)) {
|
|
|
|
|
|
|
|
nodeConfig.apiDownstream.forEach((targetArray: string[]) => {
|
|
|
|
|
|
|
|
// 确保 targetArray 是数组并且包含字符串元素
|
|
|
|
|
|
|
|
if (Array.isArray(targetArray)) {
|
|
|
|
|
|
|
|
targetArray.forEach(target => {
|
|
|
|
|
|
|
|
if (typeof target === 'string' && target.includes('$$')) {
|
|
|
|
|
|
|
|
const [targetNodeId, targetHandle] = target.split('$$');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 动态获取源句柄,而不是使用默认值
|
|
|
|
|
|
|
|
const sourceNode = flowData[nodeId];
|
|
|
|
|
|
|
|
// 统一旧版本逻辑,开始节点的输出句柄是start
|
|
|
|
|
|
|
|
let sourceHandle = sourceNode.id === 'start' ? 'start' : 'done'; // 默认值
|
|
|
|
|
|
|
|
if (sourceNode && sourceNode.component && sourceNode.component.type) {
|
|
|
|
|
|
|
|
// 根据节点类型获取正确的源句柄
|
|
|
|
|
|
|
|
sourceHandle = getNodeApiOutHandle(nodeId, sourceNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (sourceNode && sourceNode.data && sourceNode.data.parameters &&
|
|
|
|
|
|
|
|
sourceNode.data.parameters.apiOuts && sourceNode.data.parameters.apiOuts.length > 0) {
|
|
|
|
|
|
|
|
// 从apiOuts中获取第一个句柄
|
|
|
|
|
|
|
|
sourceHandle = sourceNode.data.parameters.apiOuts[0].name ||
|
|
|
|
|
|
|
|
sourceNode.data.parameters.apiOuts[0].id || sourceHandle;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建边的唯一标识符
|
|
|
|
|
|
|
|
const edgeId = `${nodeId}-${targetNodeId}-${sourceHandle}-${targetHandle}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已添加此边
|
|
|
|
|
|
|
|
if (!addedEdges.has(edgeId)) {
|
|
|
|
|
|
|
|
addedEdges.add(edgeId);
|
|
|
|
|
|
|
|
edges.push({
|
|
|
|
|
|
|
|
id: `${edgeId}`,
|
|
|
|
|
|
|
|
source: nodeId,
|
|
|
|
|
|
|
|
target: targetNodeId,
|
|
|
|
|
|
|
|
sourceHandle,
|
|
|
|
|
|
|
|
targetHandle
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
edges.push(edge);
|
|
|
|
// 处理数据下游连接
|
|
|
|
|
|
|
|
if (nodeConfig.dataDownstream && Array.isArray(nodeConfig.dataDownstream)) {
|
|
|
|
|
|
|
|
nodeConfig.dataDownstream.forEach((connectionGroup: string[]) => {
|
|
|
|
|
|
|
|
// 确保 connectionGroup 是数组并且至少包含两个元素
|
|
|
|
|
|
|
|
if (Array.isArray(connectionGroup) && connectionGroup.length >= 2) {
|
|
|
|
|
|
|
|
// 第一个元素是源节点和句柄信息
|
|
|
|
|
|
|
|
const [sourceInfo, targetInfo] = connectionGroup;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof sourceInfo === 'string' && sourceInfo.includes('@@') &&
|
|
|
|
|
|
|
|
typeof targetInfo === 'string' && targetInfo.includes('@@')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [sourceNodeId, sourceHandle] = sourceInfo.split('@@');
|
|
|
|
|
|
|
|
const [targetNodeId, targetHandle] = targetInfo.split('@@');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建边的唯一标识符
|
|
|
|
|
|
|
|
const edgeId = `${sourceNodeId}-${targetNodeId}-${sourceHandle}-${targetHandle}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已添加此边
|
|
|
|
|
|
|
|
if (!addedEdges.has(edgeId)) {
|
|
|
|
|
|
|
|
addedEdges.add(edgeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
edges.push({
|
|
|
|
|
|
|
|
id: `${edgeId}`,
|
|
|
|
|
|
|
|
source: sourceNodeId,
|
|
|
|
|
|
|
|
target: targetNodeId,
|
|
|
|
|
|
|
|
sourceHandle: sourceHandle,
|
|
|
|
|
|
|
|
targetHandle: targetHandle
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { nodes, edges };
|
|
|
|
return { nodes, edges };
|
|
|
|
@ -269,7 +261,8 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
nodeConfig.component = {
|
|
|
|
nodeConfig.component = {
|
|
|
|
type: nodeType,
|
|
|
|
type: nodeType,
|
|
|
|
compIdentifier: node.data.component.compIdentifier || '',
|
|
|
|
compIdentifier: node.data.component.compIdentifier || '',
|
|
|
|
compInstanceIdentifier: node.data.component.compInstanceIdentifier || ''
|
|
|
|
compInstanceIdentifier: node.data.component.compInstanceIdentifier || '',
|
|
|
|
|
|
|
|
compId: node.data.compId || ''
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (node.data.component?.customDef) nodeConfig.component.customDef = node.data.component.customDef;
|
|
|
|
if (node.data.component?.customDef) nodeConfig.component.customDef = node.data.component.customDef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -279,6 +272,7 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
type: nodeType
|
|
|
|
type: nodeType
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (['BASIC'].includes(nodeType)) nodeConfig.component.compId = node.data.compId || '';
|
|
|
|
|
|
|
|
|
|
|
|
// 处理参数信息
|
|
|
|
// 处理参数信息
|
|
|
|
const parameters = node.data?.parameters || {};
|
|
|
|
const parameters = node.data?.parameters || {};
|
|
|
|
@ -297,7 +291,7 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
// 处理 dataOuts(输出数据)
|
|
|
|
// 处理 dataOuts(输出数据)
|
|
|
|
if (parameters.dataOuts && parameters.dataOuts.length > 0) {
|
|
|
|
if (parameters.dataOuts && parameters.dataOuts.length > 0) {
|
|
|
|
nodeConfig.dataOuts = parameters.dataOuts.map((output: any) => ({
|
|
|
|
nodeConfig.dataOuts = parameters.dataOuts.map((output: any) => ({
|
|
|
|
id: output.name,
|
|
|
|
id: output.name || output.id,
|
|
|
|
desc: output.desc,
|
|
|
|
desc: output.desc,
|
|
|
|
dataType: output.dataType,
|
|
|
|
dataType: output.dataType,
|
|
|
|
defaultValue: output.defaultValue,
|
|
|
|
defaultValue: output.defaultValue,
|
|
|
|
@ -309,7 +303,7 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 转换连线数据
|
|
|
|
// 转换连线数据
|
|
|
|
if (edges && edges.length > 0) {
|
|
|
|
if (edges && edges.length > 0) {
|
|
|
|
flowData.lineConfigs = edges.map((edge, index) => {
|
|
|
|
flowData.lineConfigs = edges.map((edge, index) => {
|
|
|
|
// 查找源节点和目标节点以确定连线类型
|
|
|
|
// 查找源节点和目标节点以确定连线类型
|
|
|
|
@ -324,11 +318,11 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 判断是否为API类型的连线
|
|
|
|
// 判断是否为API类型的连线
|
|
|
|
else if (edge.sourceHandle && (edge.sourceHandle === 'apiOuts' ||
|
|
|
|
else if (edge.sourceHandle && (edge.sourceHandle === 'apiOuts' ||
|
|
|
|
sourceNode?.data?.parameters?.apiOuts?.some((out: any) => out.name === edge.sourceHandle))) {
|
|
|
|
sourceNode?.data?.parameters?.apiOuts?.some((out: any) => (out.name || out.id) === edge.sourceHandle))) {
|
|
|
|
lineType = 'API';
|
|
|
|
lineType = 'API';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (edge.targetHandle && (edge.targetHandle === 'apiIns' ||
|
|
|
|
else if (edge.targetHandle && (edge.targetHandle === 'apiIns' ||
|
|
|
|
targetNode?.data?.parameters?.apiIns?.some((inp: any) => inp.name === edge.targetHandle))) {
|
|
|
|
targetNode?.data?.parameters?.apiIns?.some((inp: any) => (inp.name || inp.id) === edge.targetHandle))) {
|
|
|
|
lineType = 'API';
|
|
|
|
lineType = 'API';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -350,19 +344,139 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
|
|
|
|
return flowData;
|
|
|
|
return flowData;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取节点的API输入参数
|
|
|
|
|
|
|
|
const getNodeApiIns = (nodeId: string, nodeConfig: any, currentProjectCompData: any[]) => {
|
|
|
|
|
|
|
|
// 对于特定类型的节点使用预定义值
|
|
|
|
|
|
|
|
if (nodeConfig.component?.type === 'LOOP_START') {
|
|
|
|
|
|
|
|
return [{ name: 'start', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeConfig.component?.type === 'LOOP_END') {
|
|
|
|
|
|
|
|
return [{ name: 'continue', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeId === 'end') {
|
|
|
|
|
|
|
|
return [{ name: 'end', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
const comp = currentProjectCompData.filter(item => item.id === nodeConfig?.component?.compId);
|
|
|
|
|
|
|
|
if (comp && comp.length > 0) {
|
|
|
|
|
|
|
|
return comp[0].def.apis.map(v => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...v,
|
|
|
|
|
|
|
|
name: v.id,
|
|
|
|
|
|
|
|
desc: v.desc,
|
|
|
|
|
|
|
|
dataType: v?.dataType || '',
|
|
|
|
|
|
|
|
defaultValue: v?.defaultValue || ''
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return [{ name: 'start', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 通过nodeType先区分是否需要使用特殊nodeId,不需要就正常分类开始结束的句柄id
|
|
|
|
// 获取节点的API输出参数
|
|
|
|
const buildNodeId = (nodeId, type) => {
|
|
|
|
const getNodeApiOuts = (nodeId: string, nodeConfig: any, currentProjectCompData: any[]) => {
|
|
|
|
if (nodeId.includes('LOOP_START')) {
|
|
|
|
// 对于特定类型的节点使用预定义值
|
|
|
|
if (type === 'in') return 'start';
|
|
|
|
if (nodeConfig.component?.type === 'LOOP_START') {
|
|
|
|
else return 'done';
|
|
|
|
return [{ name: 'done', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nodeId.includes('LOOP_END')) {
|
|
|
|
else if (nodeConfig.component?.type === 'LOOP_END') {
|
|
|
|
if (type === 'in') return 'continue';
|
|
|
|
return [{ name: 'break', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
else return 'break';
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeId === 'start') {
|
|
|
|
|
|
|
|
return [{ name: 'start', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
if (type === 'in') return 'start';
|
|
|
|
const comp = currentProjectCompData.filter(item => item.id === nodeConfig?.component?.compId);
|
|
|
|
else return nodeId === 'end' ? 'end' : 'done';
|
|
|
|
if (comp && comp.length > 0) {
|
|
|
|
|
|
|
|
return [{
|
|
|
|
|
|
|
|
...comp[0].def.apiOut,
|
|
|
|
|
|
|
|
dataType: '',
|
|
|
|
|
|
|
|
defaultValue: ''
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return [{ name: 'done', desc: '', dataType: '', defaultValue: '' }];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取节点的API输出句柄名称
|
|
|
|
|
|
|
|
const getNodeApiOutHandle = (nodeId: string, nodeConfig: any) => {
|
|
|
|
|
|
|
|
if (nodeConfig.component?.type === 'LOOP_START') {
|
|
|
|
|
|
|
|
return 'done';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeConfig.component?.type === 'LOOP_END') {
|
|
|
|
|
|
|
|
return 'break';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeId === 'start') {
|
|
|
|
|
|
|
|
return 'start';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeId === 'end') {
|
|
|
|
|
|
|
|
return 'end';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'done';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前工程下组件列表并扁平化处理
|
|
|
|
|
|
|
|
const getCurrentProjectStoreData = () => {
|
|
|
|
|
|
|
|
const { info, projectComponentData } = store.getState().ideContainer;
|
|
|
|
|
|
|
|
const compData = projectComponentData[info?.id] || {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result: any[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理projectCompDto中的数据
|
|
|
|
|
|
|
|
if (compData.projectCompDto) {
|
|
|
|
|
|
|
|
const { mineComp = [], pubComp = [], teamWorkComp = [] } = compData.projectCompDto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加mineComp数据
|
|
|
|
|
|
|
|
mineComp.forEach((item: any) => {
|
|
|
|
|
|
|
|
result.push({
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
type: 'mineComp'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加pubComp数据
|
|
|
|
|
|
|
|
pubComp.forEach((item: any) => {
|
|
|
|
|
|
|
|
result.push({
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
type: 'pubComp'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加teamWorkComp数据
|
|
|
|
|
|
|
|
teamWorkComp.forEach((item: any) => {
|
|
|
|
|
|
|
|
result.push({
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
type: 'teamWorkComp'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理projectFlowDto中的数据
|
|
|
|
|
|
|
|
if (compData.projectFlowDto) {
|
|
|
|
|
|
|
|
const { mineFlow = [], pubFlow = [] } = compData.projectFlowDto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加mineFlow数据
|
|
|
|
|
|
|
|
mineFlow.forEach((item: any) => {
|
|
|
|
|
|
|
|
result.push({
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
type: 'mineFlow'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加pubFlow数据
|
|
|
|
|
|
|
|
pubFlow.forEach((item: any) => {
|
|
|
|
|
|
|
|
result.push({
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
type: 'pubFlow'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|