123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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(
- <SubMenu key={menu[j].url} title={<span>{menu[j].name}</span>}>
- {
- menu[j].subMenus.map(function (item) {
- let urls = item.url.split('#');
- return <Menu.Item key={urls[1]}>{item.name}</Menu.Item>
- })
- }
- </SubMenu>
- );
- } else {
- let urlt = menu[j].url.split('#');
- htmlMenu.push(
- <Menu.Item key={urlt[1]}>{menu[j].name}</Menu.Item>
- )
- }
- };
- 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 (
- <Menu onClick={this.handleClick}
- selectedKeys={[this.state.current]}
- defaultOpenKeys={[this.state.subKey]}
- // mode="vertical"
- className="account-left"
- mode="inline"
- >
- {this.state.htmlMenus}
- </Menu>
- );
- },
- });
- export default LeftTab;
|