From 7ac2a6ce2dda98a02713fcc140a83e0139b84cbf Mon Sep 17 00:00:00 2001 From: wenyuan <49969025+wenyuanw@users.noreply.github.com> Date: Mon, 9 Jun 2025 13:48:48 +0800 Subject: [PATCH] optimize(projects): optimize tab deletion logic --- src/store/modules/tab/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/store/modules/tab/index.ts b/src/store/modules/tab/index.ts index 2e067557..bde91248 100644 --- a/src/store/modules/tab/index.ts +++ b/src/store/modules/tab/index.ts @@ -100,7 +100,12 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => { const removedTabRouteKey = tabs.value[removeTabIndex].routeKey; const isRemoveActiveTab = activeTabId.value === tabId; - const nextTab = tabs.value[removeTabIndex + 1] || homeTab.value; + + // if remove the last tab, then switch to the second last tab + const isLastTab = removeTabIndex === tabs.value.length - 1; + const nextTab = isLastTab + ? tabs.value[removeTabIndex - 1] || homeTab.value + : tabs.value[removeTabIndex + 1] || homeTab.value; // remove tab tabs.value.splice(removeTabIndex, 1);