Commit 9e67929e by anyup Committed by GitHub

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

Co-authored-by: anyup <anyupxing@163.com>
1 parent 90625782
...@@ -41,8 +41,8 @@ export function useTabs() { ...@@ -41,8 +41,8 @@ export function useTabs() {
await tabbarStore.toggleTabPin(tab || route); await tabbarStore.toggleTabPin(tab || route);
} }
async function refreshTab() { async function refreshTab(name?: string) {
await tabbarStore.refresh(router); await tabbarStore.refresh(name || router);
} }
async function openTabInNewWindow(tab?: RouteLocationNormalized) { async function openTabInNewWindow(tab?: RouteLocationNormalized) {
......
...@@ -334,7 +334,13 @@ export const useTabbarStore = defineStore('core-tabbar', { ...@@ -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 { currentRoute } = router;
const { name } = currentRoute.value; const { name } = currentRoute.value;
...@@ -350,6 +356,15 @@ export const useTabbarStore = defineStore('core-tabbar', { ...@@ -350,6 +356,15 @@ export const useTabbarStore = defineStore('core-tabbar', {
}, },
/** /**
* 根据路由名称刷新指定标签页
*/
async refreshByName(name: string) {
this.excludeCachedTabs.add(name);
await new Promise((resolve) => setTimeout(resolve, 200));
this.excludeCachedTabs.delete(name);
},
/**
* @zh_CN 重置标签页标题 * @zh_CN 重置标签页标题
*/ */
async resetTabTitle(tab: TabDefinition) { async resetTabTitle(tab: TabDefinition) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!