菜单与 审核按钮,登录新用户修改密码
This commit is contained in:
@ -4,7 +4,7 @@ import ProLayout, { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Link, useLocation, useIntl } from 'umi';
|
||||
import { connect } from 'dva';
|
||||
import defaultSettings from '../../config/defaultSettings';
|
||||
import routes from '../../config/router.config';
|
||||
import routes from '../../config/router.config';
|
||||
import { ConfigProvider, Breadcrumb } from 'antd';
|
||||
import HeaderComponent from './Header';
|
||||
import IconFont from '@/components/IconFont/IconFont';
|
||||
@ -19,14 +19,14 @@ const MenuRender = (item: any, isSubMenu: boolean) => {
|
||||
<span className="ant-pro-menu-item">
|
||||
<IconFont type={item.icon as string} />
|
||||
<span className="ant-pro-menu-item-title">
|
||||
{intl.formatMessage({ id: `${item.name}` || '' })}
|
||||
{intl.formatMessage({ id: `menu.${item.name}` || '' })}
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
<Link className="ant-pro-menu-item" key={item.path} to={item.path || '/'} innerRef={null}>
|
||||
<IconFont type={item.icon as string} />
|
||||
<span className="ant-pro-menu-item-title">
|
||||
{intl.formatMessage({ id: `${item.name}` || '' })}
|
||||
{intl.formatMessage({ id: `menu.${item.name}` || '' })}
|
||||
</span>
|
||||
</Link>
|
||||
)}
|
||||
@ -77,8 +77,8 @@ function convertMenuData(menus: any[]): any[] {
|
||||
const icon = item.icon || undefined;
|
||||
// 递归 children->routes
|
||||
let routes;
|
||||
if (item.children && item.children.length > 0) {
|
||||
routes = convertMenuData(item.children);
|
||||
if (item.routes && item.routes.length > 0) {
|
||||
routes = convertMenuData(item.routes);
|
||||
}
|
||||
// 国际化优先找 menu.name,否则直接显示 name
|
||||
return {
|
||||
@ -90,6 +90,43 @@ function convertMenuData(menus: any[]): any[] {
|
||||
});
|
||||
}
|
||||
|
||||
// 新增递归过滤函数
|
||||
function filterMenusByLocalConfig(localMenus: any[], remoteMenus: any[]): any[] {
|
||||
if (!Array.isArray(localMenus) || !Array.isArray(remoteMenus)) return [];
|
||||
// remoteMenus 可能有 children 字段,也可能有 routes 字段
|
||||
const remoteMap = new Map();
|
||||
remoteMenus.forEach(r => {
|
||||
if (r.path) remoteMap.set(r.path, r);
|
||||
});
|
||||
|
||||
// filter 和 map 后的结果直接 return
|
||||
localMenus
|
||||
.filter(local => local.path && remoteMap.has(local.path))
|
||||
.map(local => {
|
||||
const remote = remoteMap.get(local.path);
|
||||
// 兼容 children 或 routes 字段
|
||||
const localChildren = local.children || local.routes;
|
||||
const remoteChildren = remote.children || remote.routes;
|
||||
let newChildren: any[] = [];
|
||||
if (
|
||||
localChildren && localChildren.length > 0 &&
|
||||
remoteChildren && remoteChildren.length > 0
|
||||
) {
|
||||
newChildren = filterMenusByLocalConfig(localChildren, remoteChildren);
|
||||
}
|
||||
// 保留原有结构,只替换 children 或 routes
|
||||
let node = { ...local };
|
||||
if (local.children) {
|
||||
node.children = newChildren;
|
||||
} else if (local.routes) {
|
||||
node.routes = newChildren;
|
||||
}
|
||||
return node;
|
||||
});
|
||||
|
||||
return localMenus
|
||||
}
|
||||
|
||||
|
||||
const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
|
||||
const { children, tab, dispatch } = props;
|
||||
@ -118,7 +155,8 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
|
||||
const menuStr = sessionStorage.getItem('menuList');
|
||||
if (menuStr) {
|
||||
const menus = JSON.parse(menuStr);
|
||||
setMenuRoutes(convertMenuData(menus));
|
||||
const filteredMenus = filterMenusByLocalConfig(routes, menus);
|
||||
setMenuRoutes(convertMenuData(filteredMenus));
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
Reference in New Issue
Block a user