diff --git a/test-track/frontend/src/business/case/components/BaseEditItemComponent.vue b/test-track/frontend/src/business/case/components/BaseEditItemComponent.vue index 89efdde175..a273222ce4 100644 --- a/test-track/frontend/src/business/case/components/BaseEditItemComponent.vue +++ b/test-track/frontend/src/business/case/components/BaseEditItemComponent.vue @@ -205,6 +205,9 @@ export default { }); }, getTranslateOption(item) { + if (!item) { + return ''; + } if (Array.isArray(item)) { let arr = []; item.forEach((v) => { diff --git a/test-track/frontend/src/business/case/components/TestCaseEdit.vue b/test-track/frontend/src/business/case/components/TestCaseEdit.vue index 13f9793d1c..08f01d3d89 100644 --- a/test-track/frontend/src/business/case/components/TestCaseEdit.vue +++ b/test-track/frontend/src/business/case/components/TestCaseEdit.vue @@ -79,7 +79,7 @@
@@ -89,7 +89,7 @@
@@ -150,7 +150,7 @@
@@ -567,7 +567,7 @@ export default { }, computed: { routeProjectId() { - return this.$route.params.projectId; + return this.$route.query.projectId; }, moduleOptions() { return store.testCaseModuleOptions; @@ -795,16 +795,17 @@ export default { this.checkVersionEnable(); }, - editPublicCase(type) { + editPublicCase() { // 这个接口会校验权限 getEditSimpleTestCase(this.caseId) .then(() => { - openCaseEdit({caseId: this.caseId, type}, this); + openCaseEdit({caseId: this.caseId}, this); }) .catch(() => {}); }, copyPublicCase() { - this.editPublicCase('copy'); + // 这里复制使用当前项目,不使用 projectId ,可能没有权限 + openCaseEdit({caseId: this.caseId, type: 'copy', projectId: getCurrentProjectID()}, this); }, closePublicCase() { this.$emit("close"); @@ -986,11 +987,26 @@ export default { }); } else { this.projectId = this.routeProjectId; - if (this.routeProjectId) { - // 创建时会带 projectId,校验是否是当前项目 - if (getCurrentProjectID() !== this.projectId) { - setCurrentProjectID(this.projectId); - location.reload(); + // 创建和复制 + if (this.isCopy || this.isAdd) { + // 带了 routeProjectId 校验是否是当前项目 + if (this.routeProjectId) { + if (getCurrentProjectID() !== this.projectId) { + setCurrentProjectID(this.projectId); + location.reload(); + return; + } + } else { + // 没带 routeProjectId 则使用当前项目 + this.projectId = getCurrentProjectID(); + } + if (this.caseId) { + // copy + await getSimpleTestCase(this.caseId).then((response) => { + let testCase = response.data; + // 重置用例的项目ID + testCase.projectId = this.projectId; + }); } } else if (this.caseId) { // 接口会校验是否有改用例的编辑权限 @@ -1559,7 +1575,7 @@ export default { this.saveCase(); }, copyRow() { - openCaseEdit({caseId: this.testCase.id, type: 'copy'}, this); + openCaseEdit({caseId: this.testCase.id, type: 'copy', projectId: this.projectId}, this); }, deleteRow() { getTestCaseVersions(this.testCase.id) diff --git a/test-track/frontend/src/business/case/components/TestCaseList.vue b/test-track/frontend/src/business/case/components/TestCaseList.vue index 57890416a5..983caaa045 100644 --- a/test-track/frontend/src/business/case/components/TestCaseList.vue +++ b/test-track/frontend/src/business/case/components/TestCaseList.vue @@ -844,8 +844,8 @@ export default { reloadTable() { this.$refs.table.resetHeader(); }, - handleEdit(testCase, type) { - openCaseEdit({caseId: testCase.id, type}, this); + handleEdit(testCase) { + openCaseEdit({caseId: testCase.id}, this); }, getCase(id) { this.$refs.testCasePreview.open(); @@ -870,7 +870,7 @@ export default { }); }, handleCopy(testCase) { - this.handleEdit(testCase, 'copy'); + openCaseEdit({caseId: testCase.id, type: 'copy', projectId: this.projectId}, this); }, handleDelete(testCase) { let title = this.$t('test_track.case.case_delete_completely_confirm') + ": " + testCase.name + "?"; diff --git a/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue b/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue index 598cb7d83a..b8fb4a9bed 100644 --- a/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue +++ b/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue @@ -447,11 +447,11 @@ export default { callBackSelectAll(selection) { this.selectCounts = this.$refs.table.selectDataCounts; }, - handleEdit(testCase, type) { + handleEdit(testCase) { // 这个接口会校验权限 getEditSimpleTestCase(testCase.id) .then(() => { - openCaseEdit({caseId: testCase.id, type}, this); + openCaseEdit({caseId: testCase.id}, this); }) .catch(() => {}); }, diff --git a/test-track/frontend/src/business/case/test-case.js b/test-track/frontend/src/business/case/test-case.js index ecddf237b6..ecc05e3dec 100644 --- a/test-track/frontend/src/business/case/test-case.js +++ b/test-track/frontend/src/business/case/test-case.js @@ -64,7 +64,11 @@ export function openCaseEdit(query, v) { if (!query.type) { delete query.type; } - delete query.projectId; + if (query.type !== 'copy') { + // 编辑不带项目id,会检查用例的权限 + // 复制需要带项目id,复制到当前项目,包括用例库的复制 + delete query.projectId; + } let path = '/track/case/edit/' + query.caseId; delete query.caseId; let TestCaseData = v.$router.resolve({