From 4dbd13d48d9f7b170e35d3583ed8b346d6a8139a Mon Sep 17 00:00:00 2001 From: Li Kui <90845831+likui628@users.noreply.github.com> Date: Sat, 6 Jul 2024 10:08:46 +0800 Subject: [PATCH] fix: pin tab not working correct (#23) --- packages/@core/forward/stores/src/modules/tabbar.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/@core/forward/stores/src/modules/tabbar.ts b/packages/@core/forward/stores/src/modules/tabbar.ts index 4d9535b5..04928af9 100644 --- a/packages/@core/forward/stores/src/modules/tabbar.ts +++ b/packages/@core/forward/stores/src/modules/tabbar.ts @@ -143,6 +143,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', { currentTab.params = params || currentTab.params; currentTab.query = query || currentTab.query; currentTab.fullPath = fullPath || currentTab.fullPath; + currentTab.meta = meta || currentTab.meta; this.tabs.splice(tabIndex, 1, currentTab); } this.updateCacheTab(); @@ -285,7 +286,13 @@ const useCoreTabbarStore = defineStore('core-tabbar', { this.tabs[index].meta.affixTab = true; } // TODO: 这里应该把tab从tbs中移除 - this.affixTabs.push(tab as unknown as RouteRecordNormalized); + const affixIndex = this.affixTabs.findIndex( + (item) => this.getTabPath(item) === this.getTabPath(tab), + ); + if (affixIndex === -1) { + tab.meta.affixTab = true; + this.affixTabs.push(tab as unknown as RouteRecordNormalized); + } }, /** * 刷新标签页 @@ -324,6 +331,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', { ); if (index !== -1) { + tab.meta.affixTab = false; this.affixTabs[index].meta.affixTab = false; this.affixTabs.splice(index, 1); this.addTab(tab);