import React, { Component } from 'react'; import { Link } from 'react-router-dom'; import { Layout, Menu, Icon, Dropdown, Avatar, Breadcrumb, LocaleProvider } from 'antd'; import zhCN from 'antd/lib/locale-provider/zh_CN'; import '../style/adminLeft.less'; import { User } from '../stores/user'; import { asyncForm, asyncDelConfirm, asyncSMessage } from '../services/AsyncTools'; const { SubMenu } = Menu; const { Header, Sider } = Layout; const passwordItemList = [ { key: 'password', name: '新密码', type: 'input', placeholder: '请输入新密码', require: true, }, ]; export default class extends Component { constructor(props) { super(props); const { config, moduleMap } = props; const state = { routes: [] }; if (config.group) { state.routes.push({ name: config.group.name, path: moduleMap[config.module.key].groupMap[config.group.key].path, }); } if (config.module && config.group) { if (moduleMap[config.module.key].groupMap[config.group.key].subList.length > 1 || config.showKey) { state.routes.push({ name: config.title, }); } } this.state = state; } render() { const { config } = this.props; return (
{config.module ? this.renderLayoutView() : this.renderContentView(true)}
); } getUserconfigMenu() { return ( { switch (item.key) { case 'password': asyncForm('修改密码', passwordItemList, {}, data => { return User.editPassword(data).then(() => { asyncSMessage('密码修改成功!'); }); }); break; case 'logout': asyncDelConfirm('退出', '是否退出当前帐号?', () => { User.logout().then(() => { asyncSMessage('帐号已退出!'); }); }); break; default: break; } }} > 修改密码 退出登录 ); } getOtherLink() { const { project } = this.props; return ( { toLink(item.key); }} > {project.otherLink.map(link => { return ( {link.title} ); })} ); } renderLayoutView() { const { moduleMap, config, user, project } = this.props; const { collapsed, logo, name, username, openMenu } = user; return ( {config.group && ( linkTo(e.item.props.path)} onOpenChange={keys => !collapsed && User.openMenu(config.module.key, keys)} > {moduleMap[config.module.key].groupList.map(key => { const group = moduleMap[config.module.key].groupMap[key]; const hasSub = group.subList.length > 1; const view = hasSub ? ( {group.name} } > {group.subList.map(k => { const sub = group.subMap[k]; return ( {sub.name || sub.title} ); })} ) : ( {group.name} ); return view; })} )}
User.switchCollapse()} />
{/* */} {project.otherLink && project.otherLink.length > 0 && ( )}
{username}
{this.renderContentView(false)}
); } itemRender(route) { return !route.path ? {route.name} : {route.name}; } renderContentView(free) { const { config, children } = this.props; return (
{!free && !config.free && (
); } }