File was renamed from src/components/sidemenu/sidemenu.jsx |
| | |
| | | import React, {Component} from 'react' |
| | | // import { Lifecycle } from 'react-router' |
| | | import { withRouter } from 'react-router-dom' |
| | | import PropTypes from 'prop-types' |
| | | import {connect} from 'react-redux' |
| | |
| | | import { Menu, Icon } from 'antd' |
| | | import {modifyTabview} from '@/store/action' |
| | | import Api from '@/api' |
| | | import './sidemenu.scss' |
| | | import './index.scss' |
| | | |
| | | const { SubMenu } = Menu |
| | | |
| | | class Smenu extends Component { |
| | | class Sidemenu extends Component { |
| | | static propTypes = { |
| | | collapse: PropTypes.bool, |
| | | mainMenu: PropTypes.oneOfType([ |
| | |
| | | async loadsubmenu (menu) { |
| | | let result = await Api.getSubMenuData(menu.MenuID) |
| | | if (result.status) { |
| | | let param = sessionStorage.getItem('view_param') // 是否为打开新页面 |
| | | let msg = sessionStorage.getItem('UserID') + '&' + sessionStorage.getItem('lang') |
| | | let submenuindex = 0 // 展开二级菜单索引 |
| | | let tabindex = null // 打开的tab页 |
| | | if (param) { |
| | | param = param.split('&') |
| | | submenuindex = parseInt(param[1]) |
| | | tabindex = parseInt(param[2]) |
| | | sessionStorage.removeItem('view_param') |
| | | } |
| | | |
| | | this.setState({ |
| | | subMenulist: result.data, |
| | | subMenulist: result.data.map((item, i) => { |
| | | if (item.children) { |
| | | item.children = item.children.map((child, n) => { |
| | | let _msg = window.btoa(menu.index + '&' + i + '&' + n + '&' + msg) |
| | | child.src = '#/main/' + _msg |
| | | return child |
| | | }) |
| | | } |
| | | return item |
| | | }), |
| | | rootSubmenuKeys: result.data.map(item => item.id), |
| | | openKeys: this.props.collapse ? [] : [result.data[0].id] |
| | | openKeys: this.props.collapse ? [] : [result.data[submenuindex].id] |
| | | }) |
| | | |
| | | if (tabindex !== null) { |
| | | let opentab = result.data[submenuindex].children[tabindex] |
| | | opentab.selected = true |
| | | this.props.modifyTabview([opentab]) |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | menu.selected = true |
| | | tabs.push(menu) |
| | | this.props.modifyTabview(tabs) |
| | | // this.props.history.push('/main') |
| | | // this.props.history.replace('/main') |
| | | e.preventDefault() |
| | | } |
| | | |
| | | // mixins = [ Lifecycle ] |
| | | |
| | | routerWillLeave(nextLocation) { |
| | | if (!this.state.isSaved) |
| | | return 'Your work is not saved! Are you sure you want to leave?' |
| | | } |
| | | |
| | | componentDidMount () { |
| | | |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | |
| | | } |
| | | } |
| | | |
| | | componentDidUpdate () { |
| | | // console.log('componentDidUpdate') |
| | | } |
| | | |
| | | onOpenChange = openKeys => { |
| | | const latestOpenKey = openKeys.find(key => this.state.openKeys.indexOf(key) === -1) |
| | | if (this.state.rootSubmenuKeys.indexOf(latestOpenKey) === -1) { |
| | |
| | | } |
| | | render () { |
| | | return ( |
| | | <aside className={"side-menu ant-menu-dark" + (this.props.collapse ? ' side-menu-collapsed' : '')}> |
| | | <aside className={"side-menu ant-menu-dark" + (this.props.collapse ? ' side-menu-collapsed' : '') + (this.props.isiframe ? ' iframe' : '')}> |
| | | {this.state.subMenulist && |
| | | <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark" inlineCollapsed={this.props.collapse}> |
| | | {this.state.subMenulist.map(item => { |
| | |
| | | {item.children.map(cell => { |
| | | return ( |
| | | <Menu.Item key={cell.id}> |
| | | <a href="#/main/0345" id={cell.MenuID} data-item={JSON.stringify(cell)} onClick={this.changemenu.bind(this)}>{cell.MenuName}</a> |
| | | <a href={cell.src} id={cell.MenuID} data-item={JSON.stringify(cell)} onClick={this.changemenu.bind(this)}>{cell.MenuName}</a> |
| | | </Menu.Item> |
| | | ) |
| | | })} |
| | |
| | | return { |
| | | tabviews: state.tabviews, |
| | | collapse: state.collapse, |
| | | isiframe: state.isiframe, |
| | | mainMenu: state.selectedMainMenu |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Smenu)) |
| | | export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Sidemenu)) |