1
This commit is contained in:
parent
4750b9e394
commit
c45dd19d58
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user