fix: 新增编辑用例更新脑图

This commit is contained in:
chenjianxing 2021-03-24 17:51:51 +08:00
parent b3675c3a41
commit 3e52d67914
7 changed files with 153 additions and 42 deletions

View File

@ -120,8 +120,8 @@ public class TestCaseController {
@PostMapping(value = "/add", consumes = {"multipart/form-data"}) @PostMapping(value = "/add", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void addTestCase(@RequestPart("request") EditTestCaseRequest request, @RequestPart(value = "file") List<MultipartFile> files) { public String addTestCase(@RequestPart("request") EditTestCaseRequest request, @RequestPart(value = "file") List<MultipartFile> files) {
testCaseService.save(request, files); return testCaseService.save(request, files);
} }
@PostMapping(value = "/edit", consumes = {"multipart/form-data"}) @PostMapping(value = "/edit", consumes = {"multipart/form-data"})

View File

@ -8,6 +8,7 @@
@setTreeNodes="setTreeNodes" @setTreeNodes="setTreeNodes"
@exportTestCase="exportTestCase" @exportTestCase="exportTestCase"
@saveAsEdit="editTestCase" @saveAsEdit="editTestCase"
@createCase="handleCaseCreateOrEdit($event, 'add')"
@refreshAll="refreshAll" @refreshAll="refreshAll"
:type="'edit'" :type="'edit'"
ref="nodeTree" ref="nodeTree"
@ -44,7 +45,7 @@
:tree-nodes="treeNodes" :tree-nodes="treeNodes"
:project-id="projectId" :project-id="projectId"
v-if="activeDom === 'right'" v-if="activeDom === 'right'"
ref="testCaseList"/> ref="minder"/>
</ms-tab-button> </ms-tab-button>
</el-tab-pane> </el-tab-pane>
<el-tab-pane <el-tab-pane
@ -58,6 +59,8 @@
:currentTestCaseInfo="item.testCaseInfo" :currentTestCaseInfo="item.testCaseInfo"
@refresh="refreshTable" @refresh="refreshTable"
@setModuleOptions="setModuleOptions" @setModuleOptions="setModuleOptions"
@caseEdit="handleCaseCreateOrEdit($event,'edit')"
@caseCreate="handleCaseCreateOrEdit($event,'add')"
:read-only="testCaseReadOnly" :read-only="testCaseReadOnly"
:tree-nodes="treeNodes" :tree-nodes="treeNodes"
:select-node="selectNode" :select-node="selectNode"
@ -282,7 +285,9 @@ export default {
this.selectParentNodes = pNodes; this.selectParentNodes = pNodes;
}, },
refreshTable() { refreshTable() {
if ( this.$refs.testCaseList) {
this.$refs.testCaseList.initTableData(); this.$refs.testCaseList.initTableData();
}
}, },
editTestCase(testCase) { editTestCase(testCase) {
this.type="edit" this.type="edit"
@ -293,11 +298,14 @@ export default {
} }
this.addTab({name: 'edit', testCaseInfo: testCase}); this.addTab({name: 'edit', testCaseInfo: testCase});
}, },
handleCaseCreateOrEdit(data, type) {
if (this.$refs.minder) {
this.$refs.minder.addCase(data, type);
}
},
copyTestCase(testCase) { copyTestCase(testCase) {
this.type="copy" this.type="copy"
this.testCaseReadOnly = false; this.testCaseReadOnly = false;
let item = {};
testCase.isCopy = true; testCase.isCopy = true;
this.addTab({name: 'edit', testCaseInfo: testCase}); this.addTab({name: 'edit', testCaseInfo: testCase});
}, },

View File

