图层实现

This commit is contained in:
2025-12-25 18:29:41 +08:00
parent 1abd97ff1f
commit 2578bf41c8

View File

@@ -64,87 +64,77 @@ onMounted(() => {
// container: document.querySelector('#container'), // container: document.querySelector('#container'),
grid: true, grid: true,
allowResize: true, allowResize: true,
allowRotate : true, allowRotate: true,
plugins: [Menu], plugins: [Menu],
overlapMode:-1
}); });
lf.value.addMenuConfig({
const lfInstance = lf.value;
if (!lfInstance) return;
lfInstance.extension.menu.addMenuConfig({
nodeMenu: [ nodeMenu: [
{ {
text: '分享', text: '置于顶层',
callback() { callback(node: NodeData) {
alert('分享成功!') console.log(lfInstance.getNodeModelById(node.id).zIndex)
}, lfInstance.setElementZIndex(node.id, 'top');
}
}, },
{ {
text: '属性', text: '置于底层',
callback(node: NodeData) { callback(node: NodeData) {
alert(` console.log(lfInstance.getNodeModelById(node.id).zIndex)
节点id${node.id} lfInstance.setElementZIndex(node.id, 'bottom');
节点类型:${node.type} }
节点坐标:(x: ${node.x}, y: ${node.y})
`)
},
}, },
{
text: '删除节点',
callback(node: NodeData) {
lfInstance.deleteNode(node.id);
}
}
], ],
edgeMenu: [ edgeMenu: [
{ {
text: '属性', text: '删除边',
callback(edge: EdgeData) { callback(edge: EdgeData) {
const { lfInstance.deleteEdge(edge.id);
id, }
type, }
startPoint,
endPoint,
sourceNodeId,
targetNodeId,
} = edge
alert(`
边id${id}
边类型:${type}
边起点坐标:(startPoint: [${startPoint.x}, ${startPoint.y}])
边终点坐标:(endPoint: [${endPoint.x}, ${endPoint.y}])
源节点id${sourceNodeId}
目标节点id${targetNodeId}
`)
},
},
], ],
graphMenu: [ graphMenu: [
{
text: '分享',
callback() {
alert('分享成功!')
},
},
{ {
text: '添加节点', text: '添加节点',
callback(data: Position) { callback(data: Position) {
lf.addNode({ lfInstance.addNode({
type: 'rect', type: 'rect',
x: data.x, x: data.x,
y: data.y, y: data.y
}) });
}, }
}, }
], ]
}); });
registerNodes(lf.value);
setLogicFlowInstance(lf.value); registerNodes(lfInstance);
lf.value.render({ setLogicFlowInstance(lfInstance);
lfInstance.render({
// 渲染的数据 // 渲染的数据
}) });
// 监听节点点击事件,更新 selectedNode // 监听节点点击事件,更新 selectedNode
lf.value.on(EventType.NODE_CLICK, ({ data }) => { lfInstance.on(EventType.NODE_CLICK, ({ data }) => {
selectedNode.value = data; selectedNode.value = data;
}); });
// 监听空白点击事件,取消选中 // 监听空白点击事件,取消选中
lf.value.on(EventType.BLANK_CLICK, () => { lfInstance.on(EventType.BLANK_CLICK, () => {
selectedNode.value = null; selectedNode.value = null;
}); });
// 节点属性改变,如果当前节点是选中节点,则同步更新 selectedNode // 节点属性改变,如果当前节点是选中节点,则同步更新 selectedNode
lf.value.on(EventType.NODE_PROPERTIES_CHANGE, (data) => { lfInstance.on(EventType.NODE_PROPERTIES_CHANGE, (data) => {
const nodeId = data.id; const nodeId = data.id;
if (selectedNode.value && nodeId === selectedNode.value.id) { if (selectedNode.value && nodeId === selectedNode.value.id) {
if (data.properties) { if (data.properties) {
@@ -155,7 +145,6 @@ onMounted(() => {
} }
} }
}); });
}); });
// 销毁 LogicFlow // 销毁 LogicFlow