king
2023-08-04 051981a2211bb86f88a6d68f2e29816f8caeac20
src/components/header/index.jsx
@@ -3,7 +3,6 @@
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import moment from 'moment'
import { Dropdown, Menu, Modal, notification, Switch, Input } from 'antd'
import { SearchOutlined, DownOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons'
@@ -12,20 +11,20 @@
  modifyMainMenu,
  logout
} from '@/store/action'
import asyncComponent from '@/utils/asyncSpinComponent'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import asyncComponent from '@/utils/asyncComponent'
import Api from '@/api'
import MKEmitter from '@/utils/events.js'
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 './index.scss'
const { confirm } = Modal
const { Search } = Input
const Resetpwd = asyncComponent(() => import('./resetpwd'))
const LoginForm = asyncComponent(() => import('./loginform'))
const Resetpwd = asyncComponent(() => import('@/components/resetPassword'))
const QrCode = asyncComponent(() => import('@/components/qrcode'))
const LoginForm = asyncSpinComponent(() => import('./loginform'))
class Header extends Component {
  static propTpyes = {
@@ -33,22 +32,16 @@
  }
  state = {
    menulist: null, // 一级菜单
    visible: false, // 修改密码模态框
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    confirmLoading: false,
    userName: '',
    fullName: '',
    logourl: window.GLOB.mainlogo,
    appVersion: window.GLOB.appVersion,
    loginVisible: false,
    loginLoading: false,
    avatar: Utils.getrealurl(sessionStorage.getItem('avatar')),
    systems: [],
    searchkey: '',
    thdMenuList: [],
    debug: sessionStorage.getItem('debug') === 'true',
    navBar: ['linkage_navigation', 'linkage', 'menu_board', 'menu_board_navigation'].includes(window.GLOB.navBar) ? 'topmenu' : '',
    menuType: window.GLOB.navBar
    debug: sessionStorage.getItem('debug') === 'true'
  }
  handleCollapse = () => {
@@ -59,60 +52,12 @@
  changePassword = () => {
    // 点击修改密码,显示弹窗
    this.setState({
      visible: true
    })
  }
  resetPwdSubmit = () => {
    if (!this.formRef) return
    this.formRef.handleConfirm().then(res => {
      this.setState({
        confirmLoading: true
      })
      let _param = {
        func: 's_PwdUpt',
        LText: `select '${res.originpwd}','${res.password}'`
      }
      _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')          // 时间戳
      _param.LText = Utils.formatOptions(_param.LText)                   // 关键字符替换,base64加密
      _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)   // md5密钥
      Api.getSystemConfig(_param).then(result => {
        this.setState({
          visible: !result.status,
          confirmLoading: false
        })
        if (result.status) {
          notification.success({
            top: 92,
            message: '修改成功,请重新登录。',
            duration: 2
          })
          setTimeout(() => {
            sessionStorage.clear()
            this.props.logout()
            this.props.history.replace('/login')
          }, 2000)
        } else {
          notification.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
        }
      })
    }, () => {})
  }
  handleCancel = () => {
    // 取消时关闭修改密码模态框,清空表单数据
    this.setState({
      visible: false
    MKEmitter.emit('resetpassword', () => {
      setTimeout(() => {
        sessionStorage.clear()
        this.props.logout()
        this.props.history.replace('/login')
      }, 2000)
    })
  }
@@ -120,8 +65,10 @@
    // 退出登录
    let _this = this
    confirm({
      title: this.state.dict['main.logout.hint'],
      title: '您确定要退出吗?',
      content: '',
      okText: '确定',
      cancelText: '取消',
      onOk() {
        sessionStorage.clear()
        _this.props.logout()
@@ -133,8 +80,10 @@
  changeMenu (value) {
    // 主菜单切换
    if (value.OpenType === 'outpage' && value.linkUrl) {
      window.open(value.linkUrl)
    if (value.OpenType === 'newpage') {
      window.open(value.src)
    } else if (value.OpenType === 'newtab') {
      MKEmitter.emit('modifyTabs', value)
    } else if (value.OpenType === 'menu') {
      this.props.modifyMainMenu(value)
    }
@@ -186,16 +135,9 @@
      window.GLOB.mkThdMenus = [...thdMenuList, {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'}]
      if (_menu) { // 延时打开,防止标签组未完成加载
        setTimeout(() => {
          if (this.state.navBar === 'topmenu' && this.state.menuType !== 'menu_board_navigation') {
            MKEmitter.emit('modifyTabs', _menu, 'replace')
          } else {
            MKEmitter.emit('modifyTabs', _menu, 'plus')
          }
        }, 200)
      if (_menu) {
        this.openTab(_menu, 0)
      }
      MKEmitter.emit('mkMenuLoaded')
    })
    
    // 获取角色权限, edition_type 接口版本控制 ''、'Y'、'A'
@@ -222,15 +164,31 @@
          })
        }
        MKEmitter.emit('mkActionLoaded')
        window.GLOB.mkActions = _permAction
      })
    }, 50)
  }
  openTab = (menu, times) => {
    if (times > 50) return
    times++
    let tabgroup = document.getElementById('mk-tabgroup-wrap')
    if (window.GLOB.mkActions.loaded && tabgroup) {
      MKEmitter.emit('modifyTabs', menu)
    } else {
      setTimeout(() => {
        this.openTab(times)
      }, 200)
    }
  }
  getMenulist = (result) => {
    let thdMenuList = []
    let menulist = []
    let names = new Map()
    let doublenames = new Map()
    result.fst_menu && result.fst_menu.forEach(fst => {
      let fstItem = {
        MenuID: fst.MenuID,
@@ -243,8 +201,13 @@
          let PageParam = JSON.parse(fst.PageParam)
          if (PageParam.OpenType === 'outpage' && PageParam.linkUrl) {
            fstItem.OpenType = 'outpage'
            fstItem.linkUrl = PageParam.linkUrl
            fstItem.OpenType = 'newpage'
            fstItem.src = PageParam.linkUrl
            if (/#\/iframe\//.test(fstItem.src)) {
              fstItem.src = fstItem.src.replace(/@loginuid@/ig, sessionStorage.getItem('LoginUID'))
              fstItem.type = 'iframe'
              fstItem.OpenType = 'newtab'
            }
          }
        } catch (e) {}
      }
@@ -274,6 +237,7 @@
                ParentId: snd.MenuID,
                MenuID: trd.MenuID,
                MenuName: trd.MenuName,
                menu_name: trd.MenuName,
                ParentNames: [fst.MenuName, snd.MenuName],
                MenuNo: trd.MenuNo,
                EasyCode: trd.EasyCode,
@@ -286,18 +250,33 @@
                try {
                  let PageParam = JSON.parse(trd.PageParam)
                  trdItem.type = PageParam.Template || trdItem.type
                  trdItem.OpenType = PageParam.OpenType || trdItem.OpenType
                  trdItem.hidden = PageParam.hidden || trdItem.hidden
                  trdItem.type = PageParam.Template || 'CommonTable'
                  trdItem.OpenType = PageParam.OpenType || 'newtab'
                  trdItem.hidden = PageParam.hidden || 'false'
                  if (trdItem.type === 'NewPage') {
                    trdItem.OpenType = 'newpage'
                    trdItem.src = PageParam.url || ''
                    if (/#\/iframe\//.test(trdItem.src)) {
                      trdItem.src = trdItem.src.replace(/@loginuid@/ig, sessionStorage.getItem('LoginUID'))
                      trdItem.type = 'iframe'
                      trdItem.OpenType = 'newtab'
                    }
                  } else if (trdItem.OpenType === 'view') {
                    trdItem.OpenType = 'newpage'
                    trdItem.src = '#/view/' + trd.MenuID
                  } else {
                    trdItem.src = '#/tab/' + trd.MenuID
                  }
                } catch (e) {}
              } else {
                trdItem.src = '#/tab/' + trd.MenuID
              }
              if (trdItem.type !== 'NewPage') {
                trdItem.src = '#/tab/' + trd.MenuID
              if (names.has(trdItem.menu_name)) {
                doublenames.set(trdItem.menu_name, true)
              } else {
                names.set(trdItem.menu_name, true)
              }
              thdMenuList.push(trdItem)
@@ -315,6 +294,13 @@
      menulist.push(fstItem)
    })
    thdMenuList = thdMenuList.map(item => {
      if (doublenames.has(item.menu_name)) {
        item.menu_name += '(' + item.ParentNames.join('-') + ')'
      }
      return item
    })
    return { menulist, thdMenuList }
  }
