import React from 'react'; import { Menu, Icon, Layout, message } from 'antd'; import '@/account/leftTab.less'; const SubMenu = Menu.SubMenu; const MenuItemGroup = Menu.ItemGroup; import { Link } from 'react-router'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; import { menu } from '@/account/menu'; import logo from 'img/acc-logo.png'; const { Sider } = Layout; const LeftTab = React.createClass({ getInitialState() { return { openKeys: [ 'sub1' ], current: 'normal', switch: false, rootSubmenuKeys: [ 'sub1', 'sub2', 'sub3', 'sub4' ] }; }, loadData() { $.ajax({ method: 'get', dataType: 'json', url: globalConfig.context + '/api/user/homePage', data: {} }).done( function(data) { if (!data.error.length) { this.setState({ type: data.data.type }); } else { message.warning(data.error[0].message); } }.bind(this) ); }, menuClick(e) { this.setState({ current: e.key }); window.location.hash = e.key; }, iconFun() { let menuW = document.querySelector('.ant-layout-sider'); if (this.state.switch) { menuW.style.width = '200px'; menuW.style.flex = '0 0 200px'; } else { menuW.style.width = '50px'; menuW.style.flex = '0 0 50px'; } this.setState({ switch: !this.state.switch }); }, onOpenChange(openKeys) { const latestOpenKey = openKeys.find((key) => this.state.openKeys.indexOf(key) === -1); if (this.state.rootSubmenuKeys.indexOf(latestOpenKey) === -1) { this.setState({ openKeys }); } else { this.setState({ openKeys: latestOpenKey ? [ latestOpenKey ] : [] }); } }, componentWillMount() { this.loadData(); if (window.location.hash) { let current = window.location.hash.substr(2), open = []; if (!current.length) { window.location.hash = 'normal'; this.setState({ openKeys: [ 'sub1' ], current: 'normal' }); } else { menu.map((item) => { if (item.children) { item.children.map((atem) => { if (current == atem.url) { open.push(item.url); return false; } }); } }); this.setState({ openKeys: open, current }); } } else { window.location.hash = 'normal'; this.setState({ openKeys: [ 'sub1' ], current: 'normal' }); } }, render() { let demandList = [ { name: '我的需求', url: 'sub3', icon: 'bulb', children: [ { name: '科技需求列表', url: 'demand' } ] }, { name: '我的成果', url: 'sub4', icon: 'compass', children: [ { name: '科技成果列表', url: 'achievement' } ] } ]; let menuList = [],newMenu=[]; let menuNO = menu[1].children; menuNO.map((item) => { if (this.state.type == '0') { if (item.name != '企业资料') { menuList.push(item); } } else if (this.state.type == '1') { if (item.name != '个人资料') { menuList.push(item); } } else { menuList.push(item); } }); menu[1].children = menuList; if (this.state.type == '0' || this.state.type == '1') { newMenu = menu.concat(demandList); }else{ newMenu=menu; } return (
{!this.state.switch && } {!this.state.switch && ( 会员中心管理 )}
{newMenu.map((subMenu) => { if (subMenu.children && subMenu.children.length) { return ( {!this.state.switch && {subMenu.name}} } > {subMenu.children.map((menu) => {menu.name})} ); } return ( {subMenu.name} ); })}
); } }); export default LeftTab;