diff --git a/front/src/layout/MainLayout/index.jsx b/front/src/layout/MainLayout/index.jsx index 821263b..f02dbeb 100644 --- a/front/src/layout/MainLayout/index.jsx +++ b/front/src/layout/MainLayout/index.jsx @@ -1,84 +1,84 @@ -import React from "react"; -import { Link, withRouter } from "react-router-dom"; -import { Menu, Dropdown, Divider } from "antd"; -import { connect } from "react-redux"; -import styles from "./index.module.less"; -import { changeLoginInfo, DATA_NAME } from "../../redux/action/LoginInfoAction"; - -function mapStateToProps(state) { - return state[DATA_NAME]; -} - -function mapDispatchToProps(dispatch) { - return { - updateLoginInfo: (token, userInfo) => dispatch(changeLoginInfo(token, userInfo)) - }; -} - -class MainLayout extends React.Component { - constructor(props) { - super(props); - console.log(props); - this.state = {}; - } - - renderUserArea() { - const { userInfo } = this.props; - const menu = ( - - 个人资料 - 退出登陆 - - ); - if (userInfo !== null) { - return ( - - {userInfo.username} - - ); - } else { - return ( -
- 登陆 - 注册 -
- ); - } - } - - onClick = e => { - const { history } = this.props; - switch (e.key) { - case "logout": - this.props.updateLoginInfo(null, null); - localStorage.removeItem("token"); - localStorage.removeItem("userInfo"); - delete window.token; - delete window.userInfo; - history.replace("/"); - break; - default: - break; - } - }; - - render() { - return ( -
-
- logo - {this.renderUserArea()} -
- -
{this.props.children}
-
- ); - } -} - -export default withRouter( - connect( - mapStateToProps, - mapDispatchToProps - )(MainLayout) -); +import React from "react"; +import { Link, withRouter } from "react-router-dom"; +import { Menu, Dropdown, Divider } from "antd"; +import { connect } from "react-redux"; +import styles from "./index.module.less"; +import { changeLoginInfo, DATA_NAME } from "../../redux/action/LoginInfoAction"; + +function mapStateToProps(state) { + return state[DATA_NAME]; +} + +function mapDispatchToProps(dispatch) { + return { + updateLoginInfo: (token, userInfo) => dispatch(changeLoginInfo(token, userInfo)) + }; +} + +class MainLayout extends React.Component { + constructor(props) { + super(props); + console.log(props); + this.state = {}; + } + + renderUserArea() { + const { userInfo } = this.props; + const menu = ( + + 个人资料 + 退出登陆 + + ); + if (userInfo !== null) { + return ( + + {userInfo.username} + + ); + } else { + return ( +
+ 登陆 + 注册 +
+ ); + } + } + + onClick = e => { + const { history } = this.props; + switch (e.key) { + case "logout": + this.props.updateLoginInfo(null, null); + localStorage.removeItem("token"); + localStorage.removeItem("userInfo"); + delete window.token; + delete window.userInfo; + history.replace("/"); + break; + default: + break; + } + }; + + render() { + return ( +
+
+ logo + {this.renderUserArea()} +
+ +
{this.props.children}
+
+ ); + } +} + +export default withRouter( + connect( + mapStateToProps, + mapDispatchToProps + )(MainLayout) +);