leftTab.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. import { getMenu } from './publicMenu.js'
  7. const LeftTab = React.createClass({
  8. getInitialState() {
  9. return {
  10. current: '',
  11. subKey: '',
  12. };
  13. },
  14. handleClick(e) {
  15. this.props.handlekey(e.key);
  16. this.setState({
  17. current: e.key,
  18. });
  19. },
  20. componentWillMount() {
  21. let me_ = this;
  22. var ids = window.location.href.indexOf('rid=')
  23. var idk = window.location.href.substr(ids + 4)
  24. var rid = idk.split('#')
  25. var menu = getMenu(rid);
  26. let cur, sub, sut;
  27. if (rid.length > 1) {
  28. for (var h = 0; h < menu.length; h++) {
  29. if (menu[h].subMenus.length) {
  30. menu[h].subMenus.map(function (atem) {
  31. let urls = atem.url.split('#')
  32. if (rid[1] == urls[1]) {
  33. sut = menu[h].url;
  34. return false
  35. }
  36. })
  37. }
  38. }
  39. };
  40. if (menu[0].subMenus.length) {
  41. cur = menu[0].subMenus[0].url.split('#');
  42. sub = menu[0].url;
  43. } else {
  44. cur = menu[0].url.split('#');
  45. sub = ''
  46. };
  47. this.setState({
  48. current: rid.length > 1 ? rid[1] : cur[1],
  49. subKey: rid.length > 1 ? sut : sub
  50. });
  51. var htmlMenu = [];
  52. for (var j = 0; j < menu.length; j++) {
  53. if (menu[j].subMenus.length) {
  54. htmlMenu.push(
  55. <SubMenu key={menu[j].url} title={<span>{menu[j].name}</span>}>
  56. {
  57. menu[j].subMenus.map(function (item) {
  58. let urls = item.url.split('#');
  59. return <Menu.Item key={urls[1]}>{item.name}</Menu.Item>
  60. })
  61. }
  62. </SubMenu>
  63. );
  64. } else {
  65. let urlt = menu[j].url.split('#');
  66. htmlMenu.push(
  67. <Menu.Item key={urlt[1]}>{menu[j].name}</Menu.Item>
  68. )
  69. }
  70. };
  71. this.setState({
  72. htmlMenus: htmlMenu
  73. })
  74. const _me = this;
  75. if (window.location.hash && menu[0].subMenus.length) {
  76. let theKey = window.location.hash.substr(1);
  77. menu.map(function (item1) {
  78. item1.subMenus.map(function (item2) {
  79. let urls = item2.url.split('#')
  80. if (theKey == urls[1]) {
  81. _me.state.subKey = item1.url
  82. };
  83. });
  84. });
  85. this.state.current = theKey;
  86. } else {
  87. this.state.current = window.location.hash.substr(1);
  88. };
  89. },
  90. render() {
  91. return (
  92. <Menu onClick={this.handleClick}
  93. selectedKeys={[this.state.current]}
  94. defaultOpenKeys={[this.state.subKey]}
  95. // mode="vertical"
  96. className="account-left"
  97. mode="inline"
  98. >
  99. {this.state.htmlMenus}
  100. </Menu>
  101. );
  102. },
  103. });
  104. export default LeftTab;