import React from 'react'; import { Menu, Icon } from 'antd'; import './leftTab.less'; const SubMenu = Menu.SubMenu; const MenuItemGroup = Menu.ItemGroup; import { getMenu } from './publicMenu.js' const LeftTab = React.createClass({ getInitialState() { return { current: '', subKey: '', }; }, handleClick(e) { this.props.handlekey(e.key); this.setState({ current: e.key, }); }, componentWillMount() { let me_ = this; var ids = window.location.href.indexOf('rid=') var idk = window.location.href.substr(ids + 4) var rid = idk.split('#') var menu = getMenu(rid); let cur, sub, sut; if (rid.length > 1) { for (var h = 0; h < menu.length; h++) { if (menu[h].subMenus.length) { menu[h].subMenus.map(function (atem) { let urls = atem.url.split('#') if (rid[1] == urls[1]) { sut = menu[h].url; return false } }) } } }; if (menu[0].subMenus.length) { cur = menu[0].subMenus[0].url.split('#'); sub = menu[0].url; } else { cur = menu[0].url.split('#'); sub = '' }; this.setState({ current: rid.length > 1 ? rid[1] : cur[1], subKey: rid.length > 1 ? sut : sub }); var htmlMenu = []; for (var j = 0; j < menu.length; j++) { if (menu[j].subMenus.length) { htmlMenu.push( {menu[j].name}}> { menu[j].subMenus.map(function (item) { let urls = item.url.split('#'); return {item.name} }) } ); } else { let urlt = menu[j].url.split('#'); htmlMenu.push( {menu[j].name} ) } }; this.setState({ htmlMenus: htmlMenu }) const _me = this; if (window.location.hash && menu[0].subMenus.length) { let theKey = window.location.hash.substr(1); menu.map(function (item1) { item1.subMenus.map(function (item2) { let urls = item2.url.split('#') if (theKey == urls[1]) { _me.state.subKey = item1.url }; }); }); this.state.current = theKey; } else { this.state.current = window.location.hash.substr(1); }; }, render() { return ( {this.state.htmlMenus} ); }, }); export default LeftTab;