Commit 996f9e55 authored by jim's avatar jim

Enhanced meun response

parent 7c0550f1
import React, { PureComponent } from 'react'; import React, { Component } from 'react';
import { connect } from 'dva'; import { connect } from 'dva';
import { Route, routerRedux, Switch, Redirect } from 'dva/router'; import { Route, routerRedux, Switch, Redirect } from 'dva/router';
import { Menu } from 'antd'; import { Menu } from 'antd';
import Debounce from 'lodash-decorators/debounce';
import Bind from 'lodash-decorators/bind';
import styles from './Info.less'; import styles from './Info.less';
import { getRoutes } from '../../utils/utils'; import { getRoutes } from '../../utils/utils';
...@@ -17,7 +19,7 @@ const menuMap = { ...@@ -17,7 +19,7 @@ const menuMap = {
@connect(({ user }) => ({ @connect(({ user }) => ({
currentUser: user.currentUser, currentUser: user.currentUser,
})) }))
export default class Info extends PureComponent { export default class Info extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
const { match, location } = props; const { match, location } = props;
...@@ -25,10 +27,20 @@ export default class Info extends PureComponent { ...@@ -25,10 +27,20 @@ export default class Info extends PureComponent {
key = menuMap[key] ? key : 'base'; key = menuMap[key] ? key : 'base';
this.state = { this.state = {
selectKey: key, selectKey: key,
meunMode: 'inline',
}; };
} }
componentDidMount() {
this.resize();
window.addEventListener('resize', this.resize);
}
componentWillUnmount() {
window.removeEventListener('resize', this.resize);
}
getmenu = () => { getmenu = () => {
return Object.keys(menuMap).map(item => <Item key={item}>{menuMap[item]}</Item>); return Object.keys(menuMap).map(item => (
<Item key={item}>{menuMap[item]}</Item>
));
}; };
getRightTitle = () => { getRightTitle = () => {
return menuMap[this.state.selectKey]; return menuMap[this.state.selectKey];
...@@ -39,6 +51,19 @@ export default class Info extends PureComponent { ...@@ -39,6 +51,19 @@ export default class Info extends PureComponent {
selectKey: key, selectKey: key,
}); });
}; };
@Bind()
@Debounce(200)
resize() {
if (window.innerWidth > 768 || window.innerWidth < 454) {
this.setState({
meunMode: 'inline',
});
return;
}
this.setState({
meunMode: 'horizontal',
});
}
render() { render() {
const { match, routerData, currentUser } = this.props; const { match, routerData, currentUser } = this.props;
if (!currentUser.userid) { if (!currentUser.userid) {
...@@ -48,7 +73,7 @@ export default class Info extends PureComponent { ...@@ -48,7 +73,7 @@ export default class Info extends PureComponent {
<div className={styles.main}> <div className={styles.main}>
<div className={styles.leftmenu}> <div className={styles.leftmenu}>
<Menu <Menu
mode={window.innerWidth < 769 ? 'horizontal' : 'inline'} mode={this.state.meunMode}
selectedKeys={[this.state.selectKey]} selectedKeys={[this.state.selectKey]}
onClick={this.selectKey} onClick={this.selectKey}
> >
...@@ -58,16 +83,16 @@ export default class Info extends PureComponent { ...@@ -58,16 +83,16 @@ export default class Info extends PureComponent {
<div className={styles.right}> <div className={styles.right}>
<div className={styles.title}>{this.getRightTitle()}</div> <div className={styles.title}>{this.getRightTitle()}</div>
<Switch> <Switch>
{ {getRoutes(match.path, routerData).map(item => (
getRoutes(match.path, routerData).map(item => (
<Route <Route
key={item.key} key={item.key}
path={item.path} path={item.path}
render={props => <item.component {...props} currentUser={currentUser} />} render={props => (
<item.component {...props} currentUser={currentUser} />
)}
exact={item.exact} exact={item.exact}
/> />
)) ))}
}
<Redirect exact from="/userinfo" to="/userinfo/base" /> <Redirect exact from="/userinfo" to="/userinfo/base" />
<Redirect to="/exception/404" /> <Redirect to="/exception/404" />
</Switch> </Switch>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment