refactor: 路由跳转时提示脑图保存

--bug=1008131 --user=陈建星 【github#7831】进入【测试跟踪】-【测试计划】,标记用例执行结果,点击其他窗口,未提示保存,导致用例执行结果记录丢失。 https://www.tapd.cn/55049933/s/1074851
This commit is contained in:
chenjianxing 2021-11-26 16:49:44 +08:00 committed by jianxing
parent 8dc638b8fe
commit 8b2ad7a60c
8 changed files with 65 additions and 12 deletions

View File

@ -166,7 +166,8 @@ export default {
type: '', type: '',
activeDom: 'left', activeDom: 'left',
tmpActiveDom: null, tmpActiveDom: null,
total: 0 total: 0,
tmpPath: null
}; };
}, },
mounted() { mounted() {
@ -178,6 +179,14 @@ export default {
this.init(this.$route); this.init(this.$route);
} }
}, },
beforeRouteLeave(to, from, next) {
if (this.$store.state.isTestCaseMinderChanged) {
this.$refs.isChangeConfirm.open();
this.tmpPath = to.path;
} else {
next();
}
},
watch: { watch: {
redirectID() { redirectID() {
this.renderComponent = false; this.renderComponent = false;

View File

@ -58,7 +58,9 @@ export default {
open() { open() {
this.init(); this.init();
this.$refs.baseRelevance.open(); this.$refs.baseRelevance.open();
if (this.$refs.apiCaseList) {
this.$refs.apiCaseList.clear(); this.$refs.apiCaseList.clear();
}
}, },
init() { init() {
if (this.$refs.apiCaseList) { if (this.$refs.apiCaseList) {

View File

@ -567,10 +567,18 @@ export function openMinderConfirm(vueObj, activeDom) {
export function saveMinderConfirm(vueObj, isSave) { export function saveMinderConfirm(vueObj, isSave) {
if (isSave) { if (isSave) {
vueObj.$refs.minder.save(window.minder.exportJson()); vueObj.$refs.minder.save(window.minder.exportJson());
} else {
vueObj.$store.commit('setIsTestCaseMinderChanged', false);
} }
vueObj.$store.commit('setIsTestCaseMinderChanged', false);
vueObj.$nextTick(() => { vueObj.$nextTick(() => {
if (vueObj.tmpActiveDom) {
vueObj.activeDom = vueObj.tmpActiveDom; vueObj.activeDom = vueObj.tmpActiveDom;
vueObj.tmpActiveDom = null;
}
if (vueObj.tmpPath) {
vueObj.$router.push({
path: vueObj.tmpPath
});
vueObj.tmpPath = null;
}
}); });
} }

View File

@ -20,7 +20,7 @@
</template> </template>
</ms-test-plan-header-bar> </ms-test-plan-header-bar>
<test-plan-functional v-if="activeIndex === 'functional'" :redirectCharType="redirectCharType" <test-plan-functional v-if="activeIndex === 'functional'" :redirectCharType="redirectCharType"
:clickType="clickType" :plan-id="planId"/> :clickType="clickType" :plan-id="planId" ref="testPlanFunctional"/>
<test-plan-api v-if="activeIndex === 'api'" :redirectCharType="redirectCharType" :clickType="clickType" <test-plan-api v-if="activeIndex === 'api'" :redirectCharType="redirectCharType" :clickType="clickType"
:plan-id="planId"/> :plan-id="planId"/>
<test-plan-load v-if="activeIndex === 'load'" :redirectCharType="redirectCharType" :clickType="clickType" <test-plan-load v-if="activeIndex === 'load'" :redirectCharType="redirectCharType" :clickType="clickType"
@ -82,6 +82,13 @@ export default {
this.getTestPlans(); this.getTestPlans();
} }
}, },
beforeRouteLeave(to, from, next) {
if (!this.$refs.testPlanFunctional) {
next();
} else if (this.$refs.testPlanFunctional.handleBeforeRouteLeave(to)) {
next();
}
},
created() { created() {
this.$EventBus.$on('projectChange', () => { this.$EventBus.$on('projectChange', () => {
if (this.$route.name === 'planView') { if (this.$route.name === 'planView') {

View File

@ -450,7 +450,7 @@ export default {
this.testCaseTemplate = template; this.testCaseTemplate = template;
this.fields = getTableHeaderWithCustomFields(this.tableHeaderKey, this.testCaseTemplate.customFields); this.fields = getTableHeaderWithCustomFields(this.tableHeaderKey, this.testCaseTemplate.customFields);
this.result.loading = false; this.result.loading = false;
this.$refs.table.reloadTable(); if (this.$refs.table) this.$refs.table.reloadTable();
}); });
}, },
getCustomFieldValue(row, field) { getCustomFieldValue(row, field) {

View File

@ -83,7 +83,8 @@ export default {
activeDom: 'left', activeDom: 'left',
selectNode: {}, selectNode: {},
condition: {}, condition: {},
tmpActiveDom: null tmpActiveDom: null,
tmpPath: null
}; };
}, },
props: [ props: [
@ -164,7 +165,16 @@ export default {
}, },
changeConfirm(isSave) { changeConfirm(isSave) {
saveMinderConfirm(this, isSave); saveMinderConfirm(this, isSave);
},
handleBeforeRouteLeave(to) {
if (this.$store.state.isTestCaseMinderChanged) {
this.$refs.isChangeConfirm.open();
this.tmpPath = to.path;
return false;
} else {
return true;
} }
},
} }
}; };

View File

@ -17,7 +17,7 @@
</template> </template>
</ms-test-plan-header-bar> </ms-test-plan-header-bar>
<test-review-function v-if="activeIndex === 'functional'" :redirectCharType="redirectCharType" <test-review-function v-if="activeIndex === 'functional'" :redirectCharType="redirectCharType"
:clickType="clickType" :review-id="reviewId"></test-review-function> :clickType="clickType" :review-id="reviewId" ref="testReviewFunction"/>
</div> </div>
</template> </template>
@ -86,6 +86,13 @@ export default {
this.initData(); this.initData();
this.openTestCaseEdit(this.$route.path); this.openTestCaseEdit(this.$route.path);
}, },
beforeRouteLeave(to, from, next) {
if (!this.$refs.testReviewFunction) {
next();
} else if (this.$refs.testReviewFunction.handleBeforeRouteLeave(to)) {
next();
}
},
watch: { watch: {
'$route'(to, from) { '$route'(to, from) {
this.openTestCaseEdit(to.path); this.openTestCaseEdit(to.path);

View File

@ -82,7 +82,8 @@ export default {
isMenuShow: true, isMenuShow: true,
activeDom: 'left', activeDom: 'left',
condition: {}, condition: {},
tmpActiveDom: null tmpActiveDom: null,
tmpPath: null
} }
}, },
props: [ props: [
@ -130,7 +131,16 @@ export default {
}, },
changeConfirm(isSave) { changeConfirm(isSave) {
saveMinderConfirm(this, isSave); saveMinderConfirm(this, isSave);
},
handleBeforeRouteLeave(to) {
if (this.$store.state.isTestCaseMinderChanged) {
this.$refs.isChangeConfirm.open();
this.tmpPath = to.path;
return false;
} else {
return true;
} }
},
} }
} }
</script> </script>