callback
This commit is contained in:
parent
3b3a141951
commit
c37b3cc5d4
@ -1,5 +1,3 @@
|
|||||||
import { insertChildNode } from "./insertChildNode";
|
|
||||||
import { insertSiblingNode } from "./insertSiblingNode";
|
|
||||||
import { useMindMapStore } from "../index";
|
import { useMindMapStore } from "../index";
|
||||||
import type MindMapNode from "simple-mind-map/types/src/core/render/node/MindMapNode";
|
import type MindMapNode from "simple-mind-map/types/src/core/render/node/MindMapNode";
|
||||||
|
|
||||||
@ -18,6 +16,9 @@ const ICON_DELETE =
|
|||||||
export function getCustomNodeContent(
|
export function getCustomNodeContent(
|
||||||
params: {
|
params: {
|
||||||
allowRemoveWithChildren?: boolean;
|
allowRemoveWithChildren?: boolean;
|
||||||
|
del?: (node: MindMapNode) => void;
|
||||||
|
addChild?: (node: MindMapNode) => void;
|
||||||
|
edit?: (node: MindMapNode) => void;
|
||||||
} = {
|
} = {
|
||||||
allowRemoveWithChildren: false,
|
allowRemoveWithChildren: false,
|
||||||
}
|
}
|
||||||
@ -25,7 +26,7 @@ export function getCustomNodeContent(
|
|||||||
// 按钮配置
|
// 按钮配置
|
||||||
const buttonConfig = {
|
const buttonConfig = {
|
||||||
gap: 4, // 按钮间距
|
gap: 4, // 按钮间距
|
||||||
fontSize: 24, // 字体大小
|
fontSize: 16, // 字体大小
|
||||||
height: 24, // 按钮高度
|
height: 24, // 按钮高度
|
||||||
width: 24, // 按钮宽度
|
width: 24, // 按钮宽度
|
||||||
};
|
};
|
||||||
@ -109,26 +110,15 @@ export function getCustomNodeContent(
|
|||||||
// 根据按钮类型执行不同操作
|
// 根据按钮类型执行不同操作
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "addChild":
|
case "addChild":
|
||||||
insertChildNode({
|
// 添加子节点
|
||||||
beforeInsertCallback: async () => ({
|
params.addChild?.(node);
|
||||||
uid: "",
|
|
||||||
text: "新子节点",
|
|
||||||
}),
|
|
||||||
parentNodeId: node.uid,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case "delete":
|
case "delete":
|
||||||
insertSiblingNode({
|
params.del?.(node);
|
||||||
beforeInsertCallback: async () => ({
|
|
||||||
uid: "",
|
|
||||||
text: "新同级节点",
|
|
||||||
}),
|
|
||||||
nodeId: node.uid,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case "edit":
|
case "edit":
|
||||||
// 获取实例并编辑当前节点
|
// 获取实例并编辑当前节点
|
||||||
|
params.edit?.(node);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -54,6 +54,15 @@ export const useMindMapStore = defineStore(
|
|||||||
// 添加自定义节点内容
|
// 添加自定义节点内容
|
||||||
addCustomContentToNode: getCustomNodeContent({
|
addCustomContentToNode: getCustomNodeContent({
|
||||||
allowRemoveWithChildren: false,
|
allowRemoveWithChildren: false,
|
||||||
|
del : (node: MindMapNode) => {
|
||||||
|
console.log("删除节点", node);
|
||||||
|
},
|
||||||
|
addChild: (node: MindMapNode) => {
|
||||||
|
console.log("添加子节点", node);
|
||||||
|
},
|
||||||
|
edit: (node: MindMapNode) => {
|
||||||
|
console.log("编辑节点", node);
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
demonstrateConfig: {
|
demonstrateConfig: {
|
||||||
@ -75,6 +84,18 @@ export const useMindMapStore = defineStore(
|
|||||||
currentLayout.value = layout;
|
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);
|
removeKeyCommand(mindMapInstance);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user