Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/materials/src/libs/page-tab/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
23 changes: 7 additions & 16 deletions src/store/modules/tab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { SetupStoreId } from '@/enum';
import { useThemeStore } from '../theme';
import {
extractTabsByAllRoutes,
filterTabsById,
filterTabsByIds,
findTabByRouteName,
getAllTabs,
Expand Down Expand Up @@ -96,23 +95,15 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
* @param tabId Tab id
*/
async function removeTab(tabId: string) {
const isRemoveActiveTab = activeTabId.value === tabId;
const updatedTabs = filterTabsById(tabId, tabs.value);

function update() {
tabs.value = updatedTabs;
}

if (!isRemoveActiveTab) {
update();
return;
}
const removeTabIndex = tabs.value.findIndex(tab => tab.id === tabId);
if (removeTabIndex === -1) return;

const activeTab = updatedTabs.at(-1) || homeTab.value;
const isRemoveActiveTab = activeTabId.value === tabId;
const nextTab = tabs.value[removeTabIndex + 1] || homeTab.value;

if (activeTab) {
await switchRouteByTab(activeTab);
update();
tabs.value.splice(removeTabIndex, 1);
if (isRemoveActiveTab && nextTab) {
await switchRouteByTab(nextTab);
}
}

Expand Down