|
|
@@ -77,62 +77,98 @@ export default class SiderMenu extends PureComponent {
|
|
|
return itemRegExp.test(path.replace(/^\//, '').replace(/\/$/, ''));
|
|
|
});
|
|
|
}
|
|
|
- getNavMenuItems(menusData) {
|
|
|
+ /**
|
|
|
+ * 判断是否是http链接.返回 Link 或 a
|
|
|
+ * Judge whether it is http link.return a or Link
|
|
|
+ * @memberof SiderMenu
|
|
|
+ */
|
|
|
+ getMenuItemPath = (item) => {
|
|
|
+ const itemPath = this.conversionPath(item.path);
|
|
|
+ const icon = getIcon(item.icon);
|
|
|
+ const { target, name } = item;
|
|
|
+ // Is it a http link
|
|
|
+ if (/^https?:\/\//.test(itemPath)) {
|
|
|
+ return (
|
|
|
+ <a href={itemPath} target={target}>
|
|
|
+ {icon}<span>{name}</span>
|
|
|
+ </a>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <Link
|
|
|
+ to={itemPath}
|
|
|
+ target={target}
|
|
|
+ replace={itemPath === this.props.location.pathname}
|
|
|
+ onClick={this.props.isMobile ? () => { this.props.onCollapse(true); } : undefined}
|
|
|
+ >
|
|
|
+ {icon}<span>{name}</span>
|
|
|
+ </Link>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * get SubMenu or Item
|
|
|
+ */
|
|
|
+ getSubMenuOrItem=(item) => {
|
|
|
+ if (item.children && item.children.some(child => child.name)) {
|
|
|
+ return (
|
|
|
+ <SubMenu
|
|
|
+ title={
|
|
|
+ item.icon ? (
|
|
|
+ <span>
|
|
|
+ {getIcon(item.icon)}
|
|
|
+ <span>{item.name}</span>
|
|
|
+ </span>
|
|
|
+ ) : item.name
|
|
|
+ }
|
|
|
+ key={item.key || item.path}
|
|
|
+ >
|
|
|
+ {this.getNavMenuItems(item.children)}
|
|
|
+ </SubMenu>
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return (
|
|
|
+ <Menu.Item key={item.key || item.path}>
|
|
|
+ {this.getMenuItemPath(item)}
|
|
|
+ </Menu.Item>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获得菜单子节点
|
|
|
+ * @memberof SiderMenu
|
|
|
+ */
|
|
|
+ getNavMenuItems = (menusData) => {
|
|
|
if (!menusData) {
|
|
|
return [];
|
|
|
}
|
|
|
return menusData.map((item) => {
|
|
|
- if (!item.name) {
|
|
|
+ if (!item.name || item.hideInMenu) {
|
|
|
return null;
|
|
|
}
|
|
|
- let itemPath;
|
|
|
- if (item.path && item.path.indexOf('http') === 0) {
|
|
|
- itemPath = item.path;
|
|
|
- } else {
|
|
|
- itemPath = `/${item.path || ''}`.replace(/\/+/g, '/');
|
|
|
- }
|
|
|
- if (item.children && item.children.some(child => child.name)) {
|
|
|
- return item.hideInMenu ? null :
|
|
|
- (
|
|
|
- <SubMenu
|
|
|
- title={
|
|
|
- item.icon ? (
|
|
|
- <span>
|
|
|
- {getIcon(item.icon)}
|
|
|
- <span>{item.name}</span>
|
|
|
- </span>
|
|
|
- ) : item.name
|
|
|
- }
|
|
|
- key={item.key || item.path}
|
|
|
- >
|
|
|
- {this.getNavMenuItems(item.children)}
|
|
|
- </SubMenu>
|
|
|
- );
|
|
|
- }
|
|
|
- const icon = getIcon(item.icon);
|
|
|
- return item.hideInMenu ? null :
|
|
|
- (
|
|
|
- <Menu.Item key={item.key || item.path}>
|
|
|
- {
|
|
|
- /^https?:\/\//.test(itemPath) ? (
|
|
|
- <a href={itemPath} target={item.target}>
|
|
|
- {icon}<span>{item.name}</span>
|
|
|
- </a>
|
|
|
- ) : (
|
|
|
- <Link
|
|
|
- to={itemPath}
|
|
|
- target={item.target}
|
|
|
- replace={itemPath === this.props.location.pathname}
|
|
|
- onClick={this.props.isMobile ? () => { this.props.onCollapse(true); } : undefined}
|
|
|
- >
|
|
|
- {icon}<span>{item.name}</span>
|
|
|
- </Link>
|
|
|
- )
|
|
|
- }
|
|
|
- </Menu.Item>
|
|
|
- );
|
|
|
+ const ItemDom = this.getSubMenuOrItem(item);
|
|
|
+ return this.checkPermissionItem(item.authority, ItemDom);
|
|
|
});
|
|
|
}
|
|
|
+ // conversion Path
|
|
|
+ // 转化路径
|
|
|
+ conversionPath=(path) => {
|
|
|
+ if (path && path.indexOf('http') === 0) {
|
|
|
+ return path;
|
|
|
+ } else {
|
|
|
+ return `/${path || ''}`.replace(/\/+/g, '/');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // permission to check
|
|
|
+ checkPermissionItem = (authority, ItemDom) => {
|
|
|
+ if (this.props.Authorized && this.props.Authorized.check) {
|
|
|
+ const { check } = this.props.Authorized;
|
|
|
+ return check(
|
|
|
+ authority,
|
|
|
+ ItemDom
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return ItemDom;
|
|
|
+ }
|
|
|
handleOpenChange = (openKeys) => {
|
|
|
const lastOpenKey = openKeys[openKeys.length - 1];
|
|
|
const isMainMenu = this.menus.some(
|