refactor: 编辑新增测试用例实时更新脑图

This commit is contained in:
chenjianxing 2021-03-24 19:53:08 +08:00
parent 3e52d67914
commit 21a4586ddc
4 changed files with 56 additions and 63 deletions

View File

@ -122,6 +122,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.isActive = true; this.isActive = true;
}) })
},
setJsonImport(data) {
this.importJson = data;
} }
} }
} }

View File

@ -8,7 +8,7 @@
@setTreeNodes="setTreeNodes" @setTreeNodes="setTreeNodes"
@exportTestCase="exportTestCase" @exportTestCase="exportTestCase"
@saveAsEdit="editTestCase" @saveAsEdit="editTestCase"
@createCase="handleCaseCreateOrEdit($event, 'add')" @createCase="handleCaseSimpleCreate($event, 'add')"
@refreshAll="refreshAll" @refreshAll="refreshAll"
:type="'edit'" :type="'edit'"
ref="nodeTree" ref="nodeTree"
@ -158,6 +158,11 @@ export default {
} }
} }
}, },
activeName(newVal, oldVal) {
if (oldVal !== 'default' && newVal === 'default' && this.$refs.minder) {
this.$refs.minder.refresh();
}
}
}, },
computed: { computed: {
checkRedirectID: function () { checkRedirectID: function () {
@ -303,6 +308,12 @@ export default {
this.$refs.minder.addCase(data, type); this.$refs.minder.addCase(data, type);
} }
}, },
handleCaseSimpleCreate(data, type) {
this.handleCaseCreateOrEdit(data, type);
if (this.$refs.minder) {
this.$refs.minder.refresh();
}
},
copyTestCase(testCase) { copyTestCase(testCase) {
this.type="copy" this.type="copy"
this.testCaseReadOnly = false; this.testCaseReadOnly = false;

View File

@ -6,6 +6,7 @@
:tags="tags" :tags="tags"
:distinct-tags="tags" :distinct-tags="tags"
@save="save" @save="save"
ref="minder"
/> />
</template> </template>
@ -13,9 +14,8 @@
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder"; import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
import { import {
appendChild, appendChild,
editNode,
getTestCaseDataMap, getTestCaseDataMap,
parseCase parseCase, updateNode
} from "@/business/components/track/common/minder/minderUtils"; } from "@/business/components/track/common/minder/minderUtils";
export default { export default {
name: "TestCaseMinder", name: "TestCaseMinder",
@ -138,10 +138,18 @@ name: "TestCaseMinder",
}, },
addCase(data, type) { addCase(data, type) {
let nodeData = parseCase(data, new Map()); let nodeData = parseCase(data, new Map());
let minder = window.minder;
let jsonImport = minder.exportJson();
if (type === 'edit') { if (type === 'edit') {
editNode(nodeData); updateNode(jsonImport.root, nodeData);
} else { } 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();
} }
} }
} }

View File

@ -85,68 +85,39 @@ function _parseChildren(children, k, v, isDisable) {
} }
} }
export function appendChild(pId, appendNode) { export function appendChild(appendPid, root, node) {
if (!pId) { if (root.data.id === appendPid) {
pId = 'root'; root.children.push(node);
}
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) {
return; return;
} }
let node = minder.createNode("", parent); if (!root.children) {
minder.select(node, true); root.children = [];
node.data = appendNode.data; }
if (parent.isExpanded()) { let children = root.children;
node.render(); for (const index in children) {
let item = children[index];
if (item.data.id === appendPid) {
item.data.expandState = "expand";
item.children.push(node);
return;
} else { } else {
parent.expand(); appendChild(appendPid, item, node);
parent.renderTree();
} }
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) { export function updateNode(root, node) {
let minder = window.minder; if (!root.children) {
let nodes = minder.getAllNode(); root.children = [];
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(); let children = root.children;
break; for (const index in children) {
let item = children[index];
if (item.data.id === node.data.id) {
children[index] = node;
return;
} else {
updateNode(item, node);
} }
} }
minder.layout(600);
if (item) {
children.forEach(child => {
child.data.id = getUUID();
appendChild(item.data.id, child);
})
}
} }