From 9e67929ee786b204358a556119976dd2b79acbbb Mon Sep 17 00:00:00 2001 From: anyup <85225562+anyup@users.noreply.github.com> Date: Sat, 10 May 2025 22:33:31 +0800 Subject: [PATCH] feat: support to refresh the tab page by route name (#6153) Co-authored-by: anyup --- packages/effects/hooks/src/use-tabs.ts | 4 ++-- packages/stores/src/modules/tabbar.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/effects/hooks/src/use-tabs.ts b/packages/effects/hooks/src/use-tabs.ts index 60f70f14..25bc4883 100644 --- a/packages/effects/hooks/src/use-tabs.ts +++ b/packages/effects/hooks/src/use-tabs.ts @@ -41,8 +41,8 @@ export function useTabs() { await tabbarStore.toggleTabPin(tab || route); } - async function refreshTab() { - await tabbarStore.refresh(router); + async function refreshTab(name?: string) { + await tabbarStore.refresh(name || router); } async function openTabInNewWindow(tab?: RouteLocationNormalized) { diff --git a/packages/stores/src/modules/tabbar.ts b/packages/stores/src/modules/tabbar.ts index ec64bdc4..234bb02f 100644 --- a/packages/stores/src/modules/tabbar.ts +++ b/packages/stores/src/modules/tabbar.ts @@ -334,7 +334,13 @@ export const useTabbarStore = defineStore('core-tabbar', { /** * 刷新标签页 */ - async refresh(router: Router) { + async refresh(router: Router | string) { + // 如果是Router路由,那么就根据当前路由刷新 + // 如果是string字符串,为路由名称,则定向刷新指定标签页,不能是当前路由名称,否则不会刷新 + if (typeof router === 'string') { + return await this.refreshByName(router); + } + const { currentRoute } = router; const { name } = currentRoute.value; @@ -349,6 +355,15 @@ export const useTabbarStore = defineStore('core-tabbar', { stopProgress(); }, + /** + * 根据路由名称刷新指定标签页 + */ + async refreshByName(name: string) { + this.excludeCachedTabs.add(name); + await new Promise((resolve) => setTimeout(resolve, 200)); + this.excludeCachedTabs.delete(name); + }, + /** * @zh_CN 重置标签页标题 */