From 396a01c3eb50bc467b149902e0ae4da68e4f111c Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 23 Nov 2021 17:22:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=BF=AB=E6=8D=B7=E9=94=AE=E5=AF=B9=E5=A4=9A?= =?UTF-8?q?=E4=B8=AAtab=E7=94=9F=E6=95=88=20--bug=3D1008251=20--user=3D?= =?UTF-8?q?=E9=99=88=E5=BB=BA=E6=98=9F=20=E3=80=90github#7986=E3=80=91?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E4=B8=AD=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=A4=9A=E4=B8=AA=E7=94=A8=E4=BE=8B,?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=9C=80=E5=BC=80=E5=A7=8B=E6=89=93=E5=BC=80?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E4=BE=8B=E6=97=B6,=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E6=A0=87=E9=A2=98=E9=87=8D=E5=A4=8D=20#7986?= =?UTF-8?q?=20https://www.tapd.cn/55049933/s/1073101?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/track/case/TestCase.vue | 31 +++---------------- .../track/case/components/TestCaseEdit.vue | 10 ++++-- frontend/src/common/js/utils.js | 11 +++++++ frontend/src/store/index.js | 4 +-- frontend/src/store/mutations.js | 6 ++-- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/frontend/src/business/components/track/case/TestCase.vue b/frontend/src/business/components/track/case/TestCase.vue index d375a94003..b585e5e5f0 100644 --- a/frontend/src/business/components/track/case/TestCase.vue +++ b/frontend/src/business/components/track/case/TestCase.vue @@ -132,7 +132,7 @@ import SelectMenu from "../common/SelectMenu"; import MsContainer from "../../common/components/MsContainer"; import MsAsideContainer from "../../common/components/MsAsideContainer"; import MsMainContainer from "../../common/components/MsMainContainer"; -import {getCurrentProjectID, getUUID, hasPermission} from "@/common/js/utils"; +import {getCurrentProjectID, getUUID, hasPermission, setCurTabId} from "@/common/js/utils"; import TestCaseNodeTree from "../common/TestCaseNodeTree"; import MsTabButton from "@/business/components/common/components/MsTabButton"; @@ -186,14 +186,7 @@ export default { this.renderComponent = true; }); }, - '$route'(to, from) { - if (to.path.indexOf('/track/case/all') == -1) { - if (this.$refs && this.$refs.autoScenarioConfig) { - this.$refs.autoScenarioConfig.forEach(item => { - /*item.removeListener();*/ - }); - } - } + '$route'(to) { this.init(to); }, activeName(newVal, oldVal) { @@ -271,7 +264,6 @@ export default { if (redirectIDParam != null) { if (this.redirectFlag == "none") { this.activeName = "default"; - this.addListener(); this.redirectFlag = "redirected"; } } else { @@ -297,12 +289,8 @@ export default { label = tab.testCaseInfo.name; this.tabs.push({label: label, name: name, testCaseInfo: tab.testCaseInfo}); } - if (this.$refs && this.$refs.testCaseEdit) { - this.$refs.testCaseEdit.forEach(item => { - /* item.removeListener();*/ - }); // 删除所有tab的 ctrl + s 监听 - this.addListener(); - } + + setCurTabId(this, tab, 'testCaseEdit'); }, handleTabClose() { let message = ""; @@ -352,7 +340,6 @@ export default { this.tabs = this.tabs.filter(tab => tab.name !== targetName); if (this.tabs.length > 0) { this.activeName = this.tabs[this.tabs.length - 1].name; - this.addListener(); // 自动切换当前标签时,也添加监听 } else { this.activeName = "default"; } @@ -364,16 +351,6 @@ export default { } this.$refs.testCaseList.exportTestCase(type); }, - addListener() { - let index = this.tabs.findIndex(item => item.name === this.activeName); // 找到当前选中tab的index - if (index != -1) { // 为当前选中的tab添加监听 - this.$nextTick(() => { - /* - this.$refs.testCaseEdit[index].addListener(); - */ - }); - } - }, init(route) { let path = route.path; if (path.indexOf("/track/case/edit") >= 0 || path.indexOf("/track/case/create") >= 0) { diff --git a/frontend/src/business/components/track/case/components/TestCaseEdit.vue b/frontend/src/business/components/track/case/components/TestCaseEdit.vue index 9e1cd3e869..6d9bca16cd 100644 --- a/frontend/src/business/components/track/case/components/TestCaseEdit.vue +++ b/frontend/src/business/components/track/case/components/TestCaseEdit.vue @@ -149,7 +149,7 @@ import MsDialogFooter from '../../../common/components/MsDialogFooter' import { getCurrentProjectID, getCurrentUser, - getNodePath, + getNodePath, getUUID, handleCtrlSEvent, hasPermission, listenGoBack, removeGoBackListener @@ -280,6 +280,7 @@ export default { id: 'id', label: 'name', }, + tabId: getUUID() }; }, props: { @@ -339,6 +340,9 @@ export default { deep: true } }, + beforeDestroy() { + this.removeListener(); + }, mounted() { this.getSelectOptions(); if (this.type === 'edit' || this.type === 'copy') { @@ -828,7 +832,9 @@ export default { document.removeEventListener("keydown", this.createCtrlSHandle); }, createCtrlSHandle(event) { - handleCtrlSEvent(event, this.saveCase); + let curTabId = this.$store.state.curTabId; + if (curTabId === this.tabId) + handleCtrlSEvent(event, this.saveCase); }, saveFollow() { if (this.showFollow) { diff --git a/frontend/src/common/js/utils.js b/frontend/src/common/js/utils.js index d575b4ef90..4083c2150f 100644 --- a/frontend/src/common/js/utils.js +++ b/frontend/src/common/js/utils.js @@ -488,3 +488,14 @@ export function getShareId() { } return ""; } + +export function setCurTabId(vueObj, tab, ref) { + vueObj.$nextTick(() => { + if (vueObj.$refs && vueObj.$refs[ref]) { + let index = tab.index ? Number.parseInt(tab.index) : vueObj.tabs.length; + let cutEditTab = vueObj.$refs[ref][index - 1]; + let curTabId = cutEditTab ? cutEditTab.tabId : null; + vueObj.$store.commit('setCurTabId', curTabId); + } + }) +} diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 8c62778ba8..acfb9158d0 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -20,7 +20,6 @@ const state = { testReviewSelectNode: {}, testReviewSelectNodeIds: [], - testReviewModuleOptions: [], useEnvironment: "", testPlanViewSelectNode: {}, selectStep: {}, @@ -33,7 +32,8 @@ const state = { scenarioMap: new Map(), apiMap: new Map(), apiStatus: new Map(), - testCaseMap: new Map() + testCaseMap: new Map(), + curTabId: null } const store = new Vuex.Store({ diff --git a/frontend/src/store/mutations.js b/frontend/src/store/mutations.js index 9b6a7917ce..5d439b569c 100644 --- a/frontend/src/store/mutations.js +++ b/frontend/src/store/mutations.js @@ -13,13 +13,11 @@ const mutations = { setTestReviewSelectNode: (state, value) => state.testReviewSelectNode = value, setTestReviewSelectNodeIds: (state, value) => state.testReviewSelectNodeIds = value, - setTestReviewModuleOptions: (state, value) => state.testReviewModuleOptions = value, setTestPlanViewSelectNode: (state, value) => state.testPlanViewSelectNode = value, setIsTestCaseMinderChanged: (state, value) => state.isTestCaseMinderChanged = value, setCurrentProjectIsCustomNum: (state, value) => state.currentProjectIsCustomNum = value, - setTestCaseTemplate: (state, value) => { - state.testCaseTemplate = value - }, + setTestCaseTemplate: (state, value) => state.testCaseTemplate = value, + setCurTabId: (state, value) => state.curTabId = value, } export default mutations;