@@ -328,10 +314,6 @@
        loginVisible: true
      })
    } else {
      sessionStorage.setItem('role_id', sessionStorage.getItem('cloudRole_id'))
      sessionStorage.setItem('dataM', sessionStorage.getItem('cloudDataM'))
      sessionStorage.setItem('isEditState', 'true')
      this.props.modifyMainMenu(null)
      this.props.history.replace('/design')
@@ -372,14 +354,11 @@
          sessionStorage.setItem('cloudDataM', res.dataM ? 'true' : '')
          sessionStorage.setItem('cloudRole_id', res.role_id || '')
          sessionStorage.setItem('role_id', res.role_id || '')
          sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
          sessionStorage.setItem('isEditState', 'true')
          let _url = window.location.href.split('#')[0] + 'cloud'
          if (param.remember) {
            let _url = window.location.href.split('#')[0] + 'cloud'
            localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({time: new Date().getTime(), username: param.username, password: param.password}))))
          } else {
            localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({time: new Date().getTime(), username: param.username, password: ''}))))
          }
          this.props.modifyMainMenu(null)
@@ -482,19 +461,22 @@
  componentDidMount () {
    // 获取系统的版本信息,延时查询
    setTimeout(() => {
      Api.getAppVersion().then(() => {}, () => {})
      Api.getAppVersion()
    }, 1000)
    // Api.genericInterface({
    //   func: 's_get_fcc_account_data',
    //   fcc_date: '2022-03-01',
    //   search_type: ''
    // }).then(res => {
    // })
    // sessionStorage 跨页面共享
    window.addEventListener('storage', (e) => {
      if (e.key === 'getSessionStorage' && e.newValue === window.GLOB.appkey) {
        localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage))
      } else if (e.key === 'getSysPermission' && e.newValue === window.GLOB.appkey) {
        localStorage.setItem('sysPermissions', JSON.stringify({mkThdMenus: window.GLOB.mkThdMenus, mkActions: window.GLOB.mkActions}))
      } else if (e.key === 'menuUpdate') {
        let menuId = e.newValue.split(',')[1]
        if (menuId) {
          Api.getAppVersion(menuId).then(() => {
            MKEmitter.emit('reloadMenuView', menuId)
          })
        }
      }
    })
  }
