1
This commit is contained in:
parent
4750b9e394
commit
c45dd19d58
@ -1022,7 +1022,6 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
const node = JSON.parse(nodeData);
|
const node = JSON.parse(nodeData);
|
||||||
const {clientX, clientY} = e;
|
const {clientX, clientY} = e;
|
||||||
const point = graph.clientToLocal({x: clientX, y: clientY});
|
const point = graph.clientToLocal({x: clientX, y: clientY});
|
||||||
console.log("dasdasd", graph, node, nodeDefinitions, point);
|
|
||||||
addNodeToGraph(true, graph, node, nodeDefinitions, point);
|
addNodeToGraph(true, graph, node, nodeDefinitions, point);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('创建节点失败:', error);
|
console.error('创建节点失败:', error);
|
||||||
|
|||||||
@ -5,49 +5,48 @@ import {convertPortConfig} from '../constants';
|
|||||||
* 添加节点到图形
|
* 添加节点到图形
|
||||||
* @param isNew 是否为新节点
|
* @param isNew 是否为新节点
|
||||||
* @param graph X6 Graph实例
|
* @param graph X6 Graph实例
|
||||||
* @param nodeDefinitions 工作流节点定义
|
* @param currentNodeDefinition 工作流节点定义
|
||||||
* @param workflowNodeDefinitionList 工作流节点定义列表
|
* @param allNodeDefinitions 工作流节点定义列表
|
||||||
* @param position 新节点的位置(可选)
|
* @param position 新节点的位置(可选)
|
||||||
* @returns 创建的节点实例
|
* @returns 创建的节点实例
|
||||||
*/
|
*/
|
||||||
export const addNodeToGraph = (
|
export const addNodeToGraph = (
|
||||||
isNew: boolean,
|
isNew: boolean,
|
||||||
graph: Graph,
|
graph: Graph,
|
||||||
nodeDefinitions: any,
|
currentNodeDefinition: any,
|
||||||
workflowNodeDefinitionList: any,
|
allNodeDefinitions: any,
|
||||||
position?: { x: number; y: number }
|
position?: { x: number; y: number }
|
||||||
) => {
|
) => {
|
||||||
let nodeDefinition = workflowNodeDefinitionList.find(def => def.nodeType === nodeDefinitions.nodeType);
|
let nodeDefinition = allNodeDefinitions.find(def => def.nodeType === currentNodeDefinition.nodeType);
|
||||||
let uiGraph = isNew ? nodeDefinition.uiVariables : nodeDefinitions.graph;
|
let uiVariables = isNew ? nodeDefinition.uiVariables : currentNodeDefinition.graph.uiVariables;
|
||||||
console.log(uiGraph)
|
|
||||||
// 根据形状类型设置正确的 shape
|
// 根据形状类型设置正确的 shape
|
||||||
let shape = 'rect'; // 默认使用矩形
|
let shape = 'rect'; // 默认使用矩形
|
||||||
if (uiGraph.shape === 'circle') {
|
if (uiVariables.shape === 'circle') {
|
||||||
shape = 'circle';
|
shape = 'circle';
|
||||||
} else if (uiGraph.shape === 'diamond') {
|
} else if (uiVariables.shape === 'diamond') {
|
||||||
shape = 'polygon';
|
shape = 'polygon';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建节点配置
|
// 创建节点配置
|
||||||
const nodeConfig = {
|
const nodeConfig = {
|
||||||
inherit: 'rect',
|
inherit: 'rect',
|
||||||
width: uiGraph.size.width,
|
width: uiVariables.size.width,
|
||||||
height: uiGraph.size.height,
|
height: uiVariables.size.height,
|
||||||
attrs: {
|
attrs: {
|
||||||
body: {
|
body: {
|
||||||
...uiGraph.style,
|
...uiVariables.style,
|
||||||
...(uiGraph.shape === 'diamond' ? {
|
...(uiVariables.shape === 'diamond' ? {
|
||||||
refPoints: '0,10 10,0 20,10 10,20',
|
refPoints: '0,10 10,0 20,10 10,20',
|
||||||
} : {})
|
} : {})
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
text: isNew ? nodeDefinition.nodeName : nodeDefinitions.name
|
text: isNew ? nodeDefinition.nodeName : currentNodeDefinition.name
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
shape,
|
shape,
|
||||||
type: isNew ? nodeDefinition.nodeType : nodeDefinitions.type,
|
type: isNew ? nodeDefinition.nodeType : currentNodeDefinition.type,
|
||||||
code: uiGraph.nodeCode,
|
code: nodeDefinition.nodeCode,
|
||||||
ports: convertPortConfig(uiGraph.ports),
|
ports: convertPortConfig(uiVariables.ports),
|
||||||
nodeDefinition: nodeDefinition
|
nodeDefinition: nodeDefinition
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,14 +54,14 @@ export const addNodeToGraph = (
|
|||||||
if (isNew && position) {
|
if (isNew && position) {
|
||||||
// 新节点:使用传入的position
|
// 新节点:使用传入的position
|
||||||
Object.assign(nodeConfig, { x: position.x, y: position.y });
|
Object.assign(nodeConfig, { x: position.x, y: position.y });
|
||||||
} else if (!isNew && nodeDefinitions.graph?.position) {
|
} else if (!isNew && currentNodeDefinition.graph?.position) {
|
||||||
// 已有节点:使用后端返回的position
|
// 已有节点:使用后端返回的position
|
||||||
Object.assign(nodeConfig, { position: nodeDefinitions.graph.position });
|
Object.assign(nodeConfig, { position: currentNodeDefinition.graph.position });
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置节点ID(如果有)
|
// 设置节点ID(如果有)
|
||||||
if (uiGraph.id) {
|
if (uiVariables.id) {
|
||||||
Object.assign(nodeConfig, { id: uiGraph.id });
|
Object.assign(nodeConfig, { id: uiVariables.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
return graph.addNode(nodeConfig);
|
return graph.addNode(nodeConfig);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user