feat: package api
This commit is contained in:
23
src/app.tsx
23
src/app.tsx
@@ -248,9 +248,9 @@ export function patchClientRoutes({ routes }: { routes: any }) {
|
||||
const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
return menus.flatMap((item) => {
|
||||
let Component: React.ComponentType<any> | null = null;
|
||||
console.log(findFirstLeafRoute(item), "item");
|
||||
if (item.component && item.component.length > 0) {
|
||||
// 防止配置了路由,但本地暂未添加对应的页面,产生的错误
|
||||
console.log(item.component);
|
||||
Component = React.lazy(() => {
|
||||
const importComponent = () => import(`@/pages/${item.component}`);
|
||||
const import404 = () => import("@/pages/404");
|
||||
@@ -265,6 +265,7 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
icon: item.icon,
|
||||
id: item.id,
|
||||
parentId: pId,
|
||||
|
||||
children: [
|
||||
{
|
||||
path: item.url,
|
||||
@@ -275,6 +276,7 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
},
|
||||
];
|
||||
} else {
|
||||
// console.log(findFirstLeafRoute(newItem));
|
||||
return [
|
||||
{
|
||||
path: item.path,
|
||||
@@ -282,6 +284,7 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
icon: item.icon,
|
||||
id: item.menuID,
|
||||
parentId: pId,
|
||||
redirect: "/system/tenant/list",
|
||||
element: (
|
||||
<React.Suspense
|
||||
fallback={<Spin style={{ width: "100%", height: "100%" }} />}
|
||||
@@ -295,3 +298,21 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const findFirstLeafRoute = (menuItem: any, parent = "/"): string | null => {
|
||||
// 如果没有子菜单,返回当前路径
|
||||
|
||||
if (!menuItem.children || menuItem.children.length === 0) {
|
||||
return parent + menuItem.path;
|
||||
}
|
||||
|
||||
// 递归查找第一个叶子节点
|
||||
for (const child of menuItem.children) {
|
||||
const leafRoute = findFirstLeafRoute(child, menuItem.path + "/");
|
||||
if (leafRoute) {
|
||||
return leafRoute;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user