fix: pin tab not working correct (#23)

pull/48/MERGE
Li Kui 2024-07-06 10:08:46 +08:00 committed by GitHub
parent a60467b01c
commit 4dbd13d48d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 1 deletions

View File

@ -143,6 +143,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
currentTab.params = params || currentTab.params; currentTab.params = params || currentTab.params;
currentTab.query = query || currentTab.query; currentTab.query = query || currentTab.query;
currentTab.fullPath = fullPath || currentTab.fullPath; currentTab.fullPath = fullPath || currentTab.fullPath;
currentTab.meta = meta || currentTab.meta;
this.tabs.splice(tabIndex, 1, currentTab); this.tabs.splice(tabIndex, 1, currentTab);
} }
this.updateCacheTab(); this.updateCacheTab();
@ -285,7 +286,13 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
this.tabs[index].meta.affixTab = true; this.tabs[index].meta.affixTab = true;
} }
// TODO: 这里应该把tab从tbs中移除 // 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) { if (index !== -1) {
tab.meta.affixTab = false;
this.affixTabs[index].meta.affixTab = false; this.affixTabs[index].meta.affixTab = false;
this.affixTabs.splice(index, 1); this.affixTabs.splice(index, 1);
this.addTab(tab); this.addTab(tab);