refactor: 编辑新增测试用例实时更新脑图
This commit is contained in:
parent
3e52d67914
commit
21a4586ddc
|
@ -122,6 +122,9 @@ export default {
|
|||
this.$nextTick(() => {
|
||||
this.isActive = true;
|
||||
})
|
||||
},
|
||||
setJsonImport(data) {
|
||||
this.importJson = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
:tags="tags"
|
||||
:distinct-tags="tags"
|
||||
@save="save"
|
||||
ref="minder"
|
||||
/>
|
||||
</template>
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue