leftTab.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. current(e){
  15. let menuArr=this.state.menu;
  16. let curr;
  17. menuArr.map(function(item){
  18. if(e==item.url){
  19. curr=item.subMenus[0].url.split('#')
  20. }
  21. })
  22. return curr;
  23. },
  24. handleClick(e) {
  25. let menuArr=this.state.menu;
  26. let path=e.keyPath[1];
  27. if (this.state.subKey !== e.keyPath[1]) {
  28. let urls= this.current(path);
  29. location.href=globalConfig.context +urls[0]+'?rid='+this.state.idtt+'#' + e.key;
  30. };
  31. this.props.handlekey(e.key);
  32. this.setState({
  33. subKey:path,
  34. current: e.key,
  35. });
  36. },
  37. componentWillMount() {
  38. let me_=this;
  39. var ids=window.location.href.indexOf('rid=')
  40. var idk=window.location.href.substr(ids+4)
  41. var rid=idk.split('#')
  42. var menu=getMenu(rid);
  43. let sub;
  44. let curr=rid[1];
  45. for(var i=0;i<menu.length;i++){
  46. menu[i].subMenus.map(function(atem){
  47. if(atem.url.indexOf(curr)>0){
  48. sub=menu[i].url
  49. }
  50. })
  51. }
  52. let cur,subs;
  53. if(menu[0].subMenus.length){
  54. cur=menu[0].subMenus[0].url.split('#');
  55. subs=menu[0].url;
  56. }else{
  57. cur=menu[0].url.split('#');
  58. subs=''
  59. };
  60. if(sub!=undefined){
  61. this.setState({
  62. menu:menu,
  63. current:rid[1],
  64. subKey:sub,
  65. idtt:rid[0]
  66. });
  67. }else{
  68. this.setState({
  69. menu:menu,
  70. current:cur[1],
  71. subKey:subs,
  72. idtt:rid[0]
  73. });
  74. }
  75. var htmlMenu=[];
  76. for(var j=0;j<menu.length;j++){
  77. if(menu[j].subMenus.length){
  78. htmlMenu.push(
  79. <SubMenu key={menu[j].url} title={<span>{menu[j].name}</span>}>
  80. {
  81. menu[j].subMenus.map(function(item){
  82. let urls=item.url.split('#');
  83. return <Menu.Item key={urls[1]}>{item.name}</Menu.Item>
  84. })
  85. }
  86. </SubMenu>
  87. );
  88. }else{
  89. let urlt=menu[j].url.split('#');
  90. htmlMenu.push(
  91. <Menu.Item key={urlt[1]}>{menu[j].name}</Menu.Item>
  92. )
  93. }
  94. };
  95. this.setState({
  96. htmlMenus:htmlMenu
  97. })
  98. const _me = this;
  99. if (window.location.hash&&menu[0].subMenus.length) {
  100. let theKey = window.location.hash.substr(1);
  101. menu.map(function (item1) {
  102. item1.subMenus.map(function (item2) {
  103. let urls=item2.url.split('#')
  104. if (theKey == urls[1]) {
  105. _me.state.subKey = item1.url
  106. };
  107. });
  108. });
  109. this.state.current = theKey;
  110. }else{
  111. this.state.current = window.location.hash.substr(1);
  112. };
  113. },
  114. render() {
  115. return (
  116. <Menu onClick={this.handleClick}
  117. selectedKeys={[this.state.current]}
  118. defaultOpenKeys={[this.state.subKey]}
  119. mode="vertical"
  120. className="account-left"
  121. mode="inline" >
  122. {this.state.htmlMenus}
  123. </Menu>
  124. );
  125. }
  126. });
  127. export default LeftTab;