@@ -524,20 +506,16 @@
  changeVerMenu(menu, type) {
    if (type === 'first') {
      if (menu.OpenType === 'outpage' && menu.linkUrl) {
        window.open(menu.linkUrl)
      } else if (menu.OpenType === 'menu') {
      if (menu.OpenType === 'newpage') {
        window.open(menu.src)
      } else if (menu.OpenType === 'newtab') {
        MKEmitter.emit('modifyTabs', menu)
      }
    } else {
      if (menu.OpenType === 'newpage' || menu.OpenType === 'NewPage') { // NewPage为打开外部页面地址,newpage为打开系统菜单
      if (menu.OpenType === 'newpage') {
        window.open(menu.src)
      } else if (menu.OpenType === 'blank') {
        MKEmitter.emit('modifyTabs', menu, 'replace')
      } else if (this.state.navBar === 'topmenu' && this.state.menuType !== 'menu_board_navigation') {
        MKEmitter.emit('modifyTabs', menu, 'replace')
      } else {
        MKEmitter.emit('modifyTabs', menu, 'plus')
        MKEmitter.emit('modifyTabs', menu)
      }
  
      if (window.GLOB.systemType === 'production') {
@@ -552,7 +530,7 @@
      content: '重新加载应用信息',
      onOk() {
        return new Promise(resolve => {
          if (!window.GLOB.WebSql && !window.GLOB.IndexDB) {
          if (!window.GLOB.IndexDB) {
            notification.warning({
              top: 92,
              message: '更新失败,请刷新页面重试!',
@@ -561,6 +539,7 @@
            resolve()
          } else {
            Api.updateAppVersion()
            Api.delCacheConfig('all')
            setTimeout(() => {
              notification.success({
                top: 92,
@@ -578,51 +557,65 @@
  about = () => {
    Modal.success({
      title: '系统版本v' + this.state.appVersion
      title: '系统版本v' + window.GLOB.appVersion
    })
  }
  wxnotice = () => {
    Modal.success({
      className: 'mk-wx-notice',
      title: <QrCode card={{qrWidth: 320, color: '#000000'}} value={window.GLOB.baseurl + 'mob/wxnotice.html?userid=' + sessionStorage.getItem('UserID') + '&loginuid=' + sessionStorage.getItem('LoginUID')}/>,
      okText: '关闭'
    })
  }
  changeToHome = () => {
    if (!['linkage', 'menu_board'].includes(window.GLOB.navBar)) return
    MKEmitter.emit('modifyTabs', {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'}, 'replace')
    MKEmitter.emit('modifyTabs', {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'})
  }
  render () {
    const { mainMenu, collapse } = this.props
    const { thdMenuList, searchkey, debug, menulist, navBar, menuType, appVersion } = this.state
    const { thdMenuList, searchkey, debug, menulist } = this.state
    const navBar = window.GLOB.navBar
    const menu = (
      <Menu className="header-dropdown">
        {debug && <Menu.Item key="switch">
          {this.state.dict['main.edit']}
          编辑
          <Switch size="small" style={{marginLeft: '7px'}} checked={false} onChange={this.changeEditState} />
        </Menu.Item>}
        <Menu.Item key="password" onClick={this.changePassword}>{this.state.dict['main.password']}</Menu.Item>
        <Menu.Item key="password" onClick={this.changePassword}>修改密码</Menu.Item>
        {this.state.systems.length ? <Menu.SubMenu style={{minWidth: '110px'}} title="切换系统">
          {this.state.systems.map((system, index) => (
            <Menu.Item style={{minWidth: '100px', lineHeight: '30px'}} key={'sub' + index} onClick={() => {this.changeSystem(system)}}> {system.AppName} </Menu.Item>
          ))}
        </Menu.SubMenu> : null}
        <Menu.Item key="doc" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
        <Menu.Item key="doc" onClick={this.gotoDoc}>文档中心</Menu.Item>
        <Menu.Item key="verup" onClick={this.verup}>
          页面更新
        </Menu.Item>
        {appVersion ? <Menu.Item key="version" onClick={this.about}>
        {window.GLOB.WXNotice ? <Menu.Item key="wxnotice" onClick={this.wxnotice}>
          微信消息
        </Menu.Item> : null}
        {window.GLOB.appVersion ? <Menu.Item key="version" onClick={this.about}>
          关于
        </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>
    )
    return (
      <header className="header-container ant-menu-dark" id="main-header-container">
        <div className={'header-logo ' + (collapse && navBar !== 'topmenu' ? 'collapse' : '')} onClick={this.changeToHome}><img src={this.state.logourl} alt=""/></div>
        {navBar !== 'topmenu' ? <div className={'header-collapse ' + (collapse ? 'collapse' : '')}>
        {navBar === 'shutter' ?
          <div className={'header-logo ' + (collapse ? 'collapse' : '')}><img src={this.state.logourl} alt=""/></div> :
          <div className="header-logo" onClick={this.changeToHome}><img src={this.state.logourl} alt=""/></div>}
        {navBar === 'shutter' ? <div className={'header-collapse ' + (collapse ? 'collapse' : '')}>
          {collapse ? <MenuUnfoldOutlined onClick={this.handleCollapse}/> : <MenuFoldOutlined onClick={this.handleCollapse}/>}
        </div> : <div style={{width: '20px', height: '45px'}}></div>}
        {/* 正常菜单 */}
        {navBar !== 'topmenu' && menulist ?
        {navBar === 'shutter' && menulist ?
          <ul className="header-menu">{
            menulist.map(item => {
              return (
@@ -633,7 +626,7 @@
            })}
          </ul> : null
        }
        {navBar === 'topmenu' && menuType !== 'menu_board' && menuType !== 'menu_board_navigation' && menulist ?
        {(navBar === 'linkage' || navBar === 'linkage_navigation') && menulist ?
          <ul className="header-menu vertical-menu">{
            menulist.map(item => {
              if (item.children && item.children.length > 0) {
@@ -676,7 +669,7 @@
            })}
          </ul> : null
        }
        {navBar === 'topmenu' && (menuType === 'menu_board' || menuType === 'menu_board_navigation') && menulist ?
        {(navBar === 'menu_board' || navBar === 'menu_board_navigation') && menulist ?
          <ul className="header-menu vertical-menu">{
            menulist.map(item => {
              if (item.children && item.children.length > 0) {
@@ -739,12 +732,12 @@
                        option.MenuNo.toLowerCase().indexOf(searchkey.toLowerCase()) >= 0 ||
                        option.EasyCode.toLowerCase().indexOf(searchkey.toLowerCase()) >= 0
                      ) {
                        return <Menu.Item key={option.MenuID} onClick={() => this.changeVerMenu(option)}>{option.MenuName}</Menu.Item>
                        return <Menu.Item key={option.MenuID} onClick={() => this.changeVerMenu(option)}>{option.menu_name}</Menu.Item>
                      } else {
                        return null
                      }
                    }
                    return <Menu.Item key={option.MenuID} onClick={() => this.changeVerMenu(option)}>{option.MenuName}</Menu.Item>
                    return <Menu.Item key={option.MenuID} onClick={() => this.changeVerMenu(option)}>{option.menu_name}</Menu.Item>
                  })}
                </Menu>
              </div>
@@ -762,29 +755,20 @@
            </span>
          </div>
        </Dropdown>
        {/* 修改密码 */}
        <Modal
          title={this.state.dict['main.password']}
          visible={this.state.visible}
          onOk={this.resetPwdSubmit}
          confirmLoading={this.state.confirmLoading}
          onCancel={this.handleCancel}
          destroyOnClose
        >
          <Resetpwd dict={this.state.dict} wrappedComponentRef={(inst) => this.formRef = inst} resetPwdSubmit={this.resetPwdSubmit}/>
        </Modal>
        {/* 编辑状态登录 */}
        <Modal
          title={this.state.dict['main.login.develop']}
          title="登录开发机"
          visible={this.state.loginVisible}
          onOk={this.loginSubmit}
          width={'430px'}
          confirmLoading={this.state.loginLoading}
          onCancel={() => {this.setState({ loginVisible: false, loginLoading: false })}}
          destroyOnClose
        >
          >
          <LoginForm handleSubmit={() => this.loginSubmit()} wrappedComponentRef={(inst) => this.loginRef = inst}/>
        </Modal>
        {/* 修改密码 */}
        <Resetpwd />
      </header>
    )
  }