import React, { Component } from 'react'; import { connect } from 'dva'; import { Route, routerRedux, Switch, Redirect } from 'dva/router'; import { Menu } from 'antd'; import Debounce from 'lodash-decorators/debounce'; import Bind from 'lodash-decorators/bind'; 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, meunMode: 'inline', }; } componentDidMount() { this.resize(); window.addEventListener('resize', this.resize); } componentWillUnmount() { window.removeEventListener('resize', this.resize); } 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, }); }; @Bind() @Debounce(200) resize() { if (window.innerWidth > 768 || window.innerWidth < 454) { this.setState({ meunMode: 'inline', }); return; } this.setState({ meunMode: 'horizontal', }); } 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} /> ))}
); } }