import React, { Component } from 'react'; import { connect } from 'dva'; import { Route, routerRedux, Switch, Redirect } from 'dva/router'; import { Menu } from 'antd'; import styles from './Info.less'; import { getRoutes } from '../../utils/utils'; const { Item } = Menu; const menuMap = { base: '基本设置', safe: '安全设置', account: '账号绑定', message: '新消息通知', }; @connect(({ user }) => ({ currentUser: user.currentUser, })) export default class Info extends Component { constructor(props) { super(props); const { match, location } = props; let key = location.pathname.replace(`${match.path}/`, ''); key = menuMap[key] ? key : 'base'; this.state = { selectKey: key, }; } getmenu = () => { return Object.keys(menuMap).map(item => ( {menuMap[item]} )); }; getRightTitle = () => { return menuMap[this.state.selectKey]; }; selectKey = ({ key }) => { this.props.dispatch(routerRedux.push(`/userinfo/${key}`)); this.setState({ selectKey: key, }); }; render() { const { match, routerData, currentUser } = this.props; if (!currentUser.userid) { return ''; } return (
{this.getmenu()}
{this.getRightTitle()}
{getRoutes(match.path, routerData).map(item => ( ( )} exact={item.exact} /> ))}
); } }