mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 04:29:21 +08:00
update: 升级vben5.5.9到5.7.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vben/utils",
|
||||
"version": "5.5.9",
|
||||
"version": "5.7.0",
|
||||
"homepage": "https://github.com/vbenjs/vue-vben-admin",
|
||||
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
||||
"repository": {
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
RouteMeta,
|
||||
} from '@vben-core/typings';
|
||||
|
||||
import { filterTree, mapTree } from '@vben-core/shared/utils';
|
||||
import { filterTree, mapTree, sortTree } from '@vben-core/shared/utils';
|
||||
|
||||
/**
|
||||
* 根据 routes 生成菜单列表
|
||||
@@ -43,6 +43,7 @@ function generateMenus(
|
||||
link,
|
||||
order,
|
||||
title = '',
|
||||
query,
|
||||
} = meta;
|
||||
|
||||
// 确保菜单名称不为空
|
||||
@@ -71,6 +72,7 @@ function generateMenus(
|
||||
badgeVariants,
|
||||
icon,
|
||||
name,
|
||||
query,
|
||||
order,
|
||||
parent: route.parent,
|
||||
parents: route.parents,
|
||||
@@ -81,7 +83,7 @@ function generateMenus(
|
||||
});
|
||||
|
||||
// 对菜单进行排序,避免order=0时被替换成999的问题
|
||||
menus = menus.sort((a, b) => (a?.order ?? 999) - (b?.order ?? 999));
|
||||
menus = sortTree(menus, (a, b) => (a?.order ?? 999) - (b?.order ?? 999));
|
||||
|
||||
// 过滤掉隐藏的菜单项
|
||||
return filterTree(menus, (menu) => !!menu.show);
|
||||
|
||||
@@ -8,13 +8,26 @@ import type {
|
||||
|
||||
import { mapTree } from '@vben-core/shared/utils';
|
||||
|
||||
/**
|
||||
* 判断路由是否在菜单中显示但访问时展示 403(让用户知悉功能并申请权限)
|
||||
*/
|
||||
function menuHasVisibleWithForbidden(route: RouteRecordRaw): boolean {
|
||||
return !!route.meta?.menuVisibleWithForbidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态生成路由 - 后端方式
|
||||
* 对 meta.menuVisibleWithForbidden 为 true 的项直接替换为 403 组件,让用户知悉功能并申请权限。
|
||||
*/
|
||||
async function generateRoutesByBackend(
|
||||
options: GenerateMenuAndRoutesOptions,
|
||||
): Promise<RouteRecordRaw[]> {
|
||||
const { fetchMenuListAsync, layoutMap = {}, pageMap = {} } = options;
|
||||
const {
|
||||
fetchMenuListAsync,
|
||||
layoutMap = {},
|
||||
pageMap = {},
|
||||
forbiddenComponent,
|
||||
} = options;
|
||||
|
||||
try {
|
||||
const menuRoutes = await fetchMenuListAsync?.();
|
||||
@@ -28,7 +41,16 @@ async function generateRoutesByBackend(
|
||||
normalizePageMap[normalizeViewPath(key)] = value;
|
||||
}
|
||||
|
||||
const routes = convertRoutes(menuRoutes, layoutMap, normalizePageMap);
|
||||
let routes = convertRoutes(menuRoutes, layoutMap, normalizePageMap);
|
||||
|
||||
if (forbiddenComponent) {
|
||||
routes = mapTree(routes, (route) => {
|
||||
if (menuHasVisibleWithForbidden(route)) {
|
||||
route.component = forbiddenComponent;
|
||||
}
|
||||
return route;
|
||||
});
|
||||
}
|
||||
|
||||
return routes;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user