This commit is contained in:
dengqichen 2024-12-20 14:57:46 +08:00
parent 4750b9e394
commit c45dd19d58
2 changed files with 20 additions and 22 deletions

View File

@ -1022,7 +1022,6 @@ const WorkflowDesign: React.FC = () => {
const node = JSON.parse(nodeData);
const {clientX, clientY} = e;
const point = graph.clientToLocal({x: clientX, y: clientY});
console.log("dasdasd", graph, node, nodeDefinitions, point);
addNodeToGraph(true, graph, node, nodeDefinitions, point);
} catch (error) {
console.error('创建节点失败:', error);

View File

@ -5,49 +5,48 @@ import {convertPortConfig} from '../constants';
*
* @param isNew
* @param graph X6 Graph实例
* @param nodeDefinitions
* @param workflowNodeDefinitionList
* @param currentNodeDefinition
* @param allNodeDefinitions
* @param position
* @returns
*/
export const addNodeToGraph = (
isNew: boolean,
graph: Graph,
nodeDefinitions: any,
workflowNodeDefinitionList: any,
currentNodeDefinition: any,
allNodeDefinitions: any,
position?: { x: number; y: number }
) => {
let nodeDefinition = workflowNodeDefinitionList.find(def => def.nodeType === nodeDefinitions.nodeType);
let uiGraph = isNew ? nodeDefinition.uiVariables : nodeDefinitions.graph;
console.log(uiGraph)
let nodeDefinition = allNodeDefinitions.find(def => def.nodeType === currentNodeDefinition.nodeType);
let uiVariables = isNew ? nodeDefinition.uiVariables : currentNodeDefinition.graph.uiVariables;
// 根据形状类型设置正确的 shape
let shape = 'rect'; // 默认使用矩形
if (uiGraph.shape === 'circle') {
if (uiVariables.shape === 'circle') {
shape = 'circle';
} else if (uiGraph.shape === 'diamond') {
} else if (uiVariables.shape === 'diamond') {
shape = 'polygon';
}
// 创建节点配置
const nodeConfig = {
inherit: 'rect',
width: uiGraph.size.width,
height: uiGraph.size.height,
width: uiVariables.size.width,
height: uiVariables.size.height,
attrs: {
body: {
...uiGraph.style,
...(uiGraph.shape === 'diamond' ? {
...uiVariables.style,
...(uiVariables.shape === 'diamond' ? {
refPoints: '0,10 10,0 20,10 10,20',
} : {})
},
label: {
text: isNew ? nodeDefinition.nodeName : nodeDefinitions.name
text: isNew ? nodeDefinition.nodeName : currentNodeDefinition.name
},
},
shape,
type: isNew ? nodeDefinition.nodeType : nodeDefinitions.type,
code: uiGraph.nodeCode,
ports: convertPortConfig(uiGraph.ports),
type: isNew ? nodeDefinition.nodeType : currentNodeDefinition.type,
code: nodeDefinition.nodeCode,
ports: convertPortConfig(uiVariables.ports),
nodeDefinition: nodeDefinition
};
@ -55,14 +54,14 @@ export const addNodeToGraph = (
if (isNew && position) {
// 新节点使用传入的position
Object.assign(nodeConfig, { x: position.x, y: position.y });
} else if (!isNew && nodeDefinitions.graph?.position) {
} else if (!isNew && currentNodeDefinition.graph?.position) {
// 已有节点使用后端返回的position
Object.assign(nodeConfig, { position: nodeDefinitions.graph.position });
Object.assign(nodeConfig, { position: currentNodeDefinition.graph.position });
}
// 设置节点ID如果有
if (uiGraph.id) {
Object.assign(nodeConfig, { id: uiGraph.id });
if (uiVariables.id) {
Object.assign(nodeConfig, { id: uiVariables.id });
}
return graph.addNode(nodeConfig);