perf(projects): perf code

This commit is contained in:
Soybean 2024-03-10 14:36:05 +08:00
parent c05e7ff360
commit dc24a36739
3 changed files with 10 additions and 13 deletions

View File

@ -57,14 +57,9 @@ function updateExpandedKeys() {
} }
function handleClickMenu(key: RouteKey) { function handleClickMenu(key: RouteKey) {
const meta = routeStore.getSelectedMenuMetaByKey(key); const { query } = routeStore.getSelectedMenuMetaByKey(key) || {};
if (meta?.fixedQuery) {
routerPushByKey(key, { routerPushByKey(key, { query });
query: meta.fixedQuery
});
return;
}
routerPushByKey(key);
} }
watch( watch(

View File

@ -1,5 +1,5 @@
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import type { RouteMeta, RouteRecordRaw } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { useBoolean } from '@sa/hooks'; import { useBoolean } from '@sa/hooks';
import type { CustomRoute, ElegantConstRoute, LastLevelRouteKey, RouteKey, RouteMap } from '@elegant-router/types'; import type { CustomRoute, ElegantConstRoute, LastLevelRouteKey, RouteKey, RouteMap } from '@elegant-router/types';
@ -278,9 +278,11 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
* *
* @param selectedKey Selected menu key * @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. // 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 { return {

View File

@ -59,7 +59,7 @@ declare module 'vue-router' {
multiTab?: boolean; multiTab?: boolean;
/** If set, the route will be fixed in tabs, and the value is the order of fixed tabs */ /** If set, the route will be fixed in tabs, and the value is the order of fixed tabs */
fixedIndexInTab?: number; fixedIndexInTab?: number;
/** Fixed query parameters that are automatically carried when entering the route */ /** if set query parameters, it will be automatically carried when entering the route */
fixedQuery?: Record<string, string>; query?: Record<string, string>;
} }
} }