feat: support to refresh the tab page by route name (#6153)

Co-authored-by: anyup <anyupxing@163.com>
pull/104/MERGE
anyup 2025-05-10 22:33:31 +08:00 committed by GitHub
parent 90625782c0
commit 9e67929ee7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -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) {

View File

@ -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
*/