king
2024-06-21 2bccb9ec7bdefe23292a22bc153463cfa1479a49
src/views/mkiframe/index.jsx
@@ -3,6 +3,8 @@
import Api from '@/api'
import asyncComponent from '@/utils/asyncLoadComponent'
import MKEmitter from '@/utils/events.js'
import ImgScale from '@/components/imgScale'
import './index.scss'
const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
@@ -16,10 +18,68 @@
    type: 'CustomPage'
  }
  UNSAFE_componentWillMount() {
    const { menuId, loginUid, bid } = this.props.match.params
  reloading = false
    if (sessionStorage.getItem('UserID')) {
  UNSAFE_componentWillMount() {
    const { params, path } = this.props.match
    const { menuId, loginUid, bid } = params
    if (/^\/view\//.test(path)) {
      localStorage.setItem('getSysPermission', window.GLOB.appkey)
      const that = this
      window.addEventListener('storage', function(event) {
        if (event.key === 'sysPermissions' && event.newValue) {
          let values = event.newValue
          values = JSON.parse(values)
          window.GLOB.mkActions = values.mkActions
          values.mkThdMenus && values.mkThdMenus.forEach(item => {
            window.GLOB.mkThdMenus.set(item.MenuID, item)
          })
        } else if (event.key === 'menuUpdate') {
          let vals = event.newValue.split(',')
          let MenuId = vals[1]
          let position = vals[2] || ''
          if (position === 'menu' && menuId === MenuId) {
            that.setState({loading: true}, () => {
              that.setState({loading: false})
            })
          }
        }
      })
      setTimeout(() => {
        localStorage.removeItem('getSysPermission')
        localStorage.removeItem('sysPermissions')
        if (window.GLOB.mkActions && window.GLOB.mkActions.loaded) {
          this.setState({loading: false})
        } else if (sessionStorage.getItem('UserID')) {
          this.getPermRole()
        } else {
          Api.getTouristMsg().then(res => {
            if (res.status) {
              sessionStorage.setItem('UserID', res.UserID)
              sessionStorage.setItem('LoginUID', res.LoginUID)
              sessionStorage.setItem('User_Name', res.UserName)
              sessionStorage.setItem('Full_Name', res.FullName)
              sessionStorage.setItem('avatar', res.icon || '')
              sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
              sessionStorage.setItem('debug', res.debug || '')
              sessionStorage.setItem('role_id', res.role_id || '')
              sessionStorage.setItem('departmentcode', res.departmentcode || '')
              sessionStorage.setItem('organization', res.organization || '')
              sessionStorage.setItem('mk_user_type', res.mk_user_type || '')
              this.getPermRole()
            } else {
              sessionStorage.clear()
              this.props.history.replace('/login')
            }
          })
        }
      }, 20)
    } else if (sessionStorage.getItem('UserID')) {
      this.getPermRole()
    } else {
      sessionStorage.setItem('LoginUID', loginUid)
@@ -47,6 +107,122 @@
    }
    this.setState({BID: bid || '', MenuId: menuId})
  }
  componentDidMount () {
    MKEmitter.addListener('modifyTabs', this.modifyTabs)
    MKEmitter.addListener('closeTabView', this.closeTabView)
    if (window.GLOB.forcedUpdate) {
      MKEmitter.addListener('reloadTabs', this.reloadTabs)
    }
    if (window.GLOB.sysType !== 'cloud') {
      Object.defineProperty(window, 'debugger', {
        configurable: true,
        enumerable: true,
        set(value) {
          if (value + '' === 'false') {
            window.GLOB.debugger = false
          } else {
            window.GLOB.debugger = true
          }
        }
      })
      Object.defineProperty(window, 'debug', {
        configurable: true,
        enumerable: true,
        set(value) {
          if (value + '' === 'false') {
            window.GLOB.debugger = false
            window.GLOB.breakpoint = false
            sessionStorage.removeItem('breakpoint')
          } else {
            window.GLOB.debugger = true
            window.GLOB.breakpoint = value + ''
            sessionStorage.setItem('breakpoint', value)
          }
          MKEmitter.emit('debugChange')
        }
      })
    }
  }
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('modifyTabs', this.modifyTabs)
    MKEmitter.removeListener('reloadTabs', this.reloadTabs)
    MKEmitter.removeListener('closeTabView', this.closeTabView)
  }
  reloadTabs = () => {
    if (this.reloading) return
    this.reloading = true
    Api.getAppVersion(true).then(() => {
      window.location.reload()
    }, (message) => {
      notification.error({
        top: 92,
        message: message || '系统配置更新失败!',
        duration: 10
      })
    })
  }
  modifyTabs = (tab) => {
    const { MenuId, BID } = this.state
    let _menuId = tab.MenuID
    let _BID = tab.param && tab.param.$BID ? tab.param.$BID : ''
    let historys = sessionStorage.getItem('page_historys')
    historys = historys ? JSON.parse(historys) : []
    historys.push({MenuId: MenuId, BID: BID})
    sessionStorage.setItem('page_historys', JSON.stringify(historys))
    this.setState({
      MenuId: _menuId,
      BID: _BID,
      loading: true
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
  closeTabView = () => {
    let historys = sessionStorage.getItem('page_historys')
    historys = historys ? JSON.parse(historys) : []
    if (historys.length === 0) {
      window.close()
      return
    }
    let tab = historys.shift()
    sessionStorage.setItem('page_historys', JSON.stringify(historys))
    this.setState({
      MenuId: tab.MenuId,
      BID: tab.BID,
      loading: true
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
  getPermRole = () => {
@@ -93,6 +269,7 @@
        {loading ? <Spin size="large" /> : null}
        {!loading && type === 'CustomPage' ? <CustomPage MenuID={MenuId} param={{$BID: BID}} changeTemp={this.changeTemp}/> : null}
        {!loading && type === 'BaseTable' ? <BaseTable MenuID={MenuId} param={{$BID: BID}} changeTemp={this.changeTemp}/> : null}
        <ImgScale />
      </div>
    )
  }