king
2023-08-16 7e46c386be5c2cfc20af3936d26839ad3fce44b0
src/views/design/sidemenu/index.jsx
@@ -1,12 +1,10 @@
import React, {Component} from 'react'
import { connect } from 'react-redux'
import { is, fromJS } from 'immutable'
import { Menu, Popover, Modal, notification } from 'antd'
import { SwapOutlined, PlusOutlined, SettingOutlined } from '@ant-design/icons'
import { EditOutlined, PlusOutlined, SettingOutlined } from '@ant-design/icons'
import moment from 'moment'
import asyncComponent from '@/utils/asyncComponent'
import { resetEditLevel } from '@/store/action'
import Utils from '@/utils/utils.js'
import Api from '@/api'
import MKEmitter from '@/utils/events.js'
@@ -46,8 +44,15 @@
    menu = fromJS(menu).toJS()
    let openKey = ''
    if (menu.children[0]) {
      openKey = menu.openId || menu.children[0].MenuID
    // 菜单更新时,展开原二级菜单
    if (this.props.mainMenu && menu.MenuID === this.props.mainMenu.MenuID && this.state.openKeys && this.state.openKeys[0]) {
      openKey = this.state.openKeys[0]
      if (menu.children.filter(m => m.MenuID === openKey).length === 0) {
        openKey = ''
      }
    }
    if (!openKey && menu.children[0]) {
      openKey = menu.children[0].MenuID
    }
    this.setState({
@@ -63,7 +68,6 @@
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) {
      // 主菜单切换,请求2、3级菜单数据
      this.loadsubmenu(nextProps.mainMenu)
    }
  }
@@ -103,6 +107,8 @@
  }
  editmenu = (cell) => {
    if (window.GLOB.systemType === 'production') return
    if (cell.type === 'CustomPage') {
      let _param = {
        MenuType: 'custom',
@@ -113,18 +119,35 @@
      }
      _param = window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
      window.open(`#/menudesign/${_param}`)
    } else if (['RolePermission', 'NewPage'].includes(cell.type)) {
      cell.Template = cell.PageParam.Template
      cell.url = cell.PageParam.url || ''
    } else if (['CommonTable', 'TreePage'].includes(cell.type)) {
      sessionStorage.setItem('menuTree', JSON.stringify(this.props.menuTree))
      let _param = window.btoa(window.encodeURIComponent(JSON.stringify(cell)))
      cell.fstMenuId = cell.FstId
      cell.supMenuList = this.props.mainMenu.children
      cell.fstMenuList = this.props.menuTree
      window.open(`#/basedesign/${_param}`)
    } else if (cell.type === 'BaseTable') {
      sessionStorage.setItem('menuTree', JSON.stringify(this.props.menuTree))
      let _param = window.btoa(window.encodeURIComponent(JSON.stringify(cell)))
      window.open(`#/tabledesign/${_param}`)
    } else if (['RolePermission', 'NewPage'].includes(cell.type)) {
      let _cell = fromJS(cell).toJS()
      _cell.Template = _cell.PageParam.Template
      _cell.url = _cell.PageParam.url || ''
      _cell.fstMenuId = _cell.FstId
      _cell.supMenuList = this.props.mainMenu.children
      _cell.fstMenuList = this.props.menuTree
      this.setState({
        thdVisible: true,
        loading: false,
        sysMenu: cell
        sysMenu: _cell
      })
    } else {
      notification.warning({
        top: 92,
        message: '当前菜单不可编辑',
        duration: 5
      })
    }
  }
@@ -177,7 +200,7 @@
      this.setState({
        loading: true
      })
      Api.getSystemConfig(param).then(res => {
      Api.getCloudConfig(param).then(res => {
        if (res.status) {
          this.setState({
            loading: false,
@@ -237,7 +260,7 @@
        loading: true
      })
      Api.getSystemConfig(param).then(response => {
      Api.getCloudConfig(param).then(response => {
        if (response.status) {
          this.setState({
            loading: false,
@@ -271,7 +294,7 @@
            <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
              <div className="mk-popover-control">
                <PlusOutlined onClick={this.addSecMenu}/>
                <SwapOutlined onClick={this.enterSubEdit} className={'mk-swap' + (mainMenu.children.length === 0 ? ' disabled' : '')}/>
                <EditOutlined onClick={this.enterSubEdit} className={'mk-swap' + (mainMenu.children.length === 0 ? ' disabled' : '')}/>
                <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={mainMenu.MenuID} Type="20"/></div>
              </div>
            } trigger="hover" placement="top">
@@ -284,7 +307,7 @@
                key={item.MenuID}
                title={
                  <span className={!editLevel && index === 0 ? 'edit-control' : ''}>
                    <MkIcon type={item.PageParam.Icon} />
                    <MkIcon type={item.PageParam ? item.PageParam.Icon : 'folder'} />
                    <span>{item.MenuName}</span>
                  </span>
                }
@@ -293,7 +316,7 @@
                  <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
                    <div className="mk-popover-control">
                      <div style={{display: 'inline-block', minWidth: '32px'}}><AddThdMenu mainMenu={mainMenu} supMenu={item} menuTree={this.props.menuTree}/></div>
                      <SwapOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-swap"/>
                      <EditOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-swap"/>
                      <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={item.MenuID} Type="30"/></div>
                    </div>
                  } trigger="hover" placement="top">
@@ -303,7 +326,7 @@
                {item.children.map(cell => {
                  return (
                    <Menu.Item key={cell.MenuID}>
                      <span className="editable-menu-item" onDoubleClick={(e) => {e.stopPropagation();this.editmenu(cell)}}>{cell.MenuName}</span>
                      <span className="editable-menu-item" onDoubleClick={() => this.editmenu(cell)}>{cell.MenuName}</span>
                    </Menu.Item>
                  )
                })}
@@ -324,6 +347,7 @@
            menulist={this.state.editMenu.children}
            supMenuList={mainMenu.children}
            supMenu={this.state.editMenu}
            menuTree={this.props.menuTree}
            exitEdit={this.exitEdit}
          /> : null
        }
@@ -344,7 +368,7 @@
        <Modal
          title="修改菜单"
          visible={thdVisible}
          width={600}
          width={700}
          onOk={this.thdSubmit}
          confirmLoading={loading}
          onCancel={() => {this.setState({thdVisible: false})}}
@@ -361,18 +385,4 @@
  }
}
const mapStateToProps = (state) => {
  return {
    mainMenu: state.mainMenu,
    menuTree: state.menuTree,
    editLevel: state.editLevel
  }
}
const mapDispatchToProps = (dispatch) => {
  return {
    resetEditLevel: (level) => dispatch(resetEditLevel(level))
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(Sidemenu)
export default Sidemenu