Skip to content

Commit

Permalink
perf(projects): perf code
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Mar 10, 2024
1 parent c05e7ff commit dc24a36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
11 changes: 3 additions & 8 deletions src/layouts/modules/global-menu/base-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,9 @@ function updateExpandedKeys() {
}
function handleClickMenu(key: RouteKey) {
const meta = routeStore.getSelectedMenuMetaByKey(key);
if (meta?.fixedQuery) {
routerPushByKey(key, {
query: meta.fixedQuery
});
return;
}
routerPushByKey(key);
const { query } = routeStore.getSelectedMenuMetaByKey(key) || {};
routerPushByKey(key, { query });
}
watch(
Expand Down
8 changes: 5 additions & 3 deletions src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, ref } from 'vue';
import type { RouteMeta, RouteRecordRaw } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';
import { defineStore } from 'pinia';
import { useBoolean } from '@sa/hooks';
import type { CustomRoute, ElegantConstRoute, LastLevelRouteKey, RouteKey, RouteMap } from '@elegant-router/types';
Expand Down Expand Up @@ -278,9 +278,11 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
*
* @param selectedKey Selected menu key
*/
function getSelectedMenuMetaByKey(selectedKey: string): RouteMeta | null {
function getSelectedMenuMetaByKey(selectedKey: string) {
// The routes in router.options.routes are static, you need to use router.getRoutes() to get all the routes.
return router.getRoutes().find(route => route.name === selectedKey)?.meta || null;
const allRoutes = router.getRoutes();

return allRoutes.find(route => route.name === selectedKey)?.meta || null;
}

return {
Expand Down
4 changes: 2 additions & 2 deletions src/typings/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ declare module 'vue-router' {
multiTab?: boolean;
/** If set, the route will be fixed in tabs, and the value is the order of fixed tabs */
fixedIndexInTab?: number;
/** Fixed query parameters that are automatically carried when entering the route */
fixedQuery?: Record<string, string>;
/** if set query parameters, it will be automatically carried when entering the route */
query?: Record<string, string>;
}
}

0 comments on commit dc24a36

Please sign in to comment.