From b58e013957d3ad94e0a1f445c710eaf7e8dcc383 Mon Sep 17 00:00:00 2001 From: gaoyunqi Date: Thu, 25 Apr 2024 10:43:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B7=AF=E7=94=B1=E7=88=B6=E7=BA=A7?= =?UTF-8?q?=E7=9A=84=E8=AE=B0=E5=BD=95=E6=94=B9=E4=B8=BA=E5=85=A8=E5=B1=80?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E7=82=B9=E5=87=BB=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=8D=A1X=E6=97=A0=E6=B3=95=E8=B7=B3=E8=BD=AC=E5=88=B0?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E6=9D=A5=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 3 +++ src/router/guard/index.ts | 7 +++++-- src/store/modules/multipleTab.ts | 4 +++- src/views/secondDev/approveFlowPage.vue | 4 +--- src/views/secondDev/createFlow.vue | 6 ++---- src/views/secondDev/formCreatePage.vue | 4 +--- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main.ts b/src/main.ts index 770ab3b..1266495 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,9 @@ import { Modal } from 'ant-design-vue'; import 'ant-design-vue/dist/antd.less'; //如果需要使用葡萄城报表 放开代码注释 // import { Core } from '@grapecity/activereports'; +window.fcd = { + routeBackMapping: {} +}; async function bootstrap() { const app = createApp(App); diff --git a/src/router/guard/index.ts b/src/router/guard/index.ts index 9645488..cd55b98 100644 --- a/src/router/guard/index.ts +++ b/src/router/guard/index.ts @@ -38,9 +38,12 @@ function createPageGuard(router: Router) { // Notify routing changes setRouteChange(to); const toPath = to.path; - if (toPath.indexOf('views/secondDev') >= 0 || toPath.indexOf('/viewForm') >= 0) { + if (/createFlow|approveFlow|createForm|viewForm/.test(toPath)) { // 记录从哪里来的 关闭页面的时候好跳回去 - localStorage.setItem('parentRoutePath', from.path); + if(!window.fcd.routeBackMapping[to.path]){ + // tab切换也会触发路由守卫 所以只记录第一次的状态 + window.fcd.routeBackMapping[to.path] = from.path; + } } return true; }); diff --git a/src/store/modules/multipleTab.ts b/src/store/modules/multipleTab.ts index 6e6894e..a8f61ec 100644 --- a/src/store/modules/multipleTab.ts +++ b/src/store/modules/multipleTab.ts @@ -184,7 +184,7 @@ export const useMultipleTabStore = defineStore({ } }, - async closeTab(tab: RouteLocationNormalized, router: Router, backTo: String) { + async closeTab(tab: RouteLocationNormalized, router: Router) { const close = (route: RouteLocationNormalized) => { const { fullPath, meta: { affix } = {} } = route; if (affix) { @@ -207,6 +207,8 @@ export const useMultipleTabStore = defineStore({ let toTarget: RouteLocationRaw = {}; const index = this.tabList.findIndex((item) => item.path === path); + const backTo = window.fcd.routeBackMapping[tab.path]; + delete window.fcd.routeBackMapping[tab.path]; const backToIndex = backTo ? this.tabList.findIndex((item) => item.path === backTo) : -1; // If the current is the leftmost tab diff --git a/src/views/secondDev/approveFlowPage.vue b/src/views/secondDev/approveFlowPage.vue index de545e7..a5b18bd 100644 --- a/src/views/secondDev/approveFlowPage.vue +++ b/src/views/secondDev/approveFlowPage.vue @@ -82,8 +82,6 @@ const tabStore = useMultipleTabStore(); const router = useRouter(); const currentRoute = router.currentRoute.value; - const parentRoutePath = localStorage.getItem('parentRoutePath'); - localStorage.removeItem('parentRoutePath'); const fullPath = currentRoute.fullPath; const rQuery = currentRoute.query; const rParams = currentRoute.params; @@ -137,7 +135,7 @@ } function close() { - tabStore.closeTab(currentRoute, router, parentRoutePath); + tabStore.closeTab(currentRoute, router); } async function onApproveClick() { diff --git a/src/views/secondDev/createFlow.vue b/src/views/secondDev/createFlow.vue index 1344d4e..9a84a98 100644 --- a/src/views/secondDev/createFlow.vue +++ b/src/views/secondDev/createFlow.vue @@ -79,9 +79,7 @@ const { t } = useI18n(); const { data, approveUserData, initProcessData, notificationSuccess, notificationError } = userTaskItem(); const currentRoute = router.currentRoute.value; const rParams = currentRoute.params; -const fullPath = currentRoute.fullPath; -const parentRoutePath = localStorage.getItem('parentRoutePath'); -localStorage.removeItem('parentRoutePath'); +const fullPath = currentRoute.fullPath;; const rSchemaId = rParams.arg1; const rDraftsId = rParams.arg2; const taskId = ref(); @@ -125,7 +123,7 @@ function openFlowChart() { } function close() { - tabStore.closeTab(currentRoute, router, parentRoutePath); + tabStore.closeTab(currentRoute, router); } const props = defineProps({ diff --git a/src/views/secondDev/formCreatePage.vue b/src/views/secondDev/formCreatePage.vue index 0ffd861..7c7f4df 100644 --- a/src/views/secondDev/formCreatePage.vue +++ b/src/views/secondDev/formCreatePage.vue @@ -47,8 +47,6 @@ const { currentRoute } = router; const { formPath } = currentRoute.value.query; const pathArr = formPath.split('/'); -const parentRoutePath = localStorage.getItem('parentRoutePath'); -localStorage.removeItem('parentRoutePath'); const tabStore = useMultipleTabStore(); const formProps = ref(null); @@ -93,7 +91,7 @@ async function setFormType() { } function close() { - tabStore.closeTab(currentRoute.value, router, parentRoutePath); + tabStore.closeTab(currentRoute.value, router); } async function handleSubmit() {