fix: 测试用例页面浏览器回退问题

This commit is contained in:
chenjianxing 2020-07-22 20:42:59 +08:00
parent af03676879
commit 73a4ee5d12
4 changed files with 50 additions and 15 deletions

View File

@ -107,7 +107,7 @@
}
let caseId = this.$route.params.caseId;
this.openRecentTestCaseEditDialog(caseId);
this.$router.push('/track/case/all');
// this.$router.push('/track/case/all');
} else if (route.params.projectId){
this.getProjects();
this.getProjectById(route.params.projectId);
@ -205,7 +205,7 @@
this.$get('/project/get/' + id, response => {
let project = response.data;
this.setCurrentProject(project);
this.$router.push('/track/case/all');
// this.$router.push('/track/case/all');
});
}
if (id === 'all') {

View File

@ -2,7 +2,7 @@
<div>
<el-dialog
<el-dialog @close="close"
:title="operationType == 'edit' ? ( readOnly ? $t('test_track.case.view_case') : $t('test_track.case.edit_case')) : $t('test_track.case.create')"
:visible.sync="dialogFormVisible" width="65%">
@ -295,6 +295,7 @@
methods: {
open(testCase) {
this.resetForm();
this.listenGoBack();
this.operationType = 'add';
if (testCase) {
//
@ -346,6 +347,18 @@
}
});
},
listenGoBack() {
//
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.close, false);
}
},
close() {
//
window.removeEventListener('popstate', this.goBack, false);
this.dialogFormVisible = false;
},
saveCase() {
this.$refs['caseFrom'].validate((valid) => {
if (valid) {

View File

@ -8,7 +8,8 @@
<el-menu-item :index="'/track/home'">
{{ $t("i18n.home") }}
</el-menu-item>
<el-submenu v-permission="['test_manager','test_user','test_viewer']" index="3" popper-class="submenu">
<el-submenu :class="{'deactivation':!isProjectActivation}"
v-permission="['test_manager','test_user','test_viewer']" index="3" popper-class="submenu">
<template v-slot:title>{{$t('commons.project')}}</template>
<ms-recent-list :options="projectRecent"/>
<el-divider/>
@ -23,6 +24,7 @@
<el-divider/>
<ms-show-all :index="'/track/case/all'"/>
<el-menu-item :index="testCaseEditPath" class="blank_item"></el-menu-item>
<el-menu-item :index="testCaseProjectPath" class="blank_item"></el-menu-item>
<ms-create-button v-permission="['test_manager','test_user']" :index="'/track/case/create'" :title="$t('test_track.case.create_case')"/>
</el-submenu>
@ -55,6 +57,8 @@
testPlanViewPath: '',
isRouterAlive: true,
testCaseEditPath: '',
testCaseProjectPath: '',
isProjectActivation: true,
projectRecent: {
title: this.$t('project.recent'),
url: "/project/recent/5",
@ -84,24 +88,38 @@
}
},
watch: {
'$route'(to, from) {
let path = to.path;
if (path.indexOf("/track/plan/view") >= 0) {
this.testPlanViewPath = '/track/plan/view/' + this.$route.params.planId;
this.reload();
}
if (path.indexOf("/track/case/edit") >= 0) {
this.testCaseEditPath = '/track/case/edit/' + this.$route.params.caseId;
this.reload();
}
'$route'(to) {
this.init();
}
},
mounted() {
this.init();
},
methods: {
reload() {
this.isRouterAlive = false;
this.$nextTick(function () {
this.isRouterAlive = true;
});
},
init() {
let path = this.$route.path;
if (path.indexOf("/track/case") >= 0 && !!this.$route.params.projectId) {
this.testCaseProjectPath = path;
//
this.isProjectActivation = false;
this.reload();
} else {
this.isProjectActivation = true;
}
if (path.indexOf("/track/plan/view") >= 0) {
this.testPlanViewPath = path;
this.reload();
}
if (path.indexOf("/track/case/edit") >= 0) {
this.testCaseEditPath = path;
this.reload();
}
}
}
}
@ -125,4 +143,9 @@
.el-divider--horizontal {
margin: 0;
}
.deactivation >>> .el-submenu__title {
border-bottom: white !important;
}
</style>

View File

@ -354,7 +354,6 @@
}
this.testCase = item;
this.initTest();
//
this.stepResultChange();
},
openTestCaseEdit(testCase) {