king
2020-04-29 9b6ce1a5778c6e1a813237e87588c0052aae1bbb
src/components/sidemenu/index.jsx
@@ -4,8 +4,11 @@
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { Menu, Icon, notification } from 'antd'
import asyncComponent from '@/utils/asyncComponent'
import {modifyTabview, resetEditLevel} from '@/store/action'
import { modifyTabview, resetEditLevel } from '@/store/action'
import { SySMenuList } from './config'
import options from '@/store/options.js'
import zhCN from '@/locales/zh-CN/header.js'
import enUS from '@/locales/en-US/header.js'
import Api from '@/api'
@@ -46,8 +49,16 @@
      return
    }
    let result = await Api.getSystemConfig({func: 'sPC_Get_FunMenu', ParentID: menu.MenuID})
    let _param = {func: 'sPC_Get_FunMenu', ParentID: menu.MenuID, systemType: options.systemType}
    if (sessionStorage.getItem('isEditState') === 'true') { // 编辑状态时,获取菜单,增加参数debug
      _param.debug = 'Y'
    }
    let result = await Api.getSystemConfig(_param)
    if (result.status) {
      if (this.props.editState && this.props.editLevel) return
      if (result.data.length === 0) { // 查询菜单为空
        this.setState({
          subMenulist: [],
@@ -83,6 +94,8 @@
      }
      let parentID = submenuId ? submenuId : result.data[0].ParentID // 展开二级菜单ID
      let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt']
      let menulist = result.data.map(item => {
        let _smenu = {}
        _smenu.id = item.ParentID
@@ -94,6 +107,7 @@
        } catch (e) {
          _smenu.PageParam = {Icon: 'folder'}
        }
        if (item.FunMenu) {
          _smenu.children = item.FunMenu.map(child => {
            let _tmenu = {}
@@ -106,10 +120,7 @@
            } else if (child.LinkUrl === 'DataManage') {
              _tmenu.type = 'DataManage'
              _tmenu.forbidden = true
            // } else if (child.LinkUrl === 'bda/rdt?pageno=rolemenus&MenuNo=RoleMenuM') {
            //   _tmenu.type = 'RoleManage'
            //   _tmenu.forbidden = true
            } else if (child.LinkUrl.split('?')[0] === 'Main/Index' || child.LinkUrl.split('?')[0] === 'bda/rdt') {
            } else if (iframes.includes(child.LinkUrl.split('?')[0])) {
              _tmenu.type = 'iframe'
              _tmenu.forbidden = true
            }
@@ -156,13 +167,35 @@
      notification.warning({
        top: 92,
        message: result.message,
        duration: 10
        duration: 5
      })
    }
  }
  enterManageView = (type) => {
    let menulist = SySMenuList[type]
    if (window.GLOB.systemType === 'official') {
      menulist.forEach(menu => {
        menu.children = menu.children.filter(item => item.systems && item.systems.includes(window.GLOB.systemType))
      })
      menulist = menulist.filter(menu => menu.children.length > 0)
    } else {
      menulist.forEach(menu => {
        menu.children = menu.children.filter(item => !item.systems || item.systems.includes(options.systemType))
      })
    }
    this.setState({
      subMenulist: menulist,
      rootSubmenuKeys: menulist.map(item => item.MenuID),
      openKeys: this.props.collapse ? [] : [menulist[0].MenuID]
    })
  }
  changemenu(e) {
    if (this.props.editState) {
    if (this.props.editState && this.props.editLevel !== 'level4') {
      e.preventDefault()
      return
    }
@@ -188,7 +221,9 @@
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (nextProps.mainMenu && !is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) {
    if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu)) && nextProps.mainMenu && nextProps.mainMenu.MenuID === 'systemManageView') {
      this.enterManageView(nextProps.mainMenu.MenuID)
    } else if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) {
      // 主菜单切换,请求2、3级菜单数据
      this.loadsubmenu(nextProps.mainMenu)
    } else if (nextProps.collapse && this.props.collapse !== nextProps.collapse) {
@@ -200,13 +235,7 @@
  }
  shouldComponentUpdate(nextProps, nextState) {
    // if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu)) || (!this.props.collapse && !is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews)))) {
    if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) {
      // 主菜单切换,或菜单展开下的tab页变化,不会刷新
      return false
    } else {
      return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
    }
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  onOpenChange = openKeys => {
@@ -225,7 +254,7 @@
    e.stopPropagation()
    this.props.resetEditLevel('level2')
    // 获取一级菜单列表
    Api.getSystemConfig({func: 'sPC_Get_MainMenu'}).then(res => {
    Api.getSystemConfig({func: 'sPC_Get_MainMenu', debug: 'Y'}).then(res => {
      this.setState({
        mainMenuList: res.data.map(item => {
          return {
@@ -257,6 +286,7 @@
  render () {
    const editShow = (this.props.editState && !this.props.editLevel) || false
    return (
      <aside className={"side-menu ant-menu-dark" + (this.props.collapse ? ' side-menu-collapsed' : '') + (this.props.isiframe ? ' iframe' : '')}>
        {this.state.subMenulist && !(this.props.editLevel === 'level2' || this.props.editLevel === 'level3') &&