This commit is contained in:
KuroSago 2025-05-12 12:28:14 +08:00
parent 3b3a141951
commit c37b3cc5d4
2 changed files with 29 additions and 18 deletions

View File

@ -1,5 +1,3 @@
import { insertChildNode } from "./insertChildNode";
import { insertSiblingNode } from "./insertSiblingNode";
import { useMindMapStore } from "../index";
import type MindMapNode from "simple-mind-map/types/src/core/render/node/MindMapNode";
@ -18,6 +16,9 @@ const ICON_DELETE =
export function getCustomNodeContent(
params: {
allowRemoveWithChildren?: boolean;
del?: (node: MindMapNode) => void;
addChild?: (node: MindMapNode) => void;
edit?: (node: MindMapNode) => void;
} = {
allowRemoveWithChildren: false,
}
@ -25,7 +26,7 @@ export function getCustomNodeContent(
// 按钮配置
const buttonConfig = {
gap: 4, // 按钮间距
fontSize: 24, // 字体大小
fontSize: 16, // 字体大小
height: 24, // 按钮高度
width: 24, // 按钮宽度
};
@ -109,26 +110,15 @@ export function getCustomNodeContent(
// 根据按钮类型执行不同操作
switch (action) {
case "addChild":
insertChildNode({
beforeInsertCallback: async () => ({
uid: "",
text: "新子节点",
}),
parentNodeId: node.uid,
});
// 添加子节点
params.addChild?.(node);
break;
case "delete":
insertSiblingNode({
beforeInsertCallback: async () => ({
uid: "",
text: "新同级节点",
}),
nodeId: node.uid,
});
params.del?.(node);
break;
case "edit":
// 获取实例并编辑当前节点
params.edit?.(node);
break;
}
};

View File

@ -54,6 +54,15 @@ export const useMindMapStore = defineStore(
// 添加自定义节点内容
addCustomContentToNode: getCustomNodeContent({
allowRemoveWithChildren: false,
del : (node: MindMapNode) => {
console.log("删除节点", node);
},
addChild: (node: MindMapNode) => {
console.log("添加子节点", node);
},
edit: (node: MindMapNode) => {
console.log("编辑节点", node);
}
}),
demonstrateConfig: {
@ -75,6 +84,18 @@ export const useMindMapStore = defineStore(
currentLayout.value = layout;
});
// 当双击时
mindMapInstance?.on("node_dblclick", (node: MindMapNode) => {
console.log("双击节点", node);
return async () => false;
});
// node_click
mindMapInstance?.on("node_click", (node: MindMapNode) => {
console.log("点击节点", node);
return async () => false;
});
// 关闭键盘事件
removeKeyCommand(mindMapInstance);
}