@ -125,6 +125,7 @@ export default {
this.$emit('saveAsEdit', this.testCaseForm); this.$emit('saveAsEdit', this.testCaseForm);
} else { } else {
this.$emit('refresh'); this.$emit('refresh');
this.$emit('createCase', this.testCaseForm);
} }
}) })
} else { } else {

View File

@ -659,7 +659,7 @@ export default {
let param = this.buildParam(); let param = this.buildParam();
if (this.validate(param)) { if (this.validate(param)) {
let option = this.getOption(param); let option = this.getOption(param);
this.result = this.$request(option, () => { this.result = this.$request(option, (response) => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
if (this.operationType == 'add' && this.isCreateContinue) { if (this.operationType == 'add' && this.isCreateContinue) {
this.form.name = ''; this.form.name = '';
@ -678,6 +678,13 @@ export default {
} }
this.dialogFormVisible = false; this.dialogFormVisible = false;
this.$emit("refresh"); this.$emit("refresh");
if (this.type === 'add' || this.type === 'copy') {
param.id = response.data;
this.$emit("caseCreate", param);
this.close();
} else {
this.$emit("caseEdit", param);
}
}); });
} }
} else { } else {

View File

@ -35,6 +35,7 @@
<test-case-create <test-case-create
:tree-nodes="treeNodes" :tree-nodes="treeNodes"
@saveAsEdit="saveAsEdit" @saveAsEdit="saveAsEdit"
@createCase="createCase"
@refresh="refresh" @refresh="refresh"
ref="testCaseCreate" ref="testCaseCreate"
></test-case-create> ></test-case-create>
@ -98,6 +99,9 @@ export default {
saveAsEdit(data) { saveAsEdit(data) {
this.$emit('saveAsEdit', data); this.$emit('saveAsEdit', data);
}, },
createCase(data) {
this.$emit('createCase', data);
},
refresh() { refresh() {
this.$emit("refreshTable"); this.$emit("refreshTable");
}, },

View File

@ -11,7 +11,12 @@
<script> <script>
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder"; import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
import {getTestCaseDataMap} from "@/business/components/track/common/minder/minderUtils"; import {
appendChild,
editNode,
getTestCaseDataMap,
parseCase
} from "@/business/components/track/common/minder/minderUtils";
export default { export default {
name: "TestCaseMinder", name: "TestCaseMinder",
components: {MsModuleMinder}, components: {MsModuleMinder},
@ -48,6 +53,7 @@ name: "TestCaseMinder",
} }
}, },
save(data) { save(data) {
console.log(data);
let saveCases = []; let saveCases = [];
let deleteCases = []; let deleteCases = [];
this.buildSaveCase(data.root, saveCases, deleteCases, undefined); this.buildSaveCase(data.root, saveCases, deleteCases, undefined);
@ -130,7 +136,14 @@ name: "TestCaseMinder",
throw new Error(tip); throw new Error(tip);
} }
}, },
addCase(data, type) {
let nodeData = parseCase(data, new Map());
if (type === 'edit') {
editNode(nodeData);
} else {
appendChild(data.nodeId, nodeData);
}
}
} }
} }
</script> </script>

View File

@ -1,8 +1,21 @@
import {getUUID} from "@/common/js/utils";
export function getTestCaseDataMap(testCase, isDisable, setParamCallback) { export function getTestCaseDataMap(testCase, isDisable, setParamCallback) {
let dataMap = new Map(); let dataMap = new Map();
if (testCase) { if (testCase) {
testCase.forEach(item => { testCase.forEach(item => {
parseCase(item, dataMap, isDisable, setParamCallback);
})
}
return dataMap;
}
export function parseCase(item, dataMap, isDisable, setParamCallback) {
if (item.steps) {
item.steps = JSON.parse(item.steps); item.steps = JSON.parse(item.steps);
} else {
item.steps = [];
}
// if (item.tags && item.tags.length > 0) { // if (item.tags && item.tags.length > 0) {
// item.tags = JSON.parse(item.tags); // item.tags = JSON.parse(item.tags);
// } // }
@ -34,9 +47,7 @@ export function getTestCaseDataMap(testCase, isDisable, setParamCallback) {
mapItem.push(nodeItem); mapItem.push(nodeItem);
dataMap.set(item.nodeId, mapItem); dataMap.set(item.nodeId, mapItem);
} }
}) return nodeItem;
}
return dataMap;
} }
function parseChildren(nodeItem, item, isDisable) { function parseChildren(nodeItem, item, isDisable) {
@ -63,7 +74,8 @@ function _parseChildren(children, k, v, isDisable) {
data: { data: {
text: k, text: k,
resource: v ? [v] : [] resource: v ? [v] : []
} },
children: []
} }
if (isDisable) { if (isDisable) {
node.data.disable = true; node.data.disable = true;
@ -72,3 +84,69 @@ function _parseChildren(children, k, v, isDisable) {
return node; return node;
} }
} }
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) {
return;
}
let node = minder.createNode("", parent);
minder.select(node, true);
node.data = appendNode.data;
if (parent.isExpanded()) {
node.render();
} else {
parent.expand();
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) {
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;
}
}
minder.layout(600);
if (item) {
children.forEach(child => {
child.data.id = getUUID();
appendChild(item.data.id, child);
})
}
}