Skip to content

Commit

Permalink
feat(projects): filter tabs which are not in routes
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jan 20, 2024
1 parent b4f3dd2 commit f59f348
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
await initDynamicAuthRoute();
}

tabStore.initHomeTab(router);
tabStore.initHomeTab();
}

/** Init static auth route */
Expand Down
15 changes: 7 additions & 8 deletions src/store/modules/tab/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { computed, ref } from 'vue';
import type { Router } from 'vue-router';
import { useRouter } from 'vue-router';
import { defineStore } from 'pinia';
import { useEventListener } from '@vueuse/core';
import { SetupStoreId } from '@/enum';
import { useRouterPush } from '@/hooks/common/router';
import { localStg } from '@/utils/storage';
import { useThemeStore } from '../theme';
import {
filterTabsByAllRoutes,
filterTabsById,
filterTabsByIds,
getAllTabs,
Expand All @@ -19,6 +20,7 @@ import {
} from './shared';

export const useTabStore = defineStore(SetupStoreId.Tab, () => {
const router = useRouter();
const themeStore = useThemeStore();
const { routerPush } = useRouterPush(false);

Expand All @@ -28,12 +30,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
/** Get active tab */
const homeTab = ref<App.Global.Tab>();

/**
* Init home tab
*
* @param router Router instance
*/
function initHomeTab(router: Router) {
/** Init home tab */
function initHomeTab() {
homeTab.value = getDefaultHomeTab(router);
}

Expand Down Expand Up @@ -61,7 +59,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
const storageTabs = localStg.get('globalTabs');

if (themeStore.tab.cache && storageTabs) {
tabs.value = updateTabsByI18nKey(storageTabs);
const filteredTabs = filterTabsByAllRoutes(router, storageTabs);
tabs.value = updateTabsByI18nKey(filteredTabs);
}

addTab(currentRoute);
Expand Down
14 changes: 14 additions & 0 deletions src/store/modules/tab/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ export function filterTabsByIds(tabIds: string[], tabs: App.Global.Tab[]) {
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
*
Expand Down

1 comment on commit f59f348

@vercel
Copy link

@vercel vercel bot commented on f59f348 Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

soybean-admin – ./

soybean-admin-git-main-soybeanjs.vercel.app
soybean-admin-eta.vercel.app
soybean-admin-soybeanjs.vercel.app

Please sign in to comment.