From 0fa2ab5982628dc3bef58923a69d5b76d65e67e7 Mon Sep 17 00:00:00 2001 From: baiqi Date: Tue, 13 Aug 2024 18:20:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=84=91=E5=9B=BE):=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=A7=84=E5=88=92=E8=84=91=E5=9B=BE=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hooks/useMinderOperation.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/pure/ms-minder-editor/hooks/useMinderOperation.ts b/frontend/src/components/pure/ms-minder-editor/hooks/useMinderOperation.ts index db6456e149..dd8152f167 100644 --- a/frontend/src/components/pure/ms-minder-editor/hooks/useMinderOperation.ts +++ b/frontend/src/components/pure/ms-minder-editor/hooks/useMinderOperation.ts @@ -206,10 +206,12 @@ export default function useMinderOperation(options: MinderOperationProps) { * @param command 插入命令 * @param value 携带的参数 */ - const execInsertCommand = (command: string, value?: string) => { - const node: MinderJsonNode = window.minder.getSelectedNode(); + const execInsertCommand = (command: string, selectedNodes: MinderJsonNode[], value?: string) => { + if (selectedNodes.length > 1) { + return; // TODO: 批量操作暂不支持插入 + } if (options.insertNode) { - options.insertNode(node, command, value); + options.insertNode(selectedNodes[0], command, value); return; } if (window.minder.queryCommandState(command) !== -1) { @@ -233,7 +235,7 @@ export default function useMinderOperation(options: MinderOperationProps) { * @param value 携带的参数 */ const appendChildNode = (selectedNodes: MinderJsonNode[], value?: string) => { - execInsertCommand('AppendChildNode', value); + execInsertCommand('AppendChildNode', selectedNodes, value); minderStore.dispatchEvent(MinderEventName.INSERT_CHILD, value, undefined, undefined, selectedNodes); }; @@ -243,7 +245,7 @@ export default function useMinderOperation(options: MinderOperationProps) { * @param value 携带的参数 */ const appendSiblingNode = (selectedNodes: MinderJsonNode[], value?: string) => { - execInsertCommand('AppendSiblingNode', value); + execInsertCommand('AppendSiblingNode', selectedNodes, value); minderStore.dispatchEvent(MinderEventName.INSERT_SIBLING, value, undefined, undefined, selectedNodes); }; @@ -289,12 +291,16 @@ export default function useMinderOperation(options: MinderOperationProps) { * @param selectedNodes 当前选中的节点集合 */ const minderDelete = (selectedNodes: MinderJsonNode[]) => { + if (selectedNodes.length > 1 && (!options.canShowBatchDelete || options.disabled)) { + // 批量操作节点时,如果不允许批量删除或者当前操作被禁用,则不执行删除操作 + return; + } if ( - (options.canShowDeleteMenu || - (options.canShowMoreMenu && options.canShowMoreMenuNodeOperation) || - options.canShowBatchDelete) && + selectedNodes.length === 1 && + (options.canShowDeleteMenu || (options.canShowMoreMenu && options.canShowMoreMenuNodeOperation)) && !options.disabled ) { + // 单个节点操作,如果允许删除操作,则执行删除操作 const newNodes = selectedNodes.map((node) => ({ ...node, parent: node.parent, // 保存父节点信息,因为删除节点后 parent 会被置空