fix #295 include both save and cancel cases of popup modal; however, for cases when conformance page acting as starting point, bugs are still there

This commit is contained in:
Cindy Chang
2024-05-31 16:04:52 +08:00
parent 0a1eefbaa7
commit 2142399f8c
4 changed files with 57 additions and 26 deletions

View File

@@ -10,7 +10,7 @@
</template>
<script>
import { storeToRefs, mapActions, } from 'pinia';
import { storeToRefs, mapActions, mapState, } from 'pinia';
import LoadingStore from '@/stores/loading.js';
import AllMapDataStore from '@/stores/allMapData.js';
import ConformanceStore from '@/stores/conformance.js';
@@ -41,17 +41,23 @@ export default {
Navbar,
Loading
},
computed: {
...mapState(PageAdminStore, ['shouldKeepPreviousPage']),
},
methods: {
...mapActions(PageAdminStore, ['copyPendingPageToActivePage', 'setPrevioiusPage'],),
...mapActions(PageAdminStore, ['copyPendingPageToActivePage', 'setPrevioiusPage',
'clearShouldKeepPreviousPageBoolean',
],),
},
created() {
// Save token in Headers.
const token = document.cookie.replace(/(?:(?:^|.*;\s*)luciaToken\s*\=\s*([^;]*).*$)|^.*$/, "$1");
this.$http.defaults.headers.common['Authorization'] = `Bearer ${token}`;
},
// Swal modal handling is called before beforeRouteUpdate
beforeRouteUpdate(to, from, next) {
// console.log("beforeRouteUpdate", from.name, "to:", to.name);
this.setPrevioiusPage(from.name);
console.log("beforeRouteUpdate from.name", from.name)
// 離開 Map 頁時判斷是否有無資料和需要存檔
if ((from.name === 'Map' || from.name === 'CheckMap') && this.tempFilterId) {
@@ -60,15 +66,19 @@ export default {
leaveFilter(next, this.allMapDataStore.addFilterId, to.path)
} else if((this.$route.name === 'Conformance' || this.$route.name === 'CheckConformance')
&& (this.conformanceLogTempCheckId || this.conformanceFilterTempCheckId)) {
leaveConformance(next, this.conformanceStore.addConformanceCreateCheckId, to.path)
leaveConformance(next, this.conformanceStore.addConformanceCreateCheckId, to.path);
} else if(this.shouldKeepPreviousPage) {
// pass on and reset boolean for future use
this.clearShouldKeepPreviousPageBoolean();
} else {
// most cases go this road
// In this else block:
// for those pages who don't need popup modals, we handle page administration right now.
// By calling the following code, we decide the next visiting page.
this.copyPendingPageToActivePage();
next();
};
}
},
};
</script>