feat(flow): 支持循环节点类型转换与注册

- 新增对 LOOP_START 和 LOOP_END 组件类型的识别
- 在节点转换过程中构建循环开始和结束节点结构
- 为循环节点设置默认参数和位置信息
- 动态注册 LOOP 类型节点到编辑器中
- 更新节点类型判断逻辑以支持循环组件
- 序列化循环节点关联信息至 customDef 字段- 优化节点数据构造逻辑,确保组件标识正确附加
master
钟良源 4 months ago
parent 24bc2f392d
commit ae70967f86

@ -1,5 +1,6 @@
import { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node';
import LocalNode from '@/components/FlowEditor/node/localNode/LocalNode';
import LoopNode from '@/components/FlowEditor/node/loopNode/LoopNode';
/**
* flow editor nodes edges
@ -65,6 +66,9 @@ export const convertFlowData = (flowData: any, useDefault = true) => {
else if (nodeConfig.nodeId === 'end') {
nodeType = 'end';
}
else if (nodeConfig.component.type === 'LOOP_START' || nodeConfig.component.type === 'LOOP_END') {
nodeType = 'LOOP';
}
else {
nodeType = nodeConfig.component.type;
}
@ -78,6 +82,67 @@ export const convertFlowData = (flowData: any, useDefault = true) => {
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: [],
apiOuts: [{ name: 'loopStart', 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, '循环');
}
}
// 构造节点数据
const node: any = {
id: nodeConfig.nodeId,
@ -111,11 +176,11 @@ export const convertFlowData = (flowData: any, useDefault = true) => {
defaultValue: output.defaultValue
})) || []
},
type: nodeType
type: nodeType === 'LOOP' ? nodeConfig.component.type : nodeType
}
};
// 如果是机械臂节点,添加组件标识信息
// 添加组件标识信息
if (nodeConfig.component) {
node.data.component = {
compIdentifier: nodeConfig.component.compIdentifier,

Loading…
Cancel
Save