leftTab.jsx 2.9 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.jsx'
  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. console.log(menu[h].subMenus)
  31. menu[h].subMenus.map(function(atem){
  32. let urls=atem.url.split('#')
  33. if(rid[1]==urls[1]){
  34. sut=menu[h].url;
  35. return false
  36. }
  37. })
  38. }
  39. }
  40. };
  41. if(menu[0].subMenus.length){
  42. cur=menu[0].subMenus[0].url.split('#');
  43. sub=menu[0].url;
  44. }else{
  45. cur=menu[0].url.split('#');
  46. sub=''
  47. };
  48. this.setState({
  49. current:rid.length>1?rid[1]:cur[1],
  50. subKey:rid.length>1?sut:sub
  51. });
  52. var htmlMenu=[];
  53. for(var j=0;j<menu.length;j++){
  54. if(menu[j].subMenus.length){
  55. htmlMenu.push(
  56. <SubMenu key={menu[j].url} title={<span>{menu[j].name}</span>}>
  57. {
  58. menu[j].subMenus.map(function(item){
  59. let urls=item.url.split('#');
  60. return <Menu.Item key={urls[1]}>{item.name}</Menu.Item>
  61. })
  62. }
  63. </SubMenu>
  64. );
  65. }else{
  66. let urlt=menu[j].url.split('#');
  67. htmlMenu.push(
  68. <Menu.Item key={urlt[1]}>{menu[j].name}</Menu.Item>
  69. )
  70. }
  71. };
  72. this.setState({
  73. htmlMenus:htmlMenu
  74. })
  75. const _me = this;
  76. if (window.location.hash&&menu[0].subMenus.length) {
  77. let theKey = window.location.hash.substr(1);
  78. menu.map(function (item1) {
  79. item1.subMenus.map(function (item2) {
  80. let urls=item2.url.split('#')
  81. if (theKey == urls[1]) {
  82. _me.state.subKey = item1.url
  83. };
  84. });
  85. });
  86. this.state.current = theKey;
  87. }else{
  88. this.state.current = window.location.hash.substr(1);
  89. };
  90. },
  91. render() {
  92. return (
  93. <Menu onClick={this.handleClick}
  94. selectedKeys={[this.state.current]}
  95. defaultOpenKeys={[this.state.subKey]}
  96. mode="vertical"
  97. className="account-left"
  98. mode="inline">
  99. {this.state.htmlMenus}
  100. </Menu>
  101. );
  102. },
  103. });
  104. export default LeftTab;