king
2022-08-02 8d66ff34fae5b048a6b7923cc75d34f13a08be9d
src/views/design/header/index.jsx
@@ -1,9 +1,8 @@
import React, {Component} from 'react'
import { withRouter } from 'react-router-dom'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { Dropdown, Menu, Modal, notification, Switch, Button } from 'antd'
import { MenuFoldOutlined, EditOutlined, AppstoreOutlined, DownOutlined, HomeOutlined, ApiOutlined } from '@ant-design/icons'
import { Dropdown, Menu, Modal, notification, Switch, Button, Popover } from 'antd'
import { MenuFoldOutlined, SettingOutlined, AppstoreOutlined, DownOutlined, HomeOutlined, ApiOutlined, PlusOutlined, SwapOutlined, MenuOutlined } from '@ant-design/icons'
import asyncComponent from '@/utils/asyncComponent'
import {
@@ -14,31 +13,33 @@
} from '@/store/action'
import Api from '@/api'
import options from '@/store/options.js'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import Utils from '@/utils/utils.js'
import avatar from '@/assets/img/avatar.jpg'
import MainLogo from '@/assets/img/main-logo.png'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const EditMenu = asyncComponent(() => import('@/templates/menuconfig/editfirstmenu'))
const EditMenu = asyncComponent(() => import('./editfirstmenu'))
const VersionsUp = asyncComponent(() => import('./versions'))
const ThawMenu = asyncComponent(() => import('@/components/thawmenu'))
const MenuForm = asyncComponent(() => import('./editfirstmenu/menuform'))
const { confirm } = Modal
class Header extends Component {
  state = {
    menulist: null, // 一级菜单
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    userName: sessionStorage.getItem('CloudUserName'),
    avatar: Utils.getrealurl(sessionStorage.getItem('CloudAvatar')),
    memberLevel: Utils.getMemberLevel(),
    visible: false,
    loading: false
  }
  logout = () => {
    // 退出登录
    let _this = this
    confirm({
      title: this.state.dict['main.logout.hint'],
      title: '您确定要退出吗?',
      content: '',
      onOk() {
        sessionStorage.clear()
@@ -51,10 +52,6 @@
  changeMenu (value) {
    // 主菜单切换
    if (this.props.editLevel) {
      // 编辑状态下,不可切换菜单
      return
    }
    if (value.PageParam.OpenType === 'menu') {
      this.props.modifyMainMenu(value)
    } else if (value.PageParam.OpenType === 'outpage') {
@@ -77,10 +74,21 @@
      this.setState({ menulist })
      this.props.modifyMenuTree(menulist)
      if (window.GLOB.systemType !== 'production') { // 非正式系统选择第一项
        this.props.modifyMainMenu(menulist[0] || null)
      let mainMenu = menulist[0] || null
      if (this.props.editLevel === 'level1') {
        mainMenu = null
      } else if (this.props.mainMenu && this.props.mainMenu.MenuID) {
        let _menu = menulist.filter(item => item.MenuID === this.props.mainMenu.MenuID)[0]
        mainMenu = _menu || mainMenu
        if (!_menu && (this.props.editLevel === 'level2' || this.props.editLevel === 'level3')) {
          this.props.resetEditLevel(false)
        }
      }
      this.props.modifyMenuTree(menulist)
      this.props.modifyMainMenu(mainMenu)
    } else {
      notification.error({
        top: 92,
@@ -116,7 +124,8 @@
            MenuID: snd.MenuID,
            MenuName: snd.MenuName,
            PageParam: {Icon: 'folder'},
            children: []
            children: [],
            level: 'second'
          }
          if (snd.PageParam) {
@@ -137,7 +146,8 @@
                MenuNo: trd.MenuNo,
                EasyCode: trd.EasyCode,
                type: 'CommonTable',            // 默认值为常用表
                OpenType: 'newtab'              // 打开方式
                OpenType: 'newtab',             // 打开方式
                level: 'third'
              }
  
              if (trd.LinkUrl && iframes.includes(trd.LinkUrl.split('?')[0])) {
@@ -154,7 +164,7 @@
                trdItem.type = trdItem.PageParam.Template || trdItem.type
                trdItem.OpenType = trdItem.PageParam.OpenType || trdItem.OpenType
                if (trdItem.type === 'CustomPage' && this.props.memberLevel < 20) { // 会员等级大于等于20时,有编辑权限
                if (trdItem.type === 'CustomPage' && this.state.memberLevel < 20) { // 会员等级大于等于20时,有编辑权限
                  trdItem.forbidden = true
                }
              }
@@ -188,40 +198,45 @@
  enterEdit = () => {
    // 进入编辑状态
    this.props.resetEditLevel('level1')
  }
  enterEditManage = () => {
    const { editLevel } = this.props
    if (editLevel === 'HS')  return
    this.props.resetEditLevel('HS')
    this.props.modifyMainMenu({
      MenuID: 'systemManageView'
    })
  }
  /**
   * @description 退出管理界面菜单
   */
  exitManage = () => {
    const { menulist } = this.state
    if (window.GLOB.systemType === 'production') { // 正式系统版本升级后,页面刷新
      this.props.history.replace('/main')
      window.location.reload()
      return
    }
    this.props.modifyMainMenu(menulist[0] || null)
    this.props.resetEditLevel(false)
    MKEmitter.emit('modifyTabs', null, 'replace')
    this.props.modifyMainMenu(null)
  }
  
  exitEdit = () => {
    // 退出编辑状态
    this.props.resetEditLevel(false)
    this.props.modifyMainMenu(this.state.menulist[0] || null)
  }
  addMemuSubmit = () => {
    // 新建菜单:提交
    this.addMenuFormRef.handleConfirm().then(param => {
      param.func = 'sPC_MainMenu_Add'
      param.Sort = (this.state.menulist.length + 1) * 10
      this.setState({
        loading: true
      })
      Api.getSystemConfig(param).then(res => {
        if (res.status) {
          this.setState({
            loading: false,
            visible: false,
          })
          this.loadmenu()
        } else {
          this.setState({
            loading: false
          })
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
        }
      })
    }, () => {})
  }
  
  UNSAFE_componentWillMount () {
@@ -230,14 +245,6 @@
    
    // 组件加载时,获取菜单数据
    this.loadmenu()
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (!is(fromJS(this.props.menuTree), fromJS(nextProps.menuTree)) && !is(fromJS(this.state.menulist), fromJS(nextProps.menuTree))) {
      this.setState({
        menulist: nextProps.menuTree
      })
    }
  }
  componentDidMount () {
@@ -272,16 +279,14 @@
          }
        })
      }, 50)
    } else if (window.GLOB.systemType === 'production') {
      this.props.resetEditLevel('HS')
      this.props.modifyMainMenu({
        MenuID: 'systemManageView'
      })
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
    window.addEventListener('storage', (e) => {
      if (e.key !== 'menuUpdate') return
      this.reload()
    })
    MKEmitter.addListener('mkUpdateMenuList', this.reload)
  }
  /**
@@ -291,6 +296,7 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('mkUpdateMenuList', this.reload)
  }
  gotoDoc = () => {
@@ -305,10 +311,10 @@
  render () {
    const { mainMenu, editLevel } = this.props
    const { menulist } = this.state
    const { menulist, memberLevel, visible, loading } = this.state
    return (
      <header className={'sys-header-container ant-menu-dark ' + (['level2', 'level3', 'HS'].includes(editLevel) ? 'mask' : '')} id="main-header-container">
      <header className={'sys-header-container ant-menu-dark ' + (['level2', 'level3'].includes(editLevel) ? 'mask' : '')} id="main-header-container">
        <div className="header-logo"><img src={MainLogo} alt=""/></div>
        <div className="header-collapse">
          <MenuFoldOutlined/>
@@ -323,71 +329,77 @@
                </li>
              )
            })}
            {!editLevel || editLevel === 'HS' ?
              <li key="HS" onClick={this.enterEditManage} className={editLevel === 'HS' ? 'active' : ''}>
            {!editLevel ?
              <li key="HS" onClick={() => window.open('#/hs')}>
                <span>HS</span>
              </li> : null
            }
          </ul> : null
        }
        {editLevel === 'HS' ? <Button className="level4-close" type="primary" onClick={this.exitManage}>退出</Button> : null}
        {/* 进入编辑按钮 */}
        {!editLevel && menulist ? <EditOutlined onClick={this.enterEdit} className="edit-check" /> : null}
        {!editLevel && window.GLOB.systemType !== 'production' ?
          <div className="app-entrance entrance">
            <div className="icon"><AppstoreOutlined /></div>
            <div className="title">应用管理</div>
            <div className="detail">可创建及管理PC、pad及移动端等不同设备的应用,实现明科云APP、微信公众号、小程序等多平台的应用共享。</div>
            <Button type="primary" disabled={!(this.props.memberLevel >= 20)} title={this.props.memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/appmanage')}}>
              编辑
            </Button>
          </div> : null
        }
        {editLevel === 'HS' && window.GLOB.systemType === 'production' ?
          <div className="app-prod-entrance entrance">
            <div className="icon"><AppstoreOutlined /></div>
            <div className="title">应用管理</div>
            <div className="detail">可创建及管理PC、pad及移动端等不同设备的应用,实现明科云APP、微信公众号、小程序等多平台的应用共享。</div>
            <Button type="primary" disabled={!(this.props.memberLevel >= 20)} title={this.props.memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/appcheck')}}>
              查看
            </Button>
          </div> : null
        }
        {!editLevel ?
          <div className="api-entrance entrance">
            <div className="icon"><ApiOutlined /></div>
            <div className="title">接口调试</div>
            <div className="detail">可自动处理登录接口的参数加密,以及业务接口的签名计算,方便开发人员的接口测试工作。</div>
            <Button type="primary" disabled={!(this.props.memberLevel >= 20)} title={this.props.memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/interface')}}>
              编辑
            </Button>
          </div> : null
        }
        {!editLevel && window.GLOB.systemType !== 'production' && menulist ? <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <PlusOutlined onClick={() => this.setState({visible: true, loading: false})}/>
            <SwapOutlined onClick={this.enterEdit}/>
            <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId="0" Type="10"/></div>
          </div>
        } trigger="hover">
          <SettingOutlined className="edit-check"/>
        </Popover> : null}
        {/* window.btoa(window.encodeURIComponent(JSON.stringify({ MenuType: 'home', MenuId: 'home_page_id', MenuName: '首页' }))) */}
        {!editLevel && window.GLOB.systemType !== 'production' ?
        {window.GLOB.systemType !== 'production' ?
          <div className="home-entrance entrance">
            <div className="icon"><HomeOutlined /></div>
            <div className="title">首页</div>
            <div className="detail">基于自定义页面的首页设计,可实现灵活的元素配置及样式调整,展现当前系统的风格。</div>
            <Button type="primary" disabled={!(this.props.memberLevel >= 20)} title={this.props.memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/menudesign/JTdCJTIyTWVudVR5cGUlMjIlM0ElMjJob21lJTIyJTJDJTIyTWVudUlkJTIyJTNBJTIyaG9tZV9wYWdlX2lkJTIyJTJDJTIyTWVudU5hbWUlMjIlM0ElMjIlRTklQTYlOTYlRTklQTElQjUlMjIlN0Q=')}}>
            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/menudesign/JTdCJTIyTWVudVR5cGUlMjIlM0ElMjJob21lJTIyJTJDJTIyTWVudUlkJTIyJTNBJTIyaG9tZV9wYWdlX2lkJTIyJTJDJTIyTWVudU5hbWUlMjIlM0ElMjIlRTklQTYlOTYlRTklQTElQjUlMjIlN0Q=')}}>
              编辑
            </Button>
          </div> : null
        }
        <div className="api-entrance entrance">
          <div className="icon"><ApiOutlined /></div>
          <div className="title">接口调试</div>
          <div className="detail">可自动处理登录接口的参数加密,以及业务接口的签名计算,方便开发人员的接口测试工作。</div>
          <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/interface')}}>
            编辑
          </Button>
        </div>
        <div className="app-entrance entrance">
          <div className="icon"><AppstoreOutlined /></div>
          <div className="title">应用管理</div>
          <div className="detail">可创建及管理PC、pad及移动端等不同设备的应用,实现明科云APP、微信公众号、小程序等多平台的应用共享。</div>
          {window.GLOB.systemType !== 'production' ?
            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/appmanage')}}>
              编辑
            </Button> :
            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/appcheck')}}>
              查看
            </Button>
          }
        </div>
        {window.GLOB.systemType !== 'production' ? <div className="menu-entrance entrance">
          <div className="icon"><MenuOutlined /></div>
          <div className="title">菜单操作说明</div>
          <div className="detail">鼠标悬停 <SettingOutlined style={{color: '#1890ff'}}/> 可显示菜单的添加、排序(包括编辑、删除)与解冻功能,双击三级菜单可进入编辑窗口。</div>
          <Button type="primary" onClick={() => {window.open('#/main')}}>
            新窗口
          </Button>
        </div> : null}
        {/* 编辑菜单 */}
        {editLevel === 'level1' ? <EditMenu menulist={this.state.menulist} reload={this.reload} exitEdit={this.exitEdit}/> : null}
        {/* 头像、用户名 */}
        <Dropdown className="header-setting" overlay={
          <Menu className="header-dropdown">
            <Menu.Item key="switch">
              {this.state.dict['main.edit']}
              编辑
              <Switch size="small" style={{marginLeft: '7px'}} disabled={!!editLevel} checked={true} onChange={this.changeEditState} />
            </Menu.Item>
            <Menu.Item key="doc" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
            <Menu.Item key="doc" onClick={this.gotoDoc}>文档中心</Menu.Item>
            {options.sysType !== 'cloud' ? <Menu.Item style={{padding: 0}} key="verup">
              <VersionsUp />
            </Menu.Item> : null}
            <Menu.Item key="logout" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item>
            <Menu.Item key="logout" onClick={this.logout}>退出</Menu.Item>
          </Menu>
        }>
          <div style={{zIndex: 1, position: 'relative'}}>
@@ -397,6 +409,20 @@
            </span>
          </div>
        </Dropdown>
        <Modal
          title="添加菜单"
          visible={visible}
          onOk={this.addMemuSubmit}
          confirmLoading={loading}
          onCancel={() => this.setState({visible: false})}
          destroyOnClose
        >
          <MenuForm
            menu={null}
            inputSubmit={this.addMemuSubmit}
            wrappedComponentRef={(inst) => this.addMenuFormRef = inst}
          />
        </Modal>
      </header>
    )
  }
@@ -406,9 +432,7 @@
  return {
    menuTree: state.menuTree,
    mainMenu: state.mainMenu,
    editLevel: state.editLevel,
    permAction: state.permAction,
    memberLevel: state.memberLevel
    editLevel: state.editLevel
  }
}