king
2022-02-09 d59f518f466274b2caeb2e01c10c92deafe7c93b
src/components/header/index.jsx
@@ -4,7 +4,8 @@
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import moment from 'moment'
import { Dropdown, Menu, Icon, Modal, Form, notification, Switch, Input } from 'antd'
import { Dropdown, Menu, Modal, Form, notification, Switch, Input } from 'antd'
import { SearchOutlined, DownOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons'
import {
  toggleCollapse,
@@ -13,6 +14,7 @@
  initMenuPermission,
  logout
} from '@/store/action'
import asyncComponent from '@/utils/asyncComponent'
import Api from '@/api'
import MKEmitter from '@/utils/events.js'
import options from '@/store/options.js'
@@ -20,12 +22,12 @@
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 { confirm } = Modal
const { Search } = Input
const Resetpwd = asyncComponent(() => import('./resetpwd'))
const LoginForm = asyncComponent(() => import('./loginform'))
class Header extends Component {
  static propTpyes = {
@@ -38,6 +40,7 @@
    confirmLoading: false,
    userName: sessionStorage.getItem('User_Name'),
    logourl: window.GLOB.mainlogo,
    appVersion: window.GLOB.appVersion,
    loginVisible: false,
    loginLoading: false,
    avatar: Utils.getrealurl(sessionStorage.getItem('avatar')),
@@ -86,9 +89,14 @@
        if (result.status) {
          notification.success({
            top: 92,
            message: this.state.dict['main.password.resetsuccess'],
            message: '修改成功,请重新登录。',
            duration: 2
          })
          setTimeout(() => {
            sessionStorage.clear()
            this.props.logout()
            this.props.history.replace('/login')
          }, 2000)
        } else {
          notification.warning({
            top: 92,
@@ -135,31 +143,33 @@
    // 获取角色权限
    let roledefer = new Promise(resolve => {
      // edition_type 接口版本控制 ''、'Y'、'A'
      Api.getSystemConfig({
        func: 's_Get_TrdMenu_Role',
        edition_type: 'A',
        pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
      }).then(result => {
        let _permAction = {loaded: true} // 按钮权限
        if (result && result.status) {
          if (result.UserRoles_Menu) {
            result.UserRoles_Menu.forEach(menu => {
              if (!menu.MenuID) return
              _permAction[menu.MenuID] = true
      setTimeout(() => {
        Api.getSystemConfig({
          func: 's_Get_TrdMenu_Role',
          edition_type: 'A',
          pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
        }).then(result => {
          let _permAction = {loaded: true} // 按钮权限
          if (result && result.status) {
            if (result.UserRoles_Menu) {
              result.UserRoles_Menu.forEach(menu => {
                if (!menu.MenuID) return
                _permAction[menu.MenuID] = true
              })
            }
          } else if (result) {
            notification.error({
              top: 92,
              message: result.message,
              duration: 10
            })
          }
        } else if (result) {
          notification.error({
            top: 92,
            message: result.message,
            duration: 10
          })
        }
        this.props.initActionPermission(_permAction)
        resolve()
      })
          this.props.initActionPermission(_permAction)
          resolve()
        })
      }, 50)
    })
    // 获取主菜单参数
@@ -397,8 +407,14 @@
          sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
          sessionStorage.setItem('isEditState', 'true')
          this.setSystemFuncs()
          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}))))
          }
          this.setSystemFuncs()
          this.props.modifyMainMenu(null)
          this.props.history.replace('/design')
        } else {
          if (res.message.indexOf('密码错误') > -1) {
@@ -621,14 +637,14 @@
  verup = () => {
    confirm({
      title: '版本升级',
      title: '页面更新',
      content: '重新加载应用信息',
      onOk() {
        return new Promise(resolve => {
          if (!window.GLOB.WebSql && !window.GLOB.IndexDB) {
            notification.warning({
              top: 92,
              message: '升级失败,请刷新页面重试!',
              message: '更新失败,请刷新页面重试!',
              duration: 2
            })
            resolve()
@@ -637,7 +653,7 @@
            setTimeout(() => {
              notification.success({
                top: 92,
                message: '升级成功!',
                message: '更新成功!',
                duration: 2
              })
              resolve()
@@ -649,10 +665,15 @@
    })
  }
  about = () => {
    Modal.success({
      title: '系统版本v' + this.state.appVersion
    })
  }
  render () {
    const { mainMenu, collapse } = this.props
    const { thdMenuList, searchkey, debug, menulist, navBar, menuType } = this.state
    const { thdMenuList, searchkey, debug, menulist, navBar, menuType, appVersion } = this.state
    const menu = (
      <Menu className="header-dropdown">
@@ -668,8 +689,11 @@
        </Menu.SubMenu> : null}
        <Menu.Item key="doc" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</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>
    )
@@ -678,7 +702,7 @@
      <header className="header-container ant-menu-dark" id="main-header-container">
        <div className={'header-logo ' + (collapse && navBar !== 'topmenu' ? 'collapse' : '')}><img src={this.state.logourl} alt=""/></div>
        <div className={'header-collapse ' + (collapse && navBar !== 'topmenu' ? 'collapse' : '')}>
          {navBar !== 'topmenu' ? <Icon type={collapse ? 'menu-unfold' : 'menu-fold'} onClick={this.handleCollapse}/> : null}
          {navBar !== 'topmenu' ? (collapse ? <MenuUnfoldOutlined onClick={this.handleCollapse}/> : <MenuFoldOutlined onClick={this.handleCollapse}/>) : null}
        </div>
        {/* 正常菜单 */}
        {navBar !== 'topmenu' && menulist ?
@@ -778,7 +802,7 @@
          <div>
            <img src={this.state.avatar || avatar} alt=""/>
            <span>
              <span className="username">{this.state.userName}</span> <Icon type="down" />
              <span className="username">{this.state.userName}</span> <DownOutlined />
            </span>
          </div>
        </Dropdown>
@@ -815,7 +839,7 @@
              </div>
            </div>
          } trigger={['click']} className="search-menu" placement="bottomRight" onVisibleChange={this.dropdownMenuChange}>
            <Icon className="search-menu" type="search" />
            <SearchOutlined className="search-menu" />
          </Dropdown> : null
        }
        {/* 修改密码 */}
@@ -849,8 +873,7 @@
const mapStateToProps = (state) => {
  return {
    collapse: state.collapse,
    mainMenu: state.mainMenu,
    permAction: state.permAction,
    mainMenu: state.mainMenu
  }
}