From 21a4586ddc0ffa48023aca6ed1594e689757036c Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 24 Mar 2021 19:53:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=20=E7=BC=96=E8=BE=91=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=91=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/components/MsModuleMinder.vue | 3 + .../components/track/case/TestCase.vue | 13 ++- .../track/common/minder/TestCaseMinder.vue | 16 +++- .../track/common/minder/minderUtils.js | 87 +++++++------------ 4 files changed, 56 insertions(+), 63 deletions(-) diff --git a/frontend/src/business/components/common/components/MsModuleMinder.vue b/frontend/src/business/components/common/components/MsModuleMinder.vue index 16c98b690d..e13ea1f363 100644 --- a/frontend/src/business/components/common/components/MsModuleMinder.vue +++ b/frontend/src/business/components/common/components/MsModuleMinder.vue @@ -122,6 +122,9 @@ export default { this.$nextTick(() => { this.isActive = true; }) + }, + setJsonImport(data) { + this.importJson = data; } } } diff --git a/frontend/src/business/components/track/case/TestCase.vue b/frontend/src/business/components/track/case/TestCase.vue index 725d332c4d..88d25907b2 100644 --- a/frontend/src/business/components/track/case/TestCase.vue +++ b/frontend/src/business/components/track/case/TestCase.vue @@ -8,7 +8,7 @@ @setTreeNodes="setTreeNodes" @exportTestCase="exportTestCase" @saveAsEdit="editTestCase" - @createCase="handleCaseCreateOrEdit($event, 'add')" + @createCase="handleCaseSimpleCreate($event, 'add')" @refreshAll="refreshAll" :type="'edit'" ref="nodeTree" @@ -158,6 +158,11 @@ export default { } } }, + activeName(newVal, oldVal) { + if (oldVal !== 'default' && newVal === 'default' && this.$refs.minder) { + this.$refs.minder.refresh(); + } + } }, computed: { checkRedirectID: function () { @@ -303,6 +308,12 @@ export default { this.$refs.minder.addCase(data, type); } }, + handleCaseSimpleCreate(data, type) { + this.handleCaseCreateOrEdit(data, type); + if (this.$refs.minder) { + this.$refs.minder.refresh(); + } + }, copyTestCase(testCase) { this.type="copy" this.testCaseReadOnly = false; diff --git a/frontend/src/business/components/track/common/minder/TestCaseMinder.vue b/frontend/src/business/components/track/common/minder/TestCaseMinder.vue index 38d6ad35a9..b4365c0966 100644 --- a/frontend/src/business/components/track/common/minder/TestCaseMinder.vue +++ b/frontend/src/business/components/track/common/minder/TestCaseMinder.vue @@ -6,6 +6,7 @@ :tags="tags" :distinct-tags="tags" @save="save" + ref="minder" /> @@ -13,9 +14,8 @@ import MsModuleMinder from "@/business/components/common/components/MsModuleMinder"; import { appendChild, - editNode, getTestCaseDataMap, - parseCase + parseCase, updateNode } from "@/business/components/track/common/minder/minderUtils"; export default { name: "TestCaseMinder", @@ -138,10 +138,18 @@ name: "TestCaseMinder", }, addCase(data, type) { let nodeData = parseCase(data, new Map()); + let minder = window.minder; + let jsonImport = minder.exportJson(); if (type === 'edit') { - editNode(nodeData); + updateNode(jsonImport.root, nodeData); } else { - appendChild(data.nodeId, nodeData); + appendChild(data.nodeId, jsonImport.root, nodeData); + } + this.$refs.minder.setJsonImport(jsonImport); + }, + refresh() { + if (this.$refs.minder) { + this.$refs.minder.reload(); } } } diff --git a/frontend/src/business/components/track/common/minder/minderUtils.js b/frontend/src/business/components/track/common/minder/minderUtils.js index 308d3cc6c0..7f7ab72e36 100644 --- a/frontend/src/business/components/track/common/minder/minderUtils.js +++ b/frontend/src/business/components/track/common/minder/minderUtils.js @@ -85,68 +85,39 @@ function _parseChildren(children, k, v, isDisable) { } } -export function appendChild(pId, appendNode) { - if (!pId) { - pId = 'root'; - } - let minder = window.minder; - let nodes = minder.getAllNode(); - let parent = undefined; - for (let index = nodes.length -1; index >= 0; index--) { - let item = nodes[index]; - if(item.data.id === pId) { - parent = item; - break; - } - } - if (!parent) { +export function appendChild(appendPid, root, node) { + if (root.data.id === appendPid) { + root.children.push(node); return; } - let node = minder.createNode("", parent); - minder.select(node, true); - node.data = appendNode.data; - if (parent.isExpanded()) { - node.render(); - } else { - parent.expand(); - parent.renderTree(); + if (!root.children) { + root.children = []; } - minder.layout(600); - - // 添加子节点 - let children = appendNode.children; - if (children) { - children.forEach(child => { - child.data.id = getUUID(); - appendChild(node.data.id, child); - }) - } -} - -export function editNode(node) { - let minder = window.minder; - let nodes = minder.getAllNode(); - let children = []; - let item = undefined; - for (const index in nodes) { - item = nodes[index]; - if(item.data.id === node.data.id) { - item.data = node.data; - children = node.children; - if (item.children) { - item.children.forEach(n => { - minder.removeNode(n); - }) - } - item.render(); - break; + let children = root.children; + for (const index in children) { + let item = children[index]; + if (item.data.id === appendPid) { + item.data.expandState = "expand"; + item.children.push(node); + return; + } else { + appendChild(appendPid, item, node); } } - minder.layout(600); - if (item) { - children.forEach(child => { - child.data.id = getUUID(); - appendChild(item.data.id, child); - }) +} + +export function updateNode(root, node) { + if (!root.children) { + root.children = []; + } + let children = root.children; + for (const index in children) { + let item = children[index]; + if (item.data.id === node.data.id) { + children[index] = node; + return; + } else { + updateNode(item, node); + } } }