From 33929d69789f6787fa3d024c2017cdc92301c0c9 Mon Sep 17 00:00:00 2001 From: baiqi Date: Wed, 19 Jun 2024 18:58:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=85=A8=E5=B1=80):=20=E9=83=A8=E5=88=86?= =?UTF-8?q?=20bug=20=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ms-minders/featureCaseMinder/index.vue | 162 +++++++++--------- .../featureCaseMinder/useMinderBaseApi.ts | 5 +- .../ms-minders/testPlanMinder/index.vue | 82 +++++++-- .../hooks/useMinderEventListener.ts | 2 +- .../pure/ms-minder-editor/main/mainEditor.vue | 13 +- .../ms-minder-editor/menu/nodeFloatMenu.vue | 4 +- .../components/pure/ms-minder-editor/props.ts | 2 +- .../modules/components/minder-editor/index.ts | 4 +- .../modules/components/minder-editor/types.ts | 2 +- frontend/src/utils/index.ts | 4 + .../views/api-test/components/paramTable.vue | 5 +- .../scenario/components/step/index.vue | 3 + .../scenario/components/step/stepTree.vue | 1 + .../components/caseTable.vue | 26 ++- .../caseManagementFeature/index.vue | 5 +- .../views/test-plan/testPlan/detail/index.vue | 2 +- .../test-plan/testPlan/detail/plan/index.vue | 3 +- 17 files changed, 201 insertions(+), 124 deletions(-) diff --git a/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue b/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue index 8530fd0757..318f5c2ac4 100644 --- a/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue +++ b/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue @@ -85,7 +85,6 @@ } from '@/api/modules/case-management/featureCase'; import { useI18n } from '@/hooks/useI18n'; import useAppStore from '@/store/modules/app'; - import useFeatureCaseStore from '@/store/modules/case/featureCase'; import useMinderStore from '@/store/modules/components/minder-editor/index'; import { MinderCustomEvent } from '@/store/modules/components/minder-editor/types'; import { filterTree, getGenerateId, mapTree, replaceNodeInTree } from '@/utils'; @@ -160,60 +159,66 @@ async function initCaseTree(notRemote = false) { try { loading.value = true; - let res: MinderJsonNode[]; - if (notRemote) { - res = caseTree.value; - } else { - res = await getCaseMinderTree({ + if (!notRemote) { + const res = await getCaseMinderTree({ projectId: appStore.currentProjectId, moduleId: '', // 始终加载全部,然后再进入对应的模块节点 }); - } - caseTree.value = mapTree(res, (e) => ({ - ...e, - data: { - id: e.id, - text: e.name, - resource: props.modulesCount[e.id] !== undefined ? [moduleTag] : e.data?.resource, - expandState: e.level === 1 ? 'expand' : 'collapse', - count: props.modulesCount[e.id], - isNew: false, - changed: false, - }, - children: - props.modulesCount[e.id] > 0 && !e.children?.length - ? [ - { - data: { - id: 'fakeNode', - text: 'fakeNode', - resource: ['fakeNode'], - isNew: false, - changed: false, + caseTree.value = mapTree(res, (e) => ({ + ...e, + data: { + ...e.data, + id: e.id || e.data?.id || '', + text: e.name || e.data?.text || '', + resource: props.modulesCount[e.id] !== undefined ? [moduleTag] : e.data?.resource, + expandState: e.level === 1 ? 'expand' : 'collapse', + count: props.modulesCount[e.id], + isNew: false, + changed: false, + }, + children: + props.modulesCount[e.id] > 0 && !e.children?.length + ? [ + { + data: { + id: 'fakeNode', + text: 'fakeNode', + resource: ['fakeNode'], + isNew: false, + changed: false, + }, }, - }, - ] - : e.children, - })); - importJson.value.root = { - children: caseTree.value, - data: { - id: 'NONE', - text: t('ms.minders.allModule'), - resource: [moduleTag], - disabled: true, - }, - }; - importJson.value.treePath = []; - window.minder.importJson(importJson.value); - window.minder.execCommand('camera', window.minder.getRoot(), 100); - if (props.moduleId !== 'all') { - // 携带具体的模块 ID 加载时,进入该模块内 - nextTick(() => { - minderStore.dispatchEvent(MinderEventName.ENTER_NODE, undefined, undefined, undefined, [ - window.minder.getNodeById(props.moduleId), - ]); - }); + ] + : e.children, + })); + importJson.value.root = { + children: caseTree.value, + data: { + id: 'NONE', + text: t('ms.minders.allModule'), + resource: [moduleTag], + disabled: true, + }, + }; + importJson.value.treePath = []; + window.minder.importJson(importJson.value); + } + if (notRemote) { + if (props.moduleId !== 'all') { + // 携带具体的模块 ID 加载时,进入该模块内 + nextTick(() => { + minderStore.dispatchEvent(MinderEventName.ENTER_NODE, undefined, undefined, undefined, [ + window.minder.getNodeById(props.moduleId), + ]); + }); + } else { + // 携带具体的模块 ID 加载时,进入该模块内 + nextTick(() => { + minderStore.dispatchEvent(MinderEventName.ENTER_NODE, undefined, undefined, undefined, [ + importJson.value.root, + ]); + }); + } } } catch (error) { // eslint-disable-next-line no-console @@ -391,12 +396,13 @@ if ((!res || res.length === 0) && node.children?.length) { // 如果模块下没有用例且有别的模块节点,正常展开 node.expand(); - node.renderTree(); + window.minder.renderNodeBatch(node.children); node.layout(); + data.isLoaded = true; return; } // TODO:递归渲染存在的子节点 - const waitingRenderNodes: MinderJsonNode[] = []; + let waitingRenderNodes: MinderJsonNode[] = []; res.forEach((e) => { // 用例节点 const child = window.minder.createNode( @@ -439,14 +445,14 @@ }); node.expand(); // node.renderTree(); + if (node.children && node.children.length > 0) { + waitingRenderNodes = waitingRenderNodes.concat(node.children); + } window.minder.renderNodeBatch(waitingRenderNodes); node.layout(); - window.minder.execCommand('camera', node, 100); - if (node.data) { - node.data.isLoaded = true; - } + data.isLoaded = true; // 加载完用例数据后,更新当前importJson数据 - replaceNodeInTree([importJson.value.root], node.data?.id || '', node, 'data', 'id'); + replaceNodeInTree([importJson.value.root], node.data?.id || '', window.minder.exportNode(node), 'data', 'id'); } catch (error) { // eslint-disable-next-line no-console console.log(error); @@ -458,11 +464,6 @@ extraVisible.value = false; showDetailMenu.value = false; resetExtractInfo(); - if (node.children && node.children.length > 0 && node.data?.expandState === 'collapse') { - node.expand(); - node.renderTree(); - node.layout(); - } } setPriorityView(true, 'P'); } @@ -524,7 +525,7 @@ if (!caseOffspringTags.some((e) => node.data?.resource?.includes(e))) { // 非用例下的子孙节点的移除,才加入删除资源队列 tempMinderParams.value.deleteResourceList.push({ - id: node.data?.id || getGenerateId(), + id: node.data?.id || '', type: node.data?.resource?.[0] || moduleTag, }); } @@ -556,12 +557,12 @@ * 解析用例节点信息 * @param node 用例节点 */ - function getCaseNodeInfo(node: MinderJsonNode) { + function getCaseNodeInfo(node?: MinderJsonNode) { let textStep: MinderJsonNode | undefined; // 文本描述 let prerequisiteNode: MinderJsonNode | undefined; // 前置条件 let remarkNode: MinderJsonNode | undefined; // 备注 const stepNodes: MinderJsonNode[] = []; // 步骤描述 - node.children?.forEach((item) => { + node?.children?.forEach((item) => { if (item.data?.resource?.includes(textDescTag)) { textStep = item; } else if (item.data?.resource?.includes(stepTag)) { @@ -577,7 +578,7 @@ id: child.data?.id || getGenerateId(), num: i, desc: child.data?.text || '', - result: child.children?.[0].data?.text || '', + result: child.children?.[0]?.data?.text || '', }; }); return { @@ -587,7 +588,7 @@ textDescription: textStep?.data?.text || '', expectedResult: textStep?.children?.[0]?.data?.text || '', description: remarkNode?.data?.text || '', - priority: node.data?.priority, + priority: node?.data?.priority, }; } @@ -612,6 +613,17 @@ }; } + function resetMinderParams() { + tempMinderParams.value = { + projectId: appStore.currentProjectId, + versionId: '', + updateCaseList: [], + updateModuleList: [], + deleteResourceList: [], + additionalNodeList: [], + }; + } + /** * 生成脑图保存的入参 */ @@ -675,28 +687,20 @@ await saveCaseMinder(makeMinderParams(fullJson)); extraVisible.value = false; Message.success(t('common.saveSuccess')); - tempMinderParams.value = { - projectId: appStore.currentProjectId, - versionId: '', - updateCaseList: [], - updateModuleList: [], - deleteResourceList: [], - additionalNodeList: [], - }; + resetMinderParams(); emit('save'); callback(); } catch (error) { // eslint-disable-next-line no-console console.log(error); + resetMinderParams(); } finally { loading.value = false; } } - const featureCaseStore = useFeatureCaseStore(); - watch( - () => featureCaseStore.modulesCount, + () => props.moduleId, () => { initCaseTree(true); }, diff --git a/frontend/src/components/business/ms-minders/featureCaseMinder/useMinderBaseApi.ts b/frontend/src/components/business/ms-minders/featureCaseMinder/useMinderBaseApi.ts index d96ea9fdd3..168384eb51 100644 --- a/frontend/src/components/business/ms-minders/featureCaseMinder/useMinderBaseApi.ts +++ b/frontend/src/components/business/ms-minders/featureCaseMinder/useMinderBaseApi.ts @@ -259,9 +259,10 @@ export default function useMinderBaseApi({ hasEditPermission }: { hasEditPermiss if ( Object.keys(node.data || {}).length === 0 || node.data?.id === 'root' || - (node.parent?.data?.resource || []).length === 0 + (node.parent?.data?.resource || []).length === 0 || + node.parent?.data?.id === 'NONE' ) { - // 没有数据的节点、默认模块节点、父节点为文本节点的节点不可替换标签 + // 没有数据的节点、默认模块节点、父节点为文本节点、父节点为NONE虚拟根节点的节点不可替换标签 return []; } if (node.data?.resource?.some((e) => topTags.includes(e))) { diff --git a/frontend/src/components/business/ms-minders/testPlanMinder/index.vue b/frontend/src/components/business/ms-minders/testPlanMinder/index.vue index 28a36af96d..d553a219ae 100644 --- a/frontend/src/components/business/ms-minders/testPlanMinder/index.vue +++ b/frontend/src/components/business/ms-minders/testPlanMinder/index.vue @@ -13,7 +13,7 @@ :can-show-priority-menu="false" :can-show-float-menu="canShowFloatMenu" :can-show-delete-menu="canShowDeleteMenu" - :disable="!hasEditPermission" + :disabled="!hasEditPermission" custom-priority single-tag tag-enable @@ -86,7 +86,7 @@ - +