Info.js 2.14 KB
Newer Older
jim's avatar
jim committed
1
import React, { Component } from 'react';
2 3 4 5
import { connect } from 'dva';
import { Route, routerRedux, Switch, Redirect } from 'dva/router';
import { Menu } from 'antd';
import styles from './Info.less';
ddcat1115's avatar
ddcat1115 committed
6
import { getRoutes } from '../../../utils/utils';
7 8 9 10 11 12 13 14 15 16 17 18 19

const { Item } = Menu;

const menuMap = {
  base: 'ๅŸบๆœฌ่ฎพ็ฝฎ',
  safe: 'ๅฎ‰ๅ…จ่ฎพ็ฝฎ',
  account: '่ดฆๅท็ป‘ๅฎš',
  message: 'ๆ–ฐๆถˆๆฏ้€š็Ÿฅ',
};

@connect(({ user }) => ({
  currentUser: user.currentUser,
}))
jim's avatar
jim committed
20
export default class Info extends Component {
21 22 23 24 25 26 27 28 29 30
  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 = () => {
jim's avatar
jim committed
31 32 33
    return Object.keys(menuMap).map(item => (
      <Item key={item}>{menuMap[item]}</Item>
    ));
34 35 36 37 38
  };
  getRightTitle = () => {
    return menuMap[this.state.selectKey];
  };
  selectKey = ({ key }) => {
ddcat1115's avatar
ddcat1115 committed
39
    this.props.dispatch(routerRedux.push(`/user-profile/userinfo/${key}`));
40 41 42 43 44 45 46 47 48 49 50 51 52
    this.setState({
      selectKey: key,
    });
  };
  render() {
    const { match, routerData, currentUser } = this.props;
    if (!currentUser.userid) {
      return '';
    }
    return (
      <div className={styles.main}>
        <div className={styles.leftmenu}>
          <Menu
53
            mode="inline"
54 55 56 57 58 59 60 61 62
            selectedKeys={[this.state.selectKey]}
            onClick={this.selectKey}
          >
            {this.getmenu()}
          </Menu>
        </div>
        <div className={styles.right}>
          <div className={styles.title}>{this.getRightTitle()}</div>
          <Switch>
jim's avatar
jim committed
63 64 65 66 67 68 69 70 71 72
            {getRoutes(match.path, routerData).map(item => (
              <Route
                key={item.key}
                path={item.path}
                render={props => (
                  <item.component {...props} currentUser={currentUser} />
                )}
                exact={item.exact}
              />
            ))}
ddcat1115's avatar
ddcat1115 committed
73
            <Redirect exact from="/user-profile/userinfo" to="/user-profile/userinfo/base" />
74 75 76 77 78 79 80
            <Redirect to="/exception/404" />
          </Switch>
        </div>
      </div>
    );
  }
}