From 66669b7888514068c176df0dedffc91c153a48e2 Mon Sep 17 00:00:00 2001 From: gaoyunqi Date: Mon, 22 Apr 2024 12:34:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=81=E7=A8=8B=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E6=89=93=E5=BC=80=E5=90=8E=EF=BC=8C=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E8=B7=B3=E5=9B=9E=E5=AF=B9=E5=BA=94=E7=9A=84=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/guard/index.ts | 8 ++++++-- src/store/modules/multipleTab.ts | 8 +++++++- src/views/secondDev/approveFlowPage.vue | 4 +++- src/views/secondDev/createFlow.vue | 4 +++- src/views/secondDev/formCreatePage.vue | 4 +++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/router/guard/index.ts b/src/router/guard/index.ts index c567749..9645488 100644 --- a/src/router/guard/index.ts +++ b/src/router/guard/index.ts @@ -32,12 +32,16 @@ export function setupRouterGuard(router: Router) { function createPageGuard(router: Router) { const loadedPageMap = new Map(); - router.beforeEach(async (to) => { + router.beforeEach(async (to, from) => { // The page has already been loaded, it will be faster to open it again, you don’t need to do loading and other processing to.meta.loaded = !!loadedPageMap.get(to.path); // Notify routing changes setRouteChange(to); - + const toPath = to.path; + if (toPath.indexOf('views/secondDev') >= 0 || toPath.indexOf('/viewForm') >= 0) { + // 记录从哪里来的 关闭页面的时候好跳回去 + localStorage.setItem('parentRoutePath', from.path); + } return true; }); diff --git a/src/store/modules/multipleTab.ts b/src/store/modules/multipleTab.ts index f6afbfb..6e6894e 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) { + async closeTab(tab: RouteLocationNormalized, router: Router, backTo: String) { const close = (route: RouteLocationNormalized) => { const { fullPath, meta: { affix } = {} } = route; if (affix) { @@ -207,6 +207,7 @@ export const useMultipleTabStore = defineStore({ let toTarget: RouteLocationRaw = {}; const index = this.tabList.findIndex((item) => item.path === path); + const backToIndex = backTo ? this.tabList.findIndex((item) => item.path === backTo) : -1; // If the current is the leftmost tab if (index === 0) { @@ -224,6 +225,11 @@ export const useMultipleTabStore = defineStore({ const page = this.tabList[index - 1]; toTarget = getToTarget(page); } + + if (backToIndex >= 0) { + const tabPage = this.tabList[backToIndex]; + toTarget = getToTarget(tabPage); + } close(currentRoute.value); await replace(toTarget); }, diff --git a/src/views/secondDev/approveFlowPage.vue b/src/views/secondDev/approveFlowPage.vue index 917f2ee..c37a97b 100644 --- a/src/views/secondDev/approveFlowPage.vue +++ b/src/views/secondDev/approveFlowPage.vue @@ -75,6 +75,8 @@ const { bus, FLOW_PROCESSED } = useEventBus(); 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; @@ -122,7 +124,7 @@ function openFlowChart() { } function close() { - tabStore.closeTab(currentRoute, router); + tabStore.closeTab(currentRoute, router, parentRoutePath); } async function onApproveClick() { diff --git a/src/views/secondDev/createFlow.vue b/src/views/secondDev/createFlow.vue index 85f6315..c29628e 100644 --- a/src/views/secondDev/createFlow.vue +++ b/src/views/secondDev/createFlow.vue @@ -80,6 +80,8 @@ const { data, approveUserData, initProcessData, notificationSuccess, notificatio const currentRoute = router.currentRoute.value; const rParams = currentRoute.params; const fullPath = currentRoute.fullPath; +const parentRoutePath = localStorage.getItem('parentRoutePath'); +localStorage.removeItem('parentRoutePath'); const rSchemaId = rParams.arg1; const rDraftsId = rParams.arg2; const taskId = ref(); @@ -123,7 +125,7 @@ function openFlowChart() { } function close() { - tabStore.closeTab(currentRoute, router); + tabStore.closeTab(currentRoute, router, parentRoutePath); } const props = defineProps({ diff --git a/src/views/secondDev/formCreatePage.vue b/src/views/secondDev/formCreatePage.vue index 02dcf20..900abdd 100644 --- a/src/views/secondDev/formCreatePage.vue +++ b/src/views/secondDev/formCreatePage.vue @@ -41,6 +41,8 @@ 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); @@ -80,7 +82,7 @@ async function setFormType() { } function close() { - tabStore.closeTab(currentRoute.value, router); + tabStore.closeTab(currentRoute.value, router, parentRoutePath); } async function handleSubmit() {