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';
import GridContent from '../../../layouts/GridContent';
const { Item } = Menu;
const menuMap = {
base: '基本设置',
security: '安全设置',
binding: '账号绑定',
notification: '新消息通知',
};
@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,
mode: 'inline',
};
}
componentDidMount() {
window.addEventListener('resize', this.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(`/account/settings/${key}`));
this.setState({
selectKey: key,
});
};
resize = () => {
if (!this.main) {
return;
}
let mode = 'inline';
const { offsetWidth } = this.main;
if (this.main.offsetWidth < 641 && offsetWidth > 400) {
mode = 'horizontal';
}
if (window.innerWidth < 768 && offsetWidth > 400) {
mode = 'horizontal';
}
this.setState({
mode,
});
};
render() {
const { match, routerData, currentUser } = this.props;
if (!currentUser.userid) {
return '';
}
return (
{
this.main = ref;
}}
>
{this.getRightTitle()}
{getRoutes(match.path, routerData).map(item => (
(
)}
exact={item.exact}
/>
))}
);
}
}