feat(projects): filter tabs which are not in routes
This commit is contained in:
parent
b4f3dd2f7a
commit
f59f34884c
@ -151,7 +151,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
|||||||
await initDynamicAuthRoute();
|
await initDynamicAuthRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
tabStore.initHomeTab(router);
|
tabStore.initHomeTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Init static auth route */
|
/** Init static auth route */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import type { Router } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { useEventListener } from '@vueuse/core';
|
import { useEventListener } from '@vueuse/core';
|
||||||
import { SetupStoreId } from '@/enum';
|
import { SetupStoreId } from '@/enum';
|
||||||
@ -7,6 +7,7 @@ import { useRouterPush } from '@/hooks/common/router';
|
|||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
import { useThemeStore } from '../theme';
|
import { useThemeStore } from '../theme';
|
||||||
import {
|
import {
|
||||||
|
filterTabsByAllRoutes,
|
||||||
filterTabsById,
|
filterTabsById,
|
||||||
filterTabsByIds,
|
filterTabsByIds,
|
||||||
getAllTabs,
|
getAllTabs,
|
||||||
@ -19,6 +20,7 @@ import {
|
|||||||
} from './shared';
|
} from './shared';
|
||||||
|
|
||||||
export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
||||||
|
const router = useRouter();
|
||||||
const themeStore = useThemeStore();
|
const themeStore = useThemeStore();
|
||||||
const { routerPush } = useRouterPush(false);
|
const { routerPush } = useRouterPush(false);
|
||||||
|
|
||||||
@ -28,12 +30,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
/** Get active tab */
|
/** Get active tab */
|
||||||
const homeTab = ref<App.Global.Tab>();
|
const homeTab = ref<App.Global.Tab>();
|
||||||
|
|
||||||
/**
|
/** Init home tab */
|
||||||
* Init home tab
|
function initHomeTab() {
|
||||||
*
|
|
||||||
* @param router Router instance
|
|
||||||
*/
|
|
||||||
function initHomeTab(router: Router) {
|
|
||||||
homeTab.value = getDefaultHomeTab(router);
|
homeTab.value = getDefaultHomeTab(router);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +59,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
const storageTabs = localStg.get('globalTabs');
|
const storageTabs = localStg.get('globalTabs');
|
||||||
|
|
||||||
if (themeStore.tab.cache && storageTabs) {
|
if (themeStore.tab.cache && storageTabs) {
|
||||||
tabs.value = updateTabsByI18nKey(storageTabs);
|
const filteredTabs = filterTabsByAllRoutes(router, storageTabs);
|
||||||
|
tabs.value = updateTabsByI18nKey(filteredTabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
addTab(currentRoute);
|
addTab(currentRoute);
|
||||||
|
@ -126,6 +126,20 @@ export function filterTabsByIds(tabIds: string[], tabs: App.Global.Tab[]) {
|
|||||||
return tabs.filter(tab => !tabIds.includes(tab.id));
|
return tabs.filter(tab => !tabIds.includes(tab.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* filter tabs by all routes
|
||||||
|
*
|
||||||
|
* @param router
|
||||||
|
* @param tabs
|
||||||
|
*/
|
||||||
|
export function filterTabsByAllRoutes(router: Router, tabs: App.Global.Tab[]) {
|
||||||
|
const routes = router.getRoutes();
|
||||||
|
|
||||||
|
const routeNames = routes.map(route => route.name);
|
||||||
|
|
||||||
|
return tabs.filter(tab => routeNames.includes(tab.routeKey));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fixed tabs
|
* Get fixed tabs
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user