fix: 功能用例保存快捷键对多个tab生效

--bug=1008251 --user=陈建星 【github#7986】功能用例中同时打开多个用例,保存最开始打开的用例时,页面渲染标题重复 #7986 https://www.tapd.cn/55049933/s/1073101
This commit is contained in:
chenjianxing 2021-11-23 17:22:43 +08:00 committed by jianxing
parent 01c6287d6c
commit 396a01c3eb
5 changed files with 27 additions and 35 deletions

View File

@ -132,7 +132,7 @@ import SelectMenu from "../common/SelectMenu";
import MsContainer from "../../common/components/MsContainer"; import MsContainer from "../../common/components/MsContainer";
import MsAsideContainer from "../../common/components/MsAsideContainer"; import MsAsideContainer from "../../common/components/MsAsideContainer";
import MsMainContainer from "../../common/components/MsMainContainer"; 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 TestCaseNodeTree from "../common/TestCaseNodeTree";
import MsTabButton from "@/business/components/common/components/MsTabButton"; import MsTabButton from "@/business/components/common/components/MsTabButton";
@ -186,14 +186,7 @@ export default {
this.renderComponent = true; this.renderComponent = true;
}); });
}, },
'$route'(to, from) { '$route'(to) {
if (to.path.indexOf('/track/case/all') == -1) {
if (this.$refs && this.$refs.autoScenarioConfig) {
this.$refs.autoScenarioConfig.forEach(item => {
/*item.removeListener();*/
});
}
}
this.init(to); this.init(to);
}, },
activeName(newVal, oldVal) { activeName(newVal, oldVal) {
@ -271,7 +264,6 @@ export default {
if (redirectIDParam != null) { if (redirectIDParam != null) {
if (this.redirectFlag == "none") { if (this.redirectFlag == "none") {
this.activeName = "default"; this.activeName = "default";
this.addListener();
this.redirectFlag = "redirected"; this.redirectFlag = "redirected";
} }
} else { } else {
@ -297,12 +289,8 @@ export default {
label = tab.testCaseInfo.name; label = tab.testCaseInfo.name;
this.tabs.push({label: label, name: name, testCaseInfo: tab.testCaseInfo}); this.tabs.push({label: label, name: name, testCaseInfo: tab.testCaseInfo});
} }
if (this.$refs && this.$refs.testCaseEdit) {
this.$refs.testCaseEdit.forEach(item => { setCurTabId(this, tab, 'testCaseEdit');
/* item.removeListener();*/
}); // tab ctrl + s
this.addListener();
}
}, },
handleTabClose() { handleTabClose() {
let message = ""; let message = "";
@ -352,7 +340,6 @@ export default {
this.tabs = this.tabs.filter(tab => tab.name !== targetName); this.tabs = this.tabs.filter(tab => tab.name !== targetName);
if (this.tabs.length > 0) { if (this.tabs.length > 0) {
this.activeName = this.tabs[this.tabs.length - 1].name; this.activeName = this.tabs[this.tabs.length - 1].name;
this.addListener(); //
} else { } else {
this.activeName = "default"; this.activeName = "default";
} }
@ -364,16 +351,6 @@ export default {
} }
this.$refs.testCaseList.exportTestCase(type); this.$refs.testCaseList.exportTestCase(type);
}, },
addListener() {
let index = this.tabs.findIndex(item => item.name === this.activeName); // tabindex
if (index != -1) { // tab
this.$nextTick(() => {
/*
this.$refs.testCaseEdit[index].addListener();
*/
});
}
},
init(route) { init(route) {
let path = route.path; let path = route.path;
if (path.indexOf("/track/case/edit") >= 0 || path.indexOf("/track/case/create") >= 0) { if (path.indexOf("/track/case/edit") >= 0 || path.indexOf("/track/case/create") >= 0) {

View File

@ -149,7 +149,7 @@ import MsDialogFooter from '../../../common/components/MsDialogFooter'
import { import {
getCurrentProjectID, getCurrentProjectID,
getCurrentUser, getCurrentUser,
getNodePath, getNodePath, getUUID,
handleCtrlSEvent, hasPermission, handleCtrlSEvent, hasPermission,
listenGoBack, listenGoBack,
removeGoBackListener removeGoBackListener
@ -280,6 +280,7 @@ export default {
id: 'id', id: 'id',
label: 'name', label: 'name',
}, },
tabId: getUUID()
}; };
}, },
props: { props: {
@ -339,6 +340,9 @@ export default {
deep: true deep: true
} }
}, },
beforeDestroy() {
this.removeListener();
},
mounted() { mounted() {
this.getSelectOptions(); this.getSelectOptions();
if (this.type === 'edit' || this.type === 'copy') { if (this.type === 'edit' || this.type === 'copy') {
@ -828,7 +832,9 @@ export default {
document.removeEventListener("keydown", this.createCtrlSHandle); document.removeEventListener("keydown", this.createCtrlSHandle);
}, },
createCtrlSHandle(event) { createCtrlSHandle(event) {
handleCtrlSEvent(event, this.saveCase); let curTabId = this.$store.state.curTabId;
if (curTabId === this.tabId)
handleCtrlSEvent(event, this.saveCase);
}, },
saveFollow() { saveFollow() {
if (this.showFollow) { if (this.showFollow) {

View File

@ -488,3 +488,14 @@ export function getShareId() {
} }
return ""; 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);
}
})
}

View File

@ -20,7 +20,6 @@ const state = {
testReviewSelectNode: {}, testReviewSelectNode: {},
testReviewSelectNodeIds: [], testReviewSelectNodeIds: [],
testReviewModuleOptions: [],
useEnvironment: "", useEnvironment: "",
testPlanViewSelectNode: {}, testPlanViewSelectNode: {},
selectStep: {}, selectStep: {},
@ -33,7 +32,8 @@ const state = {
scenarioMap: new Map(), scenarioMap: new Map(),
apiMap: new Map(), apiMap: new Map(),
apiStatus: new Map(), apiStatus: new Map(),
testCaseMap: new Map() testCaseMap: new Map(),
curTabId: null
} }
const store = new Vuex.Store({ const store = new Vuex.Store({

View File

@ -13,13 +13,11 @@ const mutations = {
setTestReviewSelectNode: (state, value) => state.testReviewSelectNode = value, setTestReviewSelectNode: (state, value) => state.testReviewSelectNode = value,
setTestReviewSelectNodeIds: (state, value) => state.testReviewSelectNodeIds = value, setTestReviewSelectNodeIds: (state, value) => state.testReviewSelectNodeIds = value,
setTestReviewModuleOptions: (state, value) => state.testReviewModuleOptions = value,
setTestPlanViewSelectNode: (state, value) => state.testPlanViewSelectNode = value, setTestPlanViewSelectNode: (state, value) => state.testPlanViewSelectNode = value,
setIsTestCaseMinderChanged: (state, value) => state.isTestCaseMinderChanged = value, setIsTestCaseMinderChanged: (state, value) => state.isTestCaseMinderChanged = value,
setCurrentProjectIsCustomNum: (state, value) => state.currentProjectIsCustomNum = value, setCurrentProjectIsCustomNum: (state, value) => state.currentProjectIsCustomNum = value,
setTestCaseTemplate: (state, value) => { setTestCaseTemplate: (state, value) => state.testCaseTemplate = value,
state.testCaseTemplate = value setCurTabId: (state, value) => state.curTabId = value,
},
} }
export default mutations; export default mutations;