leftTab.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React from 'react';
  2. import { Menu, Icon } from 'antd';
  3. import '../leftTab.less';
  4. const SubMenu = Menu.SubMenu;
  5. const MenuItemGroup = Menu.ItemGroup;
  6. const LeftTab = React.createClass({
  7. getInitialState() {
  8. return {
  9. current: 'star',
  10. subKey: 'sub1',
  11. keyList: [
  12. { key: 'sub1', value: ['star','lecture'] },
  13. ]
  14. };
  15. },
  16. handleClick(e) {
  17. this.props.handlekey(e.key);
  18. this.setState({
  19. current: e.key,
  20. });
  21. },
  22. componentWillMount() {
  23. const _me = this;
  24. if (window.location.hash) {
  25. let theKey = window.location.hash.substr(1);
  26. this.state.keyList.map(function (item1) {
  27. item1.value.map(function (item2) {
  28. if (theKey == item2) {
  29. _me.state.subKey = item1.key
  30. };
  31. });
  32. });
  33. this.state.current = theKey;
  34. };
  35. },
  36. render() {
  37. return (
  38. <Menu onClick={this.handleClick}
  39. selectedKeys={[this.state.current]}
  40. defaultOpenKeys={[this.state.subKey]}
  41. mode="vertical"
  42. className="account-left"
  43. mode="inline" >
  44. <SubMenu key="sub1" title={<span>大咖说</span>}>
  45. <Menu.Item key="star">
  46. 科技明星
  47. </Menu.Item>
  48. <Menu.Item key="lecture">
  49. 科技讲堂
  50. </Menu.Item>
  51. </SubMenu>
  52. </Menu>
  53. );
  54. }
  55. });
  56. export default LeftTab;