fix(脑图): 测试规划脑图批量删除问题修复

This commit is contained in:
baiqi 2024-08-13 18:20:21 +08:00 committed by 刘瑞斌
parent f6e1abc18a
commit 0fa2ab5982
1 changed files with 14 additions and 8 deletions

View File

@ -206,10 +206,12 @@ export default function useMinderOperation(options: MinderOperationProps) {
* @param command * @param command
* @param value * @param value
*/ */
const execInsertCommand = (command: string, value?: string) => { const execInsertCommand = (command: string, selectedNodes: MinderJsonNode[], value?: string) => {
const node: MinderJsonNode = window.minder.getSelectedNode(); if (selectedNodes.length > 1) {
return; // TODO: 批量操作暂不支持插入
}
if (options.insertNode) { if (options.insertNode) {
options.insertNode(node, command, value); options.insertNode(selectedNodes[0], command, value);
return; return;
} }
if (window.minder.queryCommandState(command) !== -1) { if (window.minder.queryCommandState(command) !== -1) {
@ -233,7 +235,7 @@ export default function useMinderOperation(options: MinderOperationProps) {
* @param value * @param value
*/ */
const appendChildNode = (selectedNodes: MinderJsonNode[], value?: string) => { const appendChildNode = (selectedNodes: MinderJsonNode[], value?: string) => {
execInsertCommand('AppendChildNode', value); execInsertCommand('AppendChildNode', selectedNodes, value);
minderStore.dispatchEvent(MinderEventName.INSERT_CHILD, value, undefined, undefined, selectedNodes); minderStore.dispatchEvent(MinderEventName.INSERT_CHILD, value, undefined, undefined, selectedNodes);
}; };
@ -243,7 +245,7 @@ export default function useMinderOperation(options: MinderOperationProps) {
* @param value * @param value
*/ */
const appendSiblingNode = (selectedNodes: MinderJsonNode[], value?: string) => { const appendSiblingNode = (selectedNodes: MinderJsonNode[], value?: string) => {
execInsertCommand('AppendSiblingNode', value); execInsertCommand('AppendSiblingNode', selectedNodes, value);
minderStore.dispatchEvent(MinderEventName.INSERT_SIBLING, value, undefined, undefined, selectedNodes); minderStore.dispatchEvent(MinderEventName.INSERT_SIBLING, value, undefined, undefined, selectedNodes);
}; };
@ -289,12 +291,16 @@ export default function useMinderOperation(options: MinderOperationProps) {
* @param selectedNodes * @param selectedNodes
*/ */
const minderDelete = (selectedNodes: MinderJsonNode[]) => { const minderDelete = (selectedNodes: MinderJsonNode[]) => {
if (selectedNodes.length > 1 && (!options.canShowBatchDelete || options.disabled)) {
// 批量操作节点时,如果不允许批量删除或者当前操作被禁用,则不执行删除操作
return;
}
if ( if (
(options.canShowDeleteMenu || selectedNodes.length === 1 &&
(options.canShowMoreMenu && options.canShowMoreMenuNodeOperation) || (options.canShowDeleteMenu || (options.canShowMoreMenu && options.canShowMoreMenuNodeOperation)) &&
options.canShowBatchDelete) &&
!options.disabled !options.disabled
) { ) {
// 单个节点操作,如果允许删除操作,则执行删除操作
const newNodes = selectedNodes.map((node) => ({ const newNodes = selectedNodes.map((node) => ({
...node, ...node,
parent: node.parent, // 保存父节点信息,因为删除节点后 parent 会被置空 parent: node.parent, // 保存父节点信息,因为删除节点后 parent 会被置空