feat: new page

This commit is contained in:
2026-01-21 15:07:11 +08:00
parent 607b292f36
commit 502c236b0d
31 changed files with 2730 additions and 186 deletions

View File

@@ -116,3 +116,56 @@ export const loopMenuItem = (menus: MenuVO[], pId: number | string): any[] => {
// return currentPath;
// }
// }
// src/utils/route.ts
import { lazy } from 'react';
export interface RouteItem {
id: number;
parentId: number;
name: string;
path: string;
component: string | null;
componentName: string;
icon: string;
visible: boolean;
keepAlive: boolean;
alwaysShow: boolean;
children: RouteItem[] | null;
}
/**
* 转换后端路由数据为 Ant Design Pro 路由格式
*/
export function transformRoutes(routes: MenuVO[]): any[] {
return routes
.filter((route) => route.visible) // 只显示可见路由
.map((route) => {
const routeConfig: any = {
path: route.path,
name: route.name,
icon: route.icon || undefined,
};
// 处理组件
if (route.component) {
routeConfig.component = lazy(
() =>
import(`@/pages/${route.component}`).catch(
() => import('@/pages/404'),
), // 组件不存在时显示404
);
}
// 处理子路由
if (route.children && route.children.length > 0) {
routeConfig.routes = transformRoutes(route.children);
}
// 隐藏菜单但保留路由
if (!route.visible) {
routeConfig.hideInMenu = true;
}
return routeConfig;
});
}