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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 17 deletions

View File

@ -63,7 +63,7 @@ function handleClose() {
<slot></slot>
<template #suffix>
<slot name="suffix">
<SvgClose v-if="closable" :class="[style['svg-close']]" @click.stop="handleClose" />
<SvgClose v-if="closable" :class="[style['svg-close']]" @pointerdown.stop="handleClose" />
</slot>
</template>
</component>

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);
}
}