diff --git a/frontend/src/components/business/ms-minders/caseReviewMinder/index.vue b/frontend/src/components/business/ms-minders/caseReviewMinder/index.vue index afbddea559..b139fd0174 100644 --- a/frontend/src/components/business/ms-minders/caseReviewMinder/index.vue +++ b/frontend/src/components/business/ms-minders/caseReviewMinder/index.vue @@ -116,11 +116,13 @@ import MsMinderEditor from '@/components/pure/ms-minder-editor/minderEditor.vue'; import type { MinderJson, MinderJsonNode, MinderJsonNodeData } from '@/components/pure/ms-minder-editor/props'; import { + clearNodeChildren, clearSelectedNodes, createNode, expendNodeAndChildren, handleRenderNode, removeFakeNode, + renderSubModules, renderSubNodes, setPriorityView, } from '@/components/pure/ms-minder-editor/script/tool/utils'; @@ -516,13 +518,17 @@ // 如果是用例,则status是获取后端的值,可直接替换标签 if (isCaseTag(node.data)) { window.minder.execCommand('resource', [statusTagMap[status]]); + } else if (node.data.id === 'NONE') { + // 处理根节点,重新渲染整个用例树 + initCaseTree(); } else if (status !== StartReviewStatus.UNDER_REVIEWED && node.data?.resource?.includes(moduleTag)) { - // 先清空子节点,从后向前遍历时,删除节点不会影响到尚未遍历的节点 - for (let i = node.children.length - 1; i >= 0; i--) { - window.minder.removeNode(node.children[i]); + // 处理模块节点 + clearNodeChildren(node); + renderSubModules(node, importJson.value.root, modulesCount.value); + // 重新渲染用例 + if (node.data.id !== 'NONE') { + initNodeCases(node); } - // 再重新渲染 - initNodeCases(node); } emit('handleReviewDone'); } diff --git a/frontend/src/components/business/ms-minders/testPlanFeatureCaseMinder/index.vue b/frontend/src/components/business/ms-minders/testPlanFeatureCaseMinder/index.vue index 82442e1417..77fd775897 100644 --- a/frontend/src/components/business/ms-minders/testPlanFeatureCaseMinder/index.vue +++ b/frontend/src/components/business/ms-minders/testPlanFeatureCaseMinder/index.vue @@ -218,11 +218,13 @@ import MsMinderEditor from '@/components/pure/ms-minder-editor/minderEditor.vue'; import type { MinderJson, MinderJsonNode, MinderJsonNodeData } from '@/components/pure/ms-minder-editor/props'; import { + clearNodeChildren, clearSelectedNodes, createNode, expendNodeAndChildren, handleRenderNode, removeFakeNode, + renderSubModules, renderSubNodes, setPriorityView, } from '@/components/pure/ms-minder-editor/script/tool/utils'; @@ -675,13 +677,17 @@ initExecuteHistory(node.data); } window.minder.refresh(); + } else if (node.data.id === 'NONE') { + // 处理根节点,重新渲染整个用例树 + initCaseTree(); } else if (isModuleOrCollection(node.data)) { - // 先清空子节点,从后向前遍历时,删除节点不会影响到尚未遍历的节点 - for (let i = node.children.length - 1; i >= 0; i--) { - window.minder.removeNode(node.children[i]); - } + // 处理模块节点 + clearNodeChildren(node); + renderSubModules(node, importJson.value.root, modulesCount.value); // 再重新渲染 - initNodeCases(node); + if (node.data.id !== 'NONE') { + initNodeCases(node); + } } emit('refreshPlan'); } diff --git a/frontend/src/components/pure/ms-minder-editor/script/tool/utils.ts b/frontend/src/components/pure/ms-minder-editor/script/tool/utils.ts index 27fd67eda5..e19b6b9bde 100644 --- a/frontend/src/components/pure/ms-minder-editor/script/tool/utils.ts +++ b/frontend/src/components/pure/ms-minder-editor/script/tool/utils.ts @@ -1,7 +1,11 @@ import type { MinderJsonNode, MinderJsonNodeData } from '@/components/pure/ms-minder-editor/props'; +import { useI18n } from '@/hooks/useI18n'; import type { MinderNodePosition } from '@/store/modules/components/minder-editor/types'; -import { getGenerateId, mapTree } from '@/utils'; +import { findNodeByKey, getGenerateId, mapTree } from '@/utils'; + +const { t } = useI18n(); +const moduleTag = t('common.module'); export function isDisableNode(minder: any) { let node: MinderJsonNode; @@ -243,3 +247,58 @@ export function clearSelectedNodes() { window.minder.toggleSelect(currentSelectedNodes); } } + +// 清空子节点,从后向前遍历时,删除节点不会影响到尚未遍历的节点 +export function clearNodeChildren(node: MinderJsonNode) { + if (!node.children?.length) return; + for (let i = node.children.length - 1; i >= 0; i--) { + window.minder.removeNode(node.children[i]); + } +} + +// 重新递归渲染子模块 +export function renderSubModules( + node: MinderJsonNode, + importJsonRoot: MinderJsonNode, + modulesCount: Record +) { + const waitingRenderNodes: MinderJsonNode[] = []; + const createSubModules = (id: string) => { + const curNode: MinderJsonNode | null = findNodeByKey(importJsonRoot.children as MinderJsonNode[], id, 'id', 'data'); + const minderNode = window.minder.getNodeById(id); + if (curNode?.children) { + const moduleNode = curNode.children.filter( + (child) => child.data?.resource?.includes(moduleTag) || child.data?.type === 'tmpModule' + ); + if (!moduleNode.length) { + const newNode = createNode( + { + id: 'fakeNode', + text: t('ms.minders.moreCase'), + resource: [''], + }, + minderNode + ); + waitingRenderNodes.push(newNode); + } else { + moduleNode.forEach((childNode) => { + if (!childNode.data) return; + const newNode = createNode( + { + ...childNode.data, + id: childNode.id || childNode.data?.id || '', + text: childNode.name || childNode.data?.text.replace(/<\/?p\b[^>]*>/gi, '') || '', + count: modulesCount[childNode.data.id], + isLoaded: false, + }, + minderNode + ); + waitingRenderNodes.push(newNode); + createSubModules(childNode.data.id); + }); + } + } + }; + createSubModules(node.data?.id as string); + handleRenderNode(node, waitingRenderNodes); +}