diff --git a/web3/packages/mind-map/src/store/helpers/addCustomContentToNode.ts b/web3/packages/mind-map/src/store/helpers/addCustomContentToNode.ts index 1104d68a..b726063b 100644 --- a/web3/packages/mind-map/src/store/helpers/addCustomContentToNode.ts +++ b/web3/packages/mind-map/src/store/helpers/addCustomContentToNode.ts @@ -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; } }; diff --git a/web3/packages/mind-map/src/store/modules/mindMap.ts b/web3/packages/mind-map/src/store/modules/mindMap.ts index edbe74cf..00634526 100644 --- a/web3/packages/mind-map/src/store/modules/mindMap.ts +++ b/web3/packages/mind-map/src/store/modules/mindMap.ts @@ -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); }