This commit is contained in:
asp_ly 2024-12-14 16:32:55 +08:00
parent 3038debaef
commit b98c801b9f

View File

@ -953,14 +953,32 @@ const WorkflowDesign: React.FC = () => {
const sourceNode = nodeMap.get(edge.from); const sourceNode = nodeMap.get(edge.from);
const targetNode = nodeMap.get(edge.to); const targetNode = nodeMap.get(edge.to);
if (sourceNode && targetNode) { if (sourceNode && targetNode) {
// 根据节点类型获取正确的端口组
const getPortByGroup = (node: any, group: string) => {
const ports = node.getPorts();
const port = ports.find((p: any) => p.group === group);
return port?.id;
};
// 获取源节点的输出端口一定是out组
const sourcePort = getPortByGroup(sourceNode, 'out');
// 获取目标节点的输入端口一定是in组
const targetPort = getPortByGroup(targetNode, 'in');
if (!sourcePort || !targetPort) {
console.error('无法找到正确的端口:', edge);
return;
}
graphInstance.addEdge({ graphInstance.addEdge({
source: { source: {
cell: sourceNode.id, cell: sourceNode.id,
port: edge.fromPort || sourceNode.getPorts()[0].id, // 使用指定的端口或默认第一个端口 port: sourcePort,
}, },
target: { target: {
cell: targetNode.id, cell: targetNode.id,
port: edge.toPort || targetNode.getPorts()[0].id, // 使用指定的端口或默认第一个端口 port: targetPort,
}, },
attrs: { attrs: {
line: { line: {
@ -972,42 +990,6 @@ const WorkflowDesign: React.FC = () => {
}, },
}, },
}, },
tools: [
{
name: 'source-arrowhead',
args: {
attrs: {
fill: '#fff',
stroke: '#5F95FF',
strokeWidth: 1,
d: 'M 0 -6 L -8 0 L 0 6 Z',
},
},
},
{
name: 'target-arrowhead',
args: {
attrs: {
fill: '#fff',
stroke: '#5F95FF',
strokeWidth: 1,
d: 'M 0 -6 L 8 0 L 0 6 Z',
},
},
},
],
connector: {
name: 'rounded',
args: {
radius: 8
}
},
router: {
name: 'manhattan',
args: {
padding: 1
}
},
labels: [{ labels: [{
attrs: {label: {text: edge.name || ''}} attrs: {label: {text: edge.name || ''}}
}] }]