king
2023-08-15 a94b0a4d15b26ecf8fe99f0a1c3e60d60b97766d
src/tabviews/home/index.jsx
@@ -4,7 +4,6 @@
import Api from '@/api'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const DefaultHome = asyncComponent(() => import('./defaulthome'))
@@ -18,27 +17,14 @@
  state = {
    loading: true,
    background: sessionStorage.getItem('home_background'),
    waitMenu: true,
    waitAction: true,
    waiting: 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)
    }
    this.check(0)
  }
  /**
@@ -48,20 +34,20 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('mkMenuLoaded', this.mkMenuLoaded)
    MKEmitter.removeListener('mkActionLoaded', this.mkActionLoaded)
  }
  mkMenuLoaded = () => {
    this.setState({
      waitMenu: false
    })
  }
  check = (times) => {
    times++
  mkActionLoaded = () => {
    this.setState({
      waitAction: false
    })
    if ((window.GLOB.mkThdMenus.length > 0 && window.GLOB.mkActions.loaded) || times > 50) {
      this.setState({
        waiting: false
      })
    } else {
      setTimeout(() => {
        this.check(times)
      }, 200)
    }
  }
  loadHomeConfig = () => {
@@ -84,8 +70,7 @@
          if (!config || !config.enabled) {
            this.setState({
              loading: false,
              waitMenu: false,
              waitAction: false,
              waiting: false,
              view: 'default'
            })
          } else {
@@ -97,16 +82,14 @@
        } else {
          this.setState({
            loading: false,
            waitMenu: false,
            waitAction: false,
            waiting: false,
            view: 'default'
          })
        }
      } else {
        this.setState({
          loading: false,
          waitMenu: false,
          waitAction: false,
          waiting: false,
          view: 'default'
        })
        notification.warning({
@@ -119,9 +102,9 @@
  }
  render() {
    const { loading, waitAction, waitMenu, view, background } = this.state
    const { loading, waiting, view, background } = this.state
    if (loading || waitAction || waitMenu) {
    if (loading || waiting) {
      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} MenuName="首页"/>)