king
2020-07-16 9a82bce9cf0ed4a51c1b0b0669eaa38cedbace07
src/components/header/index.jsx
@@ -16,21 +16,22 @@
  resetEditState,
  resetEditLevel,
  initPermission,
  modifyDataManager,
  initActionPermission,
  initMenuPermission,
  logout
} from '@/store/action'
import Api from '@/api'
import options from '@/store/options.js'
import zhCN from '@/locales/zh-CN/header.js'
import enUS from '@/locales/en-US/header.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 Resetpwd from './resetpwd'
import LoginForm from './loginform'
import './index.scss'
const EditMenu = asyncComponent(() => import('./editmenu'))
const EditMenu = asyncComponent(() => import('@/templates/headerconfig'))
const { confirm } = Modal
const { Search } = Input
@@ -45,7 +46,7 @@
  state = {
    menulist: null, // 一级菜单
    visible: false, // 修改密码模态框
    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    confirmLoading: false,
    userName: sessionStorage.getItem('User_Name'),
    logourl: window.GLOB.mainlogo,
@@ -100,7 +101,7 @@
      })
      notification.success({
        top: 92,
        message: this.state.dict['header.password.resetsuccess'],
        message: this.state.dict['main.password.resetsuccess'],
        duration: 2
      })
    } else {
@@ -126,10 +127,10 @@
    // 退出登录
    let _this = this
    confirm({
      title: this.state.dict['header.logout.hint'],
      title: this.state.dict['main.logout.hint'],
      content: '',
      okText: this.state.dict['header.confirm'],
      cancelText: this.state.dict['header.cancel'],
      okText: this.state.dict['main.confirm'],
      cancelText: this.state.dict['main.cancel'],
      onOk() {
        sessionStorage.clear()
        _this.props.logout()
@@ -154,9 +155,12 @@
  async loadmenu () {
    // 获取主菜单
    let _param = {func: 'sPC_Get_MainMenu', systemType: options.systemType}
    let _param = {func: 'sPC_Get_MainMenu', systemType: options.sysType}
    if (sessionStorage.getItem('isEditState') === 'true') { // 编辑状态时,获取一级菜单,增加参数debug
      _param.debug = 'Y'
    }
    if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
      _param.linkurl = window.GLOB.linkurl
    }
    let result = await Api.getSystemConfig(_param)
@@ -196,6 +200,10 @@
        }),
        systems: result.Systems.filter(sys => sys.LinkUrl1 && sys.AppKey !== window.GLOB.appkey)
      })
      if (result.dataM) {
        this.props.modifyDataManager(true)
      }
    } else {
      notification.error({
        top: 92,
@@ -236,7 +244,12 @@
    
    // 获取主菜单参数
    let promiseMenu = new Promise(resolve => {
      Api.getSystemConfig({func: 'sPC_Get_MainMenu', systemType: options.systemType}).then(result => {
      let _param = {func: 'sPC_Get_MainMenu', systemType: options.sysType}
      if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
        _param.linkurl = window.GLOB.linkurl
      }
      Api.getSystemConfig(_param).then(result => {
        let mainMenu = null
        if (result && result.status) {
          if (result.debug === 'true') { // 是否为debug模式,即可复制菜单参数
@@ -270,6 +283,10 @@
            }),
            systems: result.Systems.filter(sys => sys.LinkUrl1 && sys.AppKey !== window.GLOB.appkey)
          })
          if (result.dataM) {
            this.props.modifyDataManager(true)
          }
        } else if (result) {
          notification.error({
            top: 92,
@@ -330,8 +347,8 @@
        _userName = sessionStorage.getItem('CloudUserName')
      }
      if (window.GLOB.systemType === 'official' && state) {
        this.props.resetEditLevel('level4')
      if (window.GLOB.systemType === 'production' && state) {
        this.props.resetEditLevel('HS')
        this.props.modifyMainMenu({
          MenuID: 'systemManageView'
        })
@@ -343,7 +360,7 @@
        this.props.resetEditState(state)
        return
      } else if (window.GLOB.systemType === 'official' && !state) {
      } else if (window.GLOB.systemType === 'production' && !state) {
        this.props.resetEditLevel(false)
        this.props.modifyMainMenu(menulist[0] || '')
@@ -366,7 +383,7 @@
      this.props.resetEditState(state)
    }
    if (state && this.props.sysRoles.length === 0 && this.props.permFuncField.length === 0 && window.GLOB.systemType !== 'official') {
    if (state && this.props.sysRoles.length === 0 && this.props.permFuncField.length === 0 && window.GLOB.systemType !== 'production') {
      Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
        if (res.status) {
          let _permFuncField = []
@@ -417,8 +434,8 @@
            _avatar = Utils.getrealurl(res.icon) // 头像
          }
          if (window.GLOB.systemType === 'official') {
            this.props.resetEditLevel('level4')
          if (window.GLOB.systemType === 'production') {
            this.props.resetEditLevel('HS')
            this.props.modifyMainMenu({
              MenuID: 'systemManageView'
            })
@@ -466,9 +483,9 @@
  enterEditManage = () => {
    const { editLevel } = this.props
    if (editLevel === 'level4')  return
    if (editLevel === 'HS')  return
    this.props.resetEditLevel('level4')
    this.props.resetEditLevel('HS')
    this.props.modifyMainMenu({
      MenuID: 'systemManageView'
    })
@@ -478,7 +495,7 @@
   * @description 退出管理界面菜单
   */
  exitManage = () => {
    if (window.GLOB.systemType === 'official') { // 正式系统版本升级后,页面刷新
    if (window.GLOB.systemType === 'production') { // 正式系统版本升级后,页面刷新
      window.location.reload()
      return
    }
@@ -616,22 +633,33 @@
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  gotoDoc = () => {
    if (options.sysType === 'local' && window.GLOB.mainSystemApi) {
      let ssodomain = window.GLOB.mainSystemApi.replace('/webapi/dostars', '')
      let url = `${ssodomain}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`
      window.open(url)
    } else if (options.sysType === 'SSO' || options.sysType === 'cloud') {
      window.open(`${window.location.href.replace(/\/index.html(.*)|\/#(.*)/ig, '')}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`)
    }
  }
  render () {
    const { thdMenuList, searchkey } = this.state
    const menu = (
      <Menu overlayclassname="header-dropdown">
        {this.props.debug && <Menu.Item key="0">
          {this.state.dict['header.edit']}
          {this.state.dict['main.edit']}
          <Switch size="small" className="edit-switch" disabled={!!this.props.editLevel} checked={this.props.editState} onChange={this.changeEditState} />
        </Menu.Item>}
        {!this.props.editState ? <Menu.Item key="1" onClick={this.changePassword}>{this.state.dict['header.password']}</Menu.Item> : null}
        {!this.props.editState ? <Menu.Item key="1" onClick={this.changePassword}>{this.state.dict['main.password']}</Menu.Item> : null}
        {/* {this.state.systems.length > 0 ? <Menu.SubMenu title="切换系统">
          {this.state.systems.map((system, index) => (
            <Menu.Item className="header-subSystem" key={'sub' + index} onClick={() => {this.changeSystem(system)}}> {system.AppName} </Menu.Item>
          ))}
        </Menu.SubMenu> : null} */}
        <Menu.Item key="2" onClick={this.logout}>{this.state.dict['header.logout']}</Menu.Item>
        <Menu.Item key="2" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
        <Menu.Item key="3" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item>
      </Menu>
    )
@@ -651,16 +679,19 @@
                </li>
              )
            })}
            {this.props.editState && (!this.props.editLevel || this.props.editLevel === 'level4') ?
              <li key="HS" onClick={this.enterEditManage} className={this.props.editLevel === 'level4' ? 'active' : ''}>
            {this.props.editState && (!this.props.editLevel || this.props.editLevel === 'HS') ?
              <li key="HS" onClick={this.enterEditManage} className={this.props.editLevel === 'HS' ? 'active' : ''}>
                <span>HS</span>
              </li> : null
            }
          </ul> : null
        }
        {this.props.editLevel === 'level4' ? <Button className="level4-close" type="primary" onClick={this.exitManage}>退出</Button> : null}
        {this.props.editLevel === 'HS' ? <Button className="level4-close" type="primary" onClick={this.exitManage}>退出</Button> : null}
        {/* 进入编辑按钮 */}
        {this.props.editState && !this.props.editLevel ? <Icon onClick={this.enterEdit} className="edit-check" type="edit" /> : null}
        {/* {this.props.editState && !this.props.editLevel && options.sysType === 'local' && window.GLOB.systemType !== 'production' ?
          <a href="#/mobmanage" target="_blank" className="mobile" type="edit"> 应用管理 <Icon type="arrow-right" /></a> : null
        } */}
        {/* 编辑菜单 */}
        {this.props.editLevel === 'level1' ? <EditMenu menulist={this.state.menulist} reload={this.reload} exitEdit={this.exitEdit}/> : null}
        {/* 头像、用户名 */}
@@ -710,9 +741,9 @@
        }
        {/* 修改密码 */}
        <Modal
          title={this.state.dict['header.password']}
          okText={this.state.dict['header.confirm']}
          cancelText={this.state.dict['header.cancel']}
          title={this.state.dict['main.password']}
          okText={this.state.dict['main.confirm']}
          cancelText={this.state.dict['main.cancel']}
          visible={this.state.visible}
          onOk={this.resetPwdSubmit}
          confirmLoading={this.state.confirmLoading}
@@ -723,9 +754,9 @@
        </Modal>
        {/* 编辑状态登录 */}
        <Modal
          title={this.state.dict['header.login.develop']}
          okText={this.state.dict['header.confirm']}
          cancelText={this.state.dict['header.cancel']}
          title={this.state.dict['main.login.develop']}
          okText={this.state.dict['main.confirm']}
          cancelText={this.state.dict['main.cancel']}
          visible={this.state.loginVisible}
          onOk={this.loginSubmit}
          width={'430px'}
@@ -764,6 +795,7 @@
    initActionPermission: (permRoles, permAction) => dispatch(initActionPermission(permRoles, permAction)),
    initPermission: (sysRoles, permFuncField) => dispatch(initPermission(sysRoles, permFuncField)),
    initMenuPermission: (permMenus) => dispatch(initMenuPermission(permMenus)),
    modifyDataManager: (dataManager) => dispatch(modifyDataManager(dataManager)),
    resetState: () => dispatch(resetState()),
    resetDebug: () => dispatch(resetDebug()),
    logout: () => dispatch(logout())