/* eslint-disable */
|
/**柯礼钦
|
* 4/2/2020, 11:22:51 AM
|
* doc comment for the file goes here
|
*/
|
|
/** 菜单组件 */
|
|
import React from 'react';
|
import { Spin, Layout, Menu, Icon } from 'antd';
|
import MenView from '../../components/common/MenuView';
|
import { menus, getMenuListByPermission } from '../../menu';
|
import fetch from '../../api/request';
|
|
const { Sider } = Layout;
|
|
function find(data, pathname) {
|
for (const { path, children } of data) {
|
if (path === pathname) return path;
|
if (children) {
|
const result = find(children, pathname);
|
if (result) return result;
|
}
|
}
|
return null;
|
}
|
|
function selected(data, pathname) {
|
if (!pathname || pathname === '/') return pathname;
|
return find(data, pathname) || selected(data, pathname.split('/').slice(0, -1).join('/'));
|
}
|
|
export default class MenuView extends React.Component {
|
constructor(props) {
|
super(props);
|
this.state = {
|
collapsed: true,
|
data: []
|
};
|
}
|
|
componentWillMount() {
|
// 获取从登录页面记录在缓存里的菜单数据
|
let menu = window.localStorage.getItem('menu') ? JSON.parse(window.localStorage.getItem('menu')) : [];
|
let permList = menu && menu.map(({ symbol }) => (symbol)).concat(menu.map(({ moduleSymbol }) => (moduleSymbol))).reduce((p, n) => {
|
if (p.indexOf(n) == -1) {
|
return p.concat(n)
|
} else {
|
return p
|
}
|
}, []);
|
// console.log(getMenuListByPermission(menus, permList) )
|
this.setState({ data: getMenuListByPermission(menus, permList) });
|
}
|
componentDidMount() { }
|
|
onCollapse = collapsed => {
|
this.setState({ collapsed });
|
}
|
|
render() {
|
const { data, collapsed } = this.state;
|
const pathname = selected(data, this.props.location.pathname);
|
return (
|
<Sider
|
onCollapse={this.onCollapse}
|
collapsed={collapsed}
|
breakpoint="lg"
|
collapsible={true}
|
>
|
<MenView
|
history={this.props.history}
|
pathname={pathname}
|
key={data.length}
|
menudata={data}
|
/>
|
</Sider>
|
);
|
}
|
|
}
|