diff --git a/test-track/frontend/src/business/case/components/TestCaseEdit.vue b/test-track/frontend/src/business/case/components/TestCaseEdit.vue index da7794b890..eee003f513 100644 --- a/test-track/frontend/src/business/case/components/TestCaseEdit.vue +++ b/test-track/frontend/src/business/case/components/TestCaseEdit.vue @@ -607,9 +607,6 @@ export default { routeProjectId() { return this.$route.query.projectId; }, - moduleOptions() { - return store.testCaseModuleOptions; - }, isCustomNum() { return store.currentProjectIsCustomNum; }, @@ -802,8 +799,11 @@ export default { this.treeNodes.forEach(node => { node.name = node.name === '未规划用例' ? this.$t('api_test.unplanned_case') : node.name buildTree(node, {path: ''}); - this.setNodeModule(); }); + if (!this.caseId) { + // 创建时设置模块ID + this.setDefaultModule(); + } }); } @@ -903,19 +903,6 @@ export default { "TRACK_TEST_CASE", ]); }, - setNodeModule() { - if (this.caseId) { - this.form.module = this.currentTestCaseInfo.nodeId; - this.form.nodePath = this.currentTestCaseInfo.nodePath; - } - if ((!this.form.module || - this.form.module === "default-module" || - this.form.module === "root") - && this.treeNodes.length > 0) { - this.form.module = this.treeNodes[0].id; - this.form.nodePath = this.treeNodes[0].path; - } - }, setDefaultValue() { if (!this.form.prerequisite) { this.form.prerequisite = ""; @@ -1022,9 +1009,7 @@ export default { // add document.title = this.$t('test_track.case.create_case'); - if (this.moduleOptions.length > 0) { - this.form.module = this.moduleOptions[0].id; - } + let user = JSON.parse(localStorage.getItem(TokenKey)); this.form.priority = "P3"; this.form.type = "functional"; @@ -1045,6 +1030,11 @@ export default { callback(); } }, + setDefaultModule() { + if (this.$refs.testCaseBaseInfo) { + this.$refs.testCaseBaseInfo.doSetDefaultModule(this.treeNodes); + } + }, async checkCurrentProject() { if (this.isPublicShow) { // 用例库查看用例 @@ -1154,7 +1144,10 @@ export default { this.form.stepModel = "STEP"; } this.casePublic = tmp.casePublic; + this.form.module = testCase.nodeId; + + this.$refs.testCaseBaseInfo.setDefaultModule(); //设置自定义熟悉默认值 this.customFieldForm = parseCustomField( this.form, diff --git a/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue b/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue index 3f5f5d5ffc..74fe0a1d03 100644 --- a/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue +++ b/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue @@ -8,7 +8,7 @@
ID
-
+
@@ -447,6 +448,7 @@ export default { demandOptions: [], versionFilters: [], demandList: [], + defaultModuleKey: '' }; }, props: { @@ -471,36 +473,38 @@ export default { isCustomNum() { return useStore().currentProjectIsCustomNum; }, - defaultModuleKey() { - if (this.editable && !this.editableState) { - let defaultNodeKey = ''; - if (this.$route.query.createNodeId) { - defaultNodeKey = this.$route.query.createNodeId; - } else { - this.treeNodes.forEach(node => { - if (node.label === '未规划用例') { - defaultNodeKey = node.id; - this.form.module = defaultNodeKey; - this.form.nodePath = node.path; - } - }) - } - return defaultNodeKey; - } else { - return this.form.module - } + createNodeId() { + return this.$route.query.createNodeId; } }, mounted() { this.getDemandOptions(); this.getVersionOptions(); - if (this.$route.query.createNodeId) { - this.form.module = this.$route.query.createNodeId; - let node = this.findTreeNode(this.treeNodes); - this.form.nodePath = node.path; - } }, methods: { + setDefaultModule() { + this.doSetDefaultModule(this.treeNodes); + }, + doSetDefaultModule(treeNodes) { + if (treeNodes && treeNodes.length > 0) { + if (this.createNodeId) { + // 创建时设置选中的模块 + this.form.module = this.createNodeId; + let node = this.findTreeNode(treeNodes); + this.form.nodePath = node.path; + } else if (this.form.module) { + // 编辑重新设置下 nodePath + let node = this.findTreeNode(treeNodes); + this.form.nodePath = node ? node.path : ''; + } else { + // 创建不带模块ID,设置成为规划模块 + this.form.module = treeNodes[0].id; + this.form.nodePath = treeNodes[0].path; + } + this.defaultModuleKey = this.form.module; + this.$refs.moduleTree.setData(this.form.module); + } + }, handleDemandOptionPlatform(data){ if(data.platform){ return data.platform @@ -586,8 +590,10 @@ export default { } }, setModule(id, data) { - this.form.module = id; - this.form.nodePath = data.path; + if (data) { + this.form.module = id; + this.form.nodePath = data.path; + } }, mouseLeaveEvent(refName) { if (!this.editable && this.$refs[refName]) {