fix(projects): fix active tab switch issue after removal (#723)
This commit is contained in:
parent
a6ecd3e083
commit
a7c59adabc
@ -63,7 +63,7 @@ function handleClose() {
|
|||||||
<slot></slot>
|
<slot></slot>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
<slot name="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>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
</component>
|
</component>
|
||||||
|
@ -10,7 +10,6 @@ import { SetupStoreId } from '@/enum';
|
|||||||
import { useThemeStore } from '../theme';
|
import { useThemeStore } from '../theme';
|
||||||
import {
|
import {
|
||||||
extractTabsByAllRoutes,
|
extractTabsByAllRoutes,
|
||||||
filterTabsById,
|
|
||||||
filterTabsByIds,
|
filterTabsByIds,
|
||||||
findTabByRouteName,
|
findTabByRouteName,
|
||||||
getAllTabs,
|
getAllTabs,
|
||||||
@ -96,23 +95,15 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
* @param tabId Tab id
|
* @param tabId Tab id
|
||||||
*/
|
*/
|
||||||
async function removeTab(tabId: string) {
|
async function removeTab(tabId: string) {
|
||||||
|
const removeTabIndex = tabs.value.findIndex(tab => tab.id === tabId);
|
||||||
|
if (removeTabIndex === -1) return;
|
||||||
|
|
||||||
const isRemoveActiveTab = activeTabId.value === tabId;
|
const isRemoveActiveTab = activeTabId.value === tabId;
|
||||||
const updatedTabs = filterTabsById(tabId, tabs.value);
|
const nextTab = tabs.value[removeTabIndex + 1] || homeTab.value;
|
||||||
|
|
||||||
function update() {
|
tabs.value.splice(removeTabIndex, 1);
|
||||||
tabs.value = updatedTabs;
|
if (isRemoveActiveTab && nextTab) {
|
||||||
}
|
await switchRouteByTab(nextTab);
|
||||||
|
|
||||||
if (!isRemoveActiveTab) {
|
|
||||||
update();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const activeTab = updatedTabs.at(-1) || homeTab.value;
|
|
||||||
|
|
||||||
if (activeTab) {
|
|
||||||
await switchRouteByTab(activeTab);
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user