feat: nodes list

This commit is contained in:
jialin
2024-05-20 18:13:05 +08:00
parent 313da7a9d2
commit 96e83878d1
13 changed files with 415 additions and 46 deletions
+17 -23
View File
@@ -12,19 +12,19 @@ import {
useAppData,
useLocation,
useNavigate,
type IRoute,
type IRoute
} from '@umijs/max';
import { useMemo } from 'react';
import Exception from './Exception';
import './Layout.css';
import Logo from './Logo';
import { getRightRenderContent } from './rightRender';
import { renderMenuIcon,patchRoutes } from './runtime';
import { patchRoutes } from './runtime';
// 过滤出需要显示的路由, 这里的filterFn 指 不希望显示的层级
const filterRoutes = (
routes: IRoute[],
filterFn: (route: IRoute) => boolean,
filterFn: (route: IRoute) => boolean
) => {
if (routes.length === 0) {
return [];
@@ -78,34 +78,33 @@ export default (props: any) => {
const navigate = useNavigate();
const { clientRoutes, pluginManager } = useAppData();
console.log('pluginManager===========', pluginManager);
const initialInfo = (useModel && useModel('@@initialState')) || {
initialState: undefined,
loading: false,
setInitialState: null,
setInitialState: null
};
const { initialState, loading, setInitialState } = initialInfo;
const userConfig = {
title: '',
layout: 'mix',
layout: 'mix'
};
const formatMessage = undefined;
const runtimeConfig = pluginManager.applyPlugins({
key: 'layout',
type: 'modify',
logout: true,
initialValue: {
...initialInfo,
notFound: <div>not found</div>
},
}
});
console.log(
'clientRoute===========',
clientRoutes,
runtimeConfig,
initialInfo,
initialInfo
);
// 现在的 layout 及 wrapper 实现是通过父路由的形式实现的, 会导致路由数据多了冗余层级, proLayout 消费时, 无法正确展示菜单, 这里对冗余数据进行过滤操作
@@ -116,18 +115,17 @@ export default (props: any) => {
(!!route.isLayout && route.id !== '@@/global-layout') ||
!!route.isWrapper
);
},
}
);
console.log('clientRoutes===========', clientRoutes, newRoutes)
console.log('clientRoutes===========', clientRoutes, newRoutes);
const [route] = useAccessMarkedRoutes(mapRoutes(newRoutes));
patchRoutes({ routes: route?.children || [] });
const matchedRoute = useMemo(
() => matchRoutes(route?.children || [], location.pathname)?.pop?.()?.route,
[location.pathname],
[location.pathname]
);
console.log('route===========', route)
console.log('route===========', route);
return (
<ProLayout
route={route}
@@ -147,7 +145,7 @@ console.log('route===========', route)
menu={{ locale: userConfig.locale }}
logo={Logo}
menuItemRender={(menuItemProps, defaultDom) => {
console.log('meurender=========',{ defaultDom})
console.log('meurender=========', { defaultDom });
if (menuItemProps.isUrl || menuItemProps.children) {
return defaultDom;
}
@@ -158,15 +156,11 @@ console.log('route===========', route)
to={menuItemProps.path.replace('/*', '')}
target={menuItemProps.target}
>
{defaultDom}
{defaultDom}
</Link>
);
}
return (
<>
{defaultDom}
</>
);
return <>{defaultDom}</>;
}}
itemRender={(route, _, routes) => {
const { breadcrumbName, title, path } = route;
@@ -190,7 +184,7 @@ console.log('route===========', route)
runtimeConfig,
loading,
initialState,
setInitialState,
setInitialState
});
if (runtimeConfig.rightContentRender) {
return runtimeConfig.rightContentRender(layoutProps, dom, {
@@ -199,7 +193,7 @@ console.log('route===========', route)
runtimeConfig,
loading,
initialState,
setInitialState,
setInitialState
});
}
return dom;
+7 -9
View File
@@ -1,6 +1,7 @@
// @ts-nocheck
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
import avatarImg from '@/assets/images/avatar.png';
import { LogoutOutlined } from '@ant-design/icons';
import { Avatar, Dropdown, Menu, Spin, version } from 'antd';
@@ -14,7 +15,7 @@ export function getRightRenderContent(opts: {
return opts.runtimeConfig.rightRender(
opts.initialState,
opts.setInitialState,
opts.runtimeConfig,
opts.runtimeConfig
);
}
@@ -32,10 +33,7 @@ export function getRightRenderContent(opts: {
<Avatar
size="small"
className="umi-plugin-layout-avatar"
src={
opts.initialState?.avatar ||
'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
}
src={opts.initialState?.avatar || avatarImg}
alt="avatar"
/>
) : null}
@@ -68,9 +66,9 @@ export function getRightRenderContent(opts: {
),
onClick: () => {
opts?.runtimeConfig?.logout?.(opts.initialState);
},
},
],
}
}
]
};
// antd@5 和 4.24 之后推荐使用 menu,性能更好
let dropdownProps;
@@ -86,7 +84,7 @@ export function getRightRenderContent(opts: {
</Menu.Item>
))}
</Menu>
),
)
};
} else {
// 需要 antd 4.20.0 以上版本