123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import React from 'react';
- import { Menu, Icon, Button, Switch } from 'antd';
- import { BrowserRouter as Router, Route, Link, withRouter } from 'react-router-dom';
- import MUtil from 'util/mutil.jsx';
- import './index.scss';
- const SubMenu = Menu.SubMenu;
- const _mutil = new MUtil();
- class Logo extends React.Component {
- constructor(props) {
- super(props);
- }
- render() {
- if (this.props.collapsed) {
- return (
- <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
- <text x="27" y="40">
- <tspan fill="#FFF">M</tspan>
- </text>
- </svg>
- );
- } else {
- return (
- <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
- <text x="20" y="40">
- <tspan fill="#2dafcb">HAPPY</tspan> <tspan fill="#fff">MMALL</tspan>
- </text>
- </svg>
- );
- }
- }
- }
- class SideNav extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- theme: 'dark',
- current: '/',
- // defaultOpen: 'product',
- myTextInput: '',
- userInfo: _mutil.getStorage('userInfo') || ''
- };
- }
- handleClick(e) {
- const pathname = this.props.history.location.pathname;
- this.setState({
- current: e.key
- });
- if (pathname !== '/' && this.state.userInfo === '') {
- _mutil.doLogin();
- }
- }
- componentWillMount() {
- if (this.props.location.pathname !== '/') {
- if (this.state.userInfo === '') {
- _mutil.doLogin();
- }
- console.log(this.props.location.pathname.split('-')[0]);
- this.setState({
- current: this.props.location.pathname
- });
- }
- }
- render() {
- return (
- <div id="SideNav">
- <div className="logo">
- <Logo collapsed={this.props.collapsed} />
- </div>
- <Menu
- theme={this.state.theme}
- onClick={e => {
- this.handleClick(e);
- }}
- // defaultOpenKeys={[this.state.defaultOpen]}
- // defaultSelectedKeys={['4']}
- selectedKeys={[this.state.current]}
- // mode="inline"
- >
- <Menu.Item key="/">
- <Icon type="dashboard" />
- <span>首页</span>
- <Link to="/" />
- </Menu.Item>
- <SubMenu
- key="product"
- title={
- <span>
- <Icon type="unordered-list" />
- <span>商品</span>
- </span>
- }
- >
- <Menu.Item key="/product">
- <span>商品管理</span>
- <Link to="/product" />
- </Menu.Item>
- <Menu.Item key="/product-category">
- <span>品类管理</span>
- <Link to="/product-category" />
- </Menu.Item>
- </SubMenu>
- <SubMenu
- key="order"
- onTitleClick={e => {
- this.submenuClick(e);
- }}
- title={
- <span>
- <Icon type="appstore" />
- <span>订单</span>
- </span>
- }
- >
- <Menu.Item key="/order">
- <span>订单管理</span>
- <Link to="/order" />
- </Menu.Item>
- </SubMenu>
- <SubMenu
- key="user"
- onTitleClick={e => {
- this.submenuClick(e);
- }}
- title={
- <span>
- <Icon type="user" />
- <span>用户</span>
- </span>
- }
- >
- <Menu.Item key="/user">
- <span>用户列表</span>
- <Link to="/user" />
- </Menu.Item>
- </SubMenu>
- </Menu>
- </div>
- );
- }
- }
- export default withRouter(SideNav);
|