king
2023-08-15 a94b0a4d15b26ecf8fe99f0a1c3e60d60b97766d
src/views/mkiframe/index.jsx
@@ -1,8 +1,11 @@
import React, {Component} from 'react'
import { Spin, notification } from 'antd'
import { Spin, notification, ConfigProvider } from 'antd'
import zhCN from 'antd/es/locale/zh_CN'
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'))
@@ -17,9 +20,43 @@
  }
  UNSAFE_componentWillMount() {
    const { menuId, loginUid, bid } = this.props.match.params
    const { params, path } = this.props.match
    const { menuId, loginUid, bid } = params
    if (sessionStorage.getItem('UserID')) {
    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.mkThdMenus = values.mkThdMenus
          window.GLOB.mkActions = values.mkActions
        } 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 {
          this.getPermRole()
        }
      }, 20)
    } else if (sessionStorage.getItem('UserID')) {
      this.getPermRole()
    } else {
      sessionStorage.setItem('LoginUID', loginUid)
@@ -47,6 +84,98 @@
    }
    this.setState({BID: bid || '', MenuId: menuId})
  }
  componentDidMount () {
    MKEmitter.addListener('modifyTabs', this.modifyTabs)
    MKEmitter.addListener('closeTabView', this.closeTabView)
    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('closeTabView', this.closeTabView)
  }
  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) 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 = () => {
@@ -90,9 +219,12 @@
    return (
      <div className="main-iframe">
        {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}
        <ConfigProvider locale={zhCN}>
          {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}
        </ConfigProvider>
        <ImgScale />
      </div>
    )
  }