Skip to content

Commit

Permalink
feat(projects): page: support manage_menu more options. close #366
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed May 6, 2024
1 parent ebe55af commit c4b5c65
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 202 deletions.
2 changes: 1 addition & 1 deletion src/layouts/modules/global-menu/base-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function updateExpandedKeys() {
}
function handleClickMenu(key: RouteKey) {
const { query } = routeStore.getSelectedMenuMetaByKey(key) || {};
const query = routeStore.getRouteQueryOfMetaByKey(key);
routerPushByKey(key, { query });
}
Expand Down
5 changes: 2 additions & 3 deletions src/locales/langs/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ const local: App.I18n.Schema = {
menuName: 'Menu Name',
routeName: 'Route Name',
routePath: 'Route Path',
routeParams: 'Route Params',
pathParam: 'Path Param',
layout: 'Layout Component',
page: 'Page Component',
i18nKey: 'I18n Key',
Expand All @@ -377,7 +377,6 @@ const local: App.I18n.Schema = {
activeMenu: 'Active Menu',
multiTab: 'Multi Tab',
fixedIndexInTab: 'Fixed Index In Tab',
roles: 'Roles',
query: 'Query Params',
button: 'Button',
buttonCode: 'Button Code',
Expand All @@ -389,6 +388,7 @@ const local: App.I18n.Schema = {
menuName: 'Please enter menu name',
routeName: 'Please enter route name',
routePath: 'Please enter route path',
pathParam: 'Please enter path param',
page: 'Please select page component',
layout: 'Please select layout component',
i18nKey: 'Please enter i18n key',
Expand All @@ -402,7 +402,6 @@ const local: App.I18n.Schema = {
multiTab: 'Please select whether to support multiple tabs',
fixedInTab: 'Please select whether to fix in the tab',
fixedIndexInTab: 'Please enter the index fixed in the tab',
roles: 'Please select roles',
queryKey: 'Please enter route parameter Key',
queryValue: 'Please enter route parameter Value',
button: 'Please select whether it is a button',
Expand Down
5 changes: 2 additions & 3 deletions src/locales/langs/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ const local: App.I18n.Schema = {
menuName: '菜单名称',
routeName: '路由名称',
routePath: '路由路径',
routeParams: '路由参数',
pathParam: '路径参数',
layout: '布局',
page: '页面组件',
i18nKey: '国际化key',
Expand All @@ -377,7 +377,6 @@ const local: App.I18n.Schema = {
activeMenu: '高亮的菜单',
multiTab: '支持多页签',
fixedIndexInTab: '固定在页签中的序号',
roles: '角色',
query: '路由参数',
button: '按钮',
buttonCode: '按钮编码',
Expand All @@ -389,6 +388,7 @@ const local: App.I18n.Schema = {
menuName: '请输入菜单名称',
routeName: '请输入路由名称',
routePath: '请输入路由路径',
pathParam: '请输入路径参数',
page: '请选择页面组件',
layout: '请选择布局组件',
i18nKey: '请输入国际化key',
Expand All @@ -402,7 +402,6 @@ const local: App.I18n.Schema = {
multiTab: '请选择是否支持多标签',
fixedInTab: '请选择是否固定在页签中',
fixedIndexInTab: '请输入固定在页签中的序号',
roles: '请选择角色',
queryKey: '请输入路由参数Key',
queryValue: '请输入路由参数Value',
button: '请选择是否按钮',
Expand Down
28 changes: 22 additions & 6 deletions src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,31 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
}

/**
* Get selected menu meta by key
* Get route meta by key
*
* @param selectedKey Selected menu key
* @param key Route key
*/
function getSelectedMenuMetaByKey(selectedKey: string) {
// The routes in router.options.routes are static, you need to use router.getRoutes() to get all the routes.
function getRouteMetaByKey(key: string) {
const allRoutes = router.getRoutes();

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

/**
* Get route query of meta by key
*
* @param key
*/
function getRouteQueryOfMetaByKey(key: string) {
const meta = getRouteMetaByKey(key);

const query: Record<string, string> = {};

meta?.query?.forEach(item => {
query[item.key] = item.value;
});

return query;
}

return {
Expand All @@ -360,6 +376,6 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
setIsInitAuthRoute,
getIsAuthRouteExist,
getSelectedMenuKeyPath,
getSelectedMenuMetaByKey
getRouteQueryOfMetaByKey
};
});
64 changes: 19 additions & 45 deletions src/typings/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ declare namespace Api {
*/
type IconType = '1' | '2';

type MenuPropsOfRoute = Pick<
import('vue-router').RouteMeta,
| 'i18nKey'
| 'keepAlive'
| 'constant'
| 'order'
| 'href'
| 'hideInMenu'
| 'activeMenu'
| 'multiTab'
| 'fixedIndexInTab'
| 'query'
>;

type Menu = Common.CommonRecord<{
/** parent menu id */
parentId: number;
Expand All @@ -184,56 +198,16 @@ declare namespace Api {
routePath: string;
/** component */
component?: string;
/**
* i18n key
*
* it is for internationalization
*/
i18nKey?: App.I18n.I18nKey;
/** iconify icon name or local icon name */
icon: string;
/** icon type */
iconType: IconType;
/** menu order */
order: number;
/** whether to cache the route */
keepAlive?: boolean;
/**
* Is constant route
*
* Does not need to login, and the route is defined in the front-end
*/
constant?: boolean;
/** outer link */
href?: string;
/** whether to hide the route in the menu */
hideInMenu?: boolean;
/**
* The menu key will be activated when entering the route
*
* The route is not in the menu
*
* @example
* the route is "user_detail", if it is set to "user_list", the menu "user_list" will be activated
*/
activeMenu?: import('@elegant-router/types').LastLevelRouteKey;
/** By default, the same route path will use one tab, if set to true, it will use multiple tabs */
multiTab?: boolean;
/** If set, the route will be fixed in tabs, and the value is the order of fixed tabs */
fixedIndexInTab?: number | null;
/** if set query parameters, it will be automatically carried when entering the route */
query: Record<string, string>;
/** menu buttons */
buttons?: MenuButton[];
/**
* Roles of the route
*
* Route can be accessed if the current user has at least one of the roles
*/
roles?: string[];
/** buttons */
buttons?: MenuButton[] | null;
/** children menu */
children?: Menu[];
}>;
children?: Menu[] | null;
}> &
MenuPropsOfRoute;

/** menu list */
type MenuList = Common.PaginatingQueryRecord<Menu>;
Expand Down
9 changes: 4 additions & 5 deletions src/typings/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ declare namespace App {
/** The menu label */
label: string;
/** The menu i18n key */
i18nKey?: I18n.I18nKey;
i18nKey?: I18n.I18nKey | null;
/** The route key */
routeKey: RouteKey;
/** The route path */
Expand Down Expand Up @@ -216,7 +216,7 @@ declare namespace App {
*/
localIcon?: string;
/** I18n key */
i18nKey?: I18n.I18nKey;
i18nKey?: I18n.I18nKey | null;
};

/** Form rule */
Expand Down Expand Up @@ -537,7 +537,7 @@ declare namespace App {
menuName: string;
routeName: string;
routePath: string;
routeParams: string;
pathParam: string;
layout: string;
page: string;
i18nKey: string;
Expand All @@ -552,7 +552,6 @@ declare namespace App {
activeMenu: string;
multiTab: string;
fixedIndexInTab: string;
roles: string;
query: string;
button: string;
buttonCode: string;
Expand All @@ -564,6 +563,7 @@ declare namespace App {
menuName: string;
routeName: string;
routePath: string;
pathParam: string;
layout: string;
page: string;
i18nKey: string;
Expand All @@ -577,7 +577,6 @@ declare namespace App {
multiTab: string;
fixedInTab: string;
fixedIndexInTab: string;
roles: string;
queryKey: string;
queryValue: string;
button: string;
Expand Down
20 changes: 11 additions & 9 deletions src/typings/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ declare module 'vue-router' {
*
* It's used in i18n, if it is set, the title will be ignored
*/
i18nKey?: App.I18n.I18nKey;
i18nKey?: App.I18n.I18nKey | null;
/**
* Roles of the route
*
* Route can be accessed if the current user has at least one of the roles
*
* It only works when the route mode is "static", if the route mode is "dynamic", it will be ignored
*/
roles?: string[];
/** Whether to cache the route */
keepAlive?: boolean;
keepAlive?: boolean | null;
/**
* Is constant route
*
* Does not need to login, and the route is defined in the front-end
*/
constant?: boolean;
constant?: boolean | null;
/**
* Iconify icon
*
Expand All @@ -41,11 +43,11 @@ declare module 'vue-router' {
*/
localIcon?: string;
/** Router order */
order?: number;
order?: number | null;
/** The outer link of the route */
href?: string;
href?: string | null;
/** Whether to hide the route in the menu */
hideInMenu?: boolean;
hideInMenu?: boolean | null;
/**
* The menu key will be activated when entering the route
*
Expand All @@ -54,12 +56,12 @@ declare module 'vue-router' {
* @example
* the route is "user_detail", if it is set to "user_list", the menu "user_list" will be activated
*/
activeMenu?: import('@elegant-router/types').RouteKey;
activeMenu?: import('@elegant-router/types').RouteKey | null;
/** By default, the same route path will use one tab, if set to true, it will use multiple tabs */
multiTab?: boolean;
multiTab?: boolean | null;
/** If set, the route will be fixed in tabs, and the value is the order of fixed tabs */
fixedIndexInTab?: number | null;
/** if set query parameters, it will be automatically carried when entering the route */
query?: Record<string, string>;
query?: { key: string; value: string }[] | null;
}
}
Loading

0 comments on commit c4b5c65

Please sign in to comment.