From bcfa33822736b761757a2673d977f752cb5c4f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Fri, 13 Aug 2021 15:13:35 +0800 Subject: [PATCH] feat: add `updatePath` for `useTabs` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加更新标签path的方法 close: #1068 --- src/hooks/web/useTabs.ts | 14 +++++++++++--- src/store/modules/multipleTab.ts | 11 +++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/hooks/web/useTabs.ts b/src/hooks/web/useTabs.ts index 68659e5d2..926d90b80 100644 --- a/src/hooks/web/useTabs.ts +++ b/src/hooks/web/useTabs.ts @@ -46,6 +46,15 @@ export function useTabs(_router?: Router) { await tabStore.setTabTitle(title, targetTab); } + async function updateTabPath(path: string, tab?: RouteLocationNormalized) { + const canIUse = canIUseTabs; + if (!canIUse) { + return; + } + const targetTab = tab || getCurrentTab(); + await tabStore.updateTabPath(path, targetTab); + } + async function handleTabAction(action: TableActionEnum, tab?: RouteLocationNormalized) { const canIUse = canIUseTabs; if (!canIUse) { @@ -87,9 +96,8 @@ export function useTabs(_router?: Router) { closeRight: () => handleTabAction(TableActionEnum.CLOSE_RIGHT), closeOther: () => handleTabAction(TableActionEnum.CLOSE_OTHER), closeCurrent: () => handleTabAction(TableActionEnum.CLOSE_CURRENT), - close: (tab?: RouteLocationNormalized) => { - handleTabAction(TableActionEnum.CLOSE, tab); - }, + close: (tab?: RouteLocationNormalized) => handleTabAction(TableActionEnum.CLOSE, tab), setTitle: (title: string, tab?: RouteLocationNormalized) => updateTabTitle(title, tab), + updatePath: (fullPath: string, tab?: RouteLocationNormalized) => updateTabPath(fullPath, tab), }; } diff --git a/src/store/modules/multipleTab.ts b/src/store/modules/multipleTab.ts index 8fbbeeb8e..9ba377881 100644 --- a/src/store/modules/multipleTab.ts +++ b/src/store/modules/multipleTab.ts @@ -300,6 +300,17 @@ export const useMultipleTabStore = defineStore({ await this.updateCacheTab(); } }, + /** + * replace tab's path + * **/ + async updateTabPath(fullPath: string, route: RouteLocationNormalized) { + const findTab = this.getTabList.find((item) => item === route); + if (findTab) { + findTab.fullPath = fullPath; + findTab.path = fullPath; + await this.updateCacheTab(); + } + }, }, });