king
2023-03-11 34e7681fd12b1c4e4994d3bea1a553870e10bc50
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'
@@ -16,15 +15,13 @@
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 Resetpwd = asyncComponent(() => import('@/components/resetPassword'))
const LoginForm = asyncComponent(() => import('./loginform'))
class Header extends Component {
@@ -33,9 +30,6 @@
  }
  state = {
    menulist: null, // 一级菜单
    visible: false, // 修改密码模态框
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    confirmLoading: false,
    userName: '',
    fullName: '',
    logourl: window.GLOB.mainlogo,
@@ -57,60 +51,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
          })
    MKEmitter.emit('resetpassword', () => {
          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
    })
  }
@@ -118,8 +64,10 @@
    // 退出登录
    let _this = this
    confirm({
      title: this.state.dict['main.logout.hint'],
      title: '您确定要退出吗?',
      content: '',
      okText: '确定',
      cancelText: '取消',
      onOk() {
        sessionStorage.clear()
        _this.props.logout()
@@ -225,6 +173,8 @@
  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,
@@ -268,6 +218,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,
@@ -296,6 +247,12 @@
              trdItem.OpenType = trdItem.OpenType.toLowerCase() // NewPage为打开外部页面地址
              if (names.has(trdItem.menu_name)) {
                doublenames.set(trdItem.menu_name, true)
              } else {
                names.set(trdItem.menu_name, true)
              }
              thdMenuList.push(trdItem)
              return trdItem
@@ -309,6 +266,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 }
@@ -594,23 +558,23 @@
    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}>
          关于
        </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>
    )
@@ -740,12 +704,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>
@@ -763,20 +727,9 @@
            </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'}
@@ -786,6 +739,8 @@
        >
          <LoginForm handleSubmit={() => this.loginSubmit()} wrappedComponentRef={(inst) => this.loginRef = inst}/>
        </Modal>
        {/* 修改密码 */}
        <Resetpwd />
      </header>
    )
  }