From bd5dd2cf28a0943721c397d70c53fe3988a4f81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=92=90?= Date: Wed, 8 Feb 2023 22:29:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(components):=20=E9=A1=B5=E9=9D=A2=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E8=A2=AB=E6=8B=A6=E6=88=AA,=20=E5=88=99=E4=BC=9A?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=20tab=20=E9=A1=B5=E7=AD=BE=E4=B8=8E=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/router.ts | 4 ++-- src/store/modules/tab/index.ts | 30 +++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/composables/router.ts b/src/composables/router.ts index eb488008c..d756aacf1 100644 --- a/src/composables/router.ts +++ b/src/composables/router.ts @@ -19,9 +19,9 @@ export function useRouterPush(inSetup = true) { if (newTab) { const routerData = router.resolve(to); window.open(routerData.href, '_blank'); - } else { - router.push(to); + return Promise.resolve(); } + return router.push(to); } /** 返回上一级路由 */ diff --git a/src/store/modules/tab/index.ts b/src/store/modules/tab/index.ts index ed3df8f5d..c39d9fd3c 100644 --- a/src/store/modules/tab/index.ts +++ b/src/store/modules/tab/index.ts @@ -114,34 +114,42 @@ export const useTabStore = defineStore('tab-store', { * 删除多页签 * @param fullPath - 路由fullPath */ - removeTab(fullPath: string) { + async removeTab(fullPath: string) { const { routerPush } = useRouterPush(false); const isActive = this.activeTab === fullPath; const updateTabs = this.tabs.filter(tab => tab.fullPath !== fullPath); - this.tabs = updateTabs; + if (!isActive) { + this.tabs = updateTabs; + } if (isActive && updateTabs.length) { const activePath = updateTabs[updateTabs.length - 1].fullPath; - this.setActiveTab(activePath); - routerPush(activePath); + const navigationFailure = await routerPush(activePath); + if (!navigationFailure) { + this.tabs = updateTabs; + this.setActiveTab(activePath); + } } }, /** * 清空多页签(多页签首页保留) * @param excludes - 保留的多页签path */ - clearTab(excludes: string[] = []) { + async clearTab(excludes: string[] = []) { const { routerPush } = useRouterPush(false); const homePath = this.homeTab.fullPath; const remain = [homePath, ...excludes]; const hasActive = remain.includes(this.activeTab); const updateTabs = this.tabs.filter(tab => remain.includes(tab.fullPath)); - this.tabs = updateTabs; + if (hasActive) this.tabs = updateTabs; if (!hasActive && updateTabs.length) { const activePath = updateTabs[updateTabs.length - 1].fullPath; - this.setActiveTab(activePath); - routerPush(activePath); + const navigationFailure = await routerPush(activePath); + if (!navigationFailure) { + this.tabs = updateTabs; + this.setActiveTab(activePath); + } } }, /** @@ -174,13 +182,13 @@ export const useTabStore = defineStore('tab-store', { * 点击单个tab * @param fullPath - 路由fullPath */ - handleClickTab(fullPath: string) { + async handleClickTab(fullPath: string) { const { routerPush } = useRouterPush(false); const isActive = this.activeTab === fullPath; if (!isActive) { - this.setActiveTab(fullPath); - routerPush(fullPath); + const navigationFailure = await routerPush(fullPath); + if (!navigationFailure) this.setActiveTab(fullPath); } }, /**