From 996f9e55c2348a29ae5564c5c9e052ac028e85c0 Mon Sep 17 00:00:00 2001 From: jim Date: Fri, 9 Feb 2018 18:28:57 +0800 Subject: [PATCH] Enhanced meun response --- src/routes/Userinfo/Info.js | 53 +++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/routes/Userinfo/Info.js b/src/routes/Userinfo/Info.js index 68683b9e..17a7852f 100644 --- a/src/routes/Userinfo/Info.js +++ b/src/routes/Userinfo/Info.js @@ -1,7 +1,9 @@ -import React, { PureComponent } from 'react'; +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'; @@ -17,7 +19,7 @@ const menuMap = { @connect(({ user }) => ({ currentUser: user.currentUser, })) -export default class Info extends PureComponent { +export default class Info extends Component { constructor(props) { super(props); const { match, location } = props; @@ -25,10 +27,20 @@ export default class Info extends PureComponent { 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]}); + return Object.keys(menuMap).map(item => ( + {menuMap[item]} + )); }; getRightTitle = () => { return menuMap[this.state.selectKey]; @@ -39,6 +51,19 @@ export default class Info extends PureComponent { 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) { @@ -48,7 +73,7 @@ export default class Info extends PureComponent {
@@ -58,16 +83,16 @@ export default class Info extends PureComponent {
{this.getRightTitle()}
- { - getRoutes(match.path, routerData).map(item => ( - } - exact={item.exact} - /> - )) - } + {getRoutes(match.path, routerData).map(item => ( + ( + + )} + exact={item.exact} + /> + ))} -- GitLab