king
2020-08-20 3683e1475e8d74f690172a468518d88d91a69ccc
src/components/header/index.jsx
@@ -4,7 +4,7 @@
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import moment from 'moment'
import {Dropdown, Menu, Icon, Modal, Form, notification, Switch, Button, Input } from 'antd'
import { Dropdown, Menu, Icon, Modal, Form, notification, Switch, Button, Input, Badge } from 'antd'
import asyncComponent from '@/utils/asyncComponent'
import {
@@ -55,7 +55,9 @@
    avatar: avatar,
    systems: [],
    searchkey: '',
    thdMenuList: []
    thdMenuList: [],
    oriVersion: '',
    newVersion: ''
  }
  handleCollapse = () => {
@@ -633,10 +635,54 @@
        })
      }
    })
    // 获取系统的版本信息
    new Promise((resolve, reject) => {
      Api.getAppVersion(resolve, reject)
    }).then(res => {
      this.setState({
        oriVersion: res.oldVersion,
        newVersion: res.newVersion
      })
    })
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  verup = () => {
    const { oriVersion, newVersion } = this.state
    const _this = this
    confirm({
      title: this.state.dict['main.verup'],
      content: `最新版本${newVersion},当前版本${oriVersion}`,
      okText: this.state.dict['main.confirm'],
      cancelText: this.state.dict['main.cancel'],
      onOk() {
        return new Promise(resolve => {
          Api.updateAppVersion(newVersion).then(res => {
            if (res.status) {
              notification.success({
                top: 92,
                message: '升级成功!',
                duration: 2
              })
              _this.setState({oriVersion: newVersion})
            } else {
              notification.warning({
                top: 92,
                message: '升级失败,请刷新页面重试!',
                duration: 2
              })
            }
            resolve()
          })
        })
      },
      onCancel() {}
    })
  }
  gotoDoc = () => {
@@ -650,22 +696,25 @@
  }
  render () {
    const { thdMenuList, searchkey } = this.state
    const { thdMenuList, searchkey, oriVersion, newVersion } = this.state
    const menu = (
      <Menu overlayclassname="header-dropdown">
        {this.props.debug && <Menu.Item key="0">
      <Menu className="header-dropdown">
        {this.props.debug && <Menu.Item key="switch">
          {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['main.password']}</Menu.Item> : null}
        {!this.props.editState ? <Menu.Item key="password" 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.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
        <Menu.Item key="3" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item>
        <Menu.Item key="doc" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
        {oriVersion ? <Menu.Item key="verup" onClick={this.verup}>
          <Badge dot={oriVersion !== newVersion}>{this.state.dict['main.verup']}</Badge>
        </Menu.Item> : null}
        <Menu.Item key="logout" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item>
      </Menu>
    )