king
2023-01-17 cc1a76df575c18f0d0ee96e8658461efdce3a918
src/tabviews/home/index.jsx
@@ -4,6 +4,7 @@
import Api from '@/api'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const DefaultHome = asyncComponent(() => import('./defaulthome'))
@@ -16,10 +17,54 @@
  state = {
    loading: true,
    background: sessionStorage.getItem('home_background'),
    waitMenu: true,
    waitAction: true,
    view: ''
  }
  componentDidMount () {
    this.loadHomeConfig()
    if (window.GLOB.mkThdMenus.length > 0) {
      this.setState({
        waitMenu: false
      })
    } else {
      MKEmitter.addListener('mkMenuLoaded', this.mkMenuLoaded)
    }
    if (window.GLOB.mkActions.loaded) {
      this.setState({
        waitAction: false
      })
    } else {
      MKEmitter.addListener('mkActionLoaded', this.mkActionLoaded)
    }
  }
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('mkMenuLoaded', this.mkMenuLoaded)
    MKEmitter.removeListener('mkActionLoaded', this.mkActionLoaded)
  }
  mkMenuLoaded = () => {
    this.setState({
      waitMenu: false
    })
  }
  mkActionLoaded = () => {
    this.setState({
      waitAction: false
    })
  }
  loadHomeConfig = () => {
    let _param = {
      func: 'sPC_Get_LongParam',
      MenuID: this.props.MenuID
@@ -27,19 +72,41 @@
    Api.getCacheConfig(_param).then(result => {
      if (result.status) {
        if (result.LongParam) {
          this.setState({
            loading: false,
            view: 'custom'
          })
          let config = ''
          try { // 配置信息解析
            config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
          } catch (e) {
            console.warn('Parse Failure')
            config = ''
          }
          if (!config || !config.enabled) {
            this.setState({
              loading: false,
              waitMenu: false,
              waitAction: false,
              view: 'default'
            })
          } else {
            this.setState({
              loading: false,
              view: 'custom'
            })
          }
        } else {
          this.setState({
            loading: false,
            waitMenu: false,
            waitAction: false,
            view: 'default'
          })
        }
      } else {
        this.setState({
          loading: false,
          waitMenu: false,
          waitAction: false,
          view: 'default'
        })
        notification.warning({
@@ -52,12 +119,12 @@
  }
  render() {
    const { loading, view } = this.state
    const { loading, waitAction, waitMenu, view, background } = this.state
    if (loading) {
      return (<Spin className="home-box-spin" size="large" />)
    if (loading || waitAction || waitMenu) {
      return (<div className="home-loading-view" style={{background: background}}><Spin className="home-box-spin" size="large" /></div>)
    } else if (view === 'custom') {
      return (<CustomPage MenuID={this.props.MenuID}/>)
      return (<CustomPage MenuID={this.props.MenuID} MenuName="首页"/>)
    } else {
      return (<DefaultHome />)
    }