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"})
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void addTestCase(@RequestPart("request") EditTestCaseRequest request, @RequestPart(value = "file") List<MultipartFile> files) {
testCaseService.save(request, files);
public String addTestCase(@RequestPart("request") EditTestCaseRequest request, @RequestPart(value = "file") List<MultipartFile> files) {
return testCaseService.save(request, files);
}
@PostMapping(value = "/edit", consumes = {"multipart/form-data"})

View File

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

View File

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

View File

@ -659,7 +659,7 @@ export default {
let param = this.buildParam();
if (this.validate(param)) {
let option = this.getOption(param);
this.result = this.$request(option, () => {
this.result = this.$request(option, (response) => {
this.$success(this.$t('commons.save_success'));
if (this.operationType == 'add' && this.isCreateContinue) {
this.form.name = '';
@ -678,6 +678,13 @@ export default {
}
this.dialogFormVisible = false;
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 {

View File

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

View File

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

View File

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