index.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React from 'react';
  2. import { Menu, Icon, Button, Switch } from 'antd';
  3. import { BrowserRouter as Router, Route, Link, withRouter } from 'react-router-dom';
  4. import MUtil from 'util/mutil.jsx';
  5. import './index.scss';
  6. const SubMenu = Menu.SubMenu;
  7. const _mutil = new MUtil();
  8. class Logo extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. }
  12. render() {
  13. if (this.props.collapsed) {
  14. return (
  15. <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  16. <text x="27" y="40">
  17. <tspan fill="#FFF">M</tspan>
  18. </text>
  19. </svg>
  20. );
  21. } else {
  22. return (
  23. <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  24. <text x="20" y="40">
  25. <tspan fill="#2dafcb">HAPPY</tspan> <tspan fill="#fff">MMALL</tspan>
  26. </text>
  27. </svg>
  28. );
  29. }
  30. }
  31. }
  32. class SideNav extends React.Component {
  33. constructor(props) {
  34. super(props);
  35. this.state = {
  36. theme: 'dark',
  37. current: '/',
  38. // defaultOpen: 'product',
  39. myTextInput: '',
  40. userInfo: _mutil.getStorage('userInfo') || ''
  41. };
  42. }
  43. handleClick(e) {
  44. const pathname = this.props.history.location.pathname;
  45. this.setState({
  46. current: e.key
  47. });
  48. if (pathname !== '/' && this.state.userInfo === '') {
  49. _mutil.doLogin();
  50. }
  51. }
  52. componentWillMount() {
  53. if (this.props.location.pathname !== '/') {
  54. if (this.state.userInfo === '') {
  55. _mutil.doLogin();
  56. }
  57. console.log(this.props.location.pathname.split('-')[0]);
  58. this.setState({
  59. current: this.props.location.pathname
  60. });
  61. }
  62. }
  63. render() {
  64. return (
  65. <div id="SideNav">
  66. <div className="logo">
  67. <Logo collapsed={this.props.collapsed} />
  68. </div>
  69. <Menu
  70. theme={this.state.theme}
  71. onClick={e => {
  72. this.handleClick(e);
  73. }}
  74. // defaultOpenKeys={[this.state.defaultOpen]}
  75. // defaultSelectedKeys={['4']}
  76. selectedKeys={[this.state.current]}
  77. // mode="inline"
  78. >
  79. <Menu.Item key="/">
  80. <Icon type="dashboard" />
  81. <span>首页</span>
  82. <Link to="/" />
  83. </Menu.Item>
  84. <SubMenu
  85. key="product"
  86. title={
  87. <span>
  88. <Icon type="unordered-list" />
  89. <span>商品</span>
  90. </span>
  91. }
  92. >
  93. <Menu.Item key="/product">
  94. <span>商品管理</span>
  95. <Link to="/product" />
  96. </Menu.Item>
  97. <Menu.Item key="/product-category">
  98. <span>品类管理</span>
  99. <Link to="/product-category" />
  100. </Menu.Item>
  101. </SubMenu>
  102. <SubMenu
  103. key="order"
  104. onTitleClick={e => {
  105. this.submenuClick(e);
  106. }}
  107. title={
  108. <span>
  109. <Icon type="appstore" />
  110. <span>订单</span>
  111. </span>
  112. }
  113. >
  114. <Menu.Item key="/order">
  115. <span>订单管理</span>
  116. <Link to="/order" />
  117. </Menu.Item>
  118. </SubMenu>
  119. <SubMenu
  120. key="user"
  121. onTitleClick={e => {
  122. this.submenuClick(e);
  123. }}
  124. title={
  125. <span>
  126. <Icon type="user" />
  127. <span>用户</span>
  128. </span>
  129. }
  130. >
  131. <Menu.Item key="/user">
  132. <span>用户列表</span>
  133. <Link to="/user" />
  134. </Menu.Item>
  135. </SubMenu>
  136. </Menu>
  137. </div>
  138. );
  139. }
  140. }
  141. export default withRouter(SideNav);