From a7c59adabce5d091a6ffbeb10309d43ae9e293c0 Mon Sep 17 00:00:00 2001 From: C_7 <53211941+me-o@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:37:35 +0800 Subject: [PATCH] fix(projects): fix active tab switch issue after removal (#723) --- .../materials/src/libs/page-tab/index.vue | 2 +- src/store/modules/tab/index.ts | 23 ++++++------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/packages/materials/src/libs/page-tab/index.vue b/packages/materials/src/libs/page-tab/index.vue index 0c0c6995..8c7b98d2 100644 --- a/packages/materials/src/libs/page-tab/index.vue +++ b/packages/materials/src/libs/page-tab/index.vue @@ -63,7 +63,7 @@ function handleClose() { diff --git a/src/store/modules/tab/index.ts b/src/store/modules/tab/index.ts index 730abe05..e6fe927c 100644 --- a/src/store/modules/tab/index.ts +++ b/src/store/modules/tab/index.ts @@ -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); } }