fix(projects): fix active tab switch issue after removal (#723)

This commit is contained in:
C_7
2025-03-19 22:37:35 +08:00
committed by GitHub
parent a6ecd3e083
commit a7c59adabc
2 changed files with 8 additions and 17 deletions

View File

@ -10,7 +10,6 @@ import { SetupStoreId } from '@/enum';
import { useThemeStore } from '../theme';
import {
extractTabsByAllRoutes,
filterTabsById,
filterTabsByIds,
findTabByRouteName,
getAllTabs,
@ -96,23 +95,15 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
* @param tabId Tab id
*/
async function removeTab(tabId: string) {
const removeTabIndex = tabs.value.findIndex(tab => tab.id === tabId);
if (removeTabIndex === -1) return;
const isRemoveActiveTab = activeTabId.value === tabId;
const updatedTabs = filterTabsById(tabId, tabs.value);
const nextTab = tabs.value[removeTabIndex + 1] || homeTab.value;
function update() {
tabs.value = updatedTabs;
}
if (!isRemoveActiveTab) {
update();
return;
}
const activeTab = updatedTabs.at(-1) || homeTab.value;
if (activeTab) {
await switchRouteByTab(activeTab);
update();
tabs.value.splice(removeTabIndex, 1);
if (isRemoveActiveTab && nextTab) {
await switchRouteByTab(nextTab);
}
}