From da64ab0923bf8817fc8599a6e37b953ce38f64c8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 27 八月 2023 18:37:36 +0800
Subject: [PATCH] 2023-08-27

---
 src/tabviews/home/index.jsx |  103 ++++++++++++++++++++-------------------------------
 1 files changed, 40 insertions(+), 63 deletions(-)

diff --git a/src/tabviews/home/index.jsx b/src/tabviews/home/index.jsx
index 23338d0..d91ecef 100644
--- a/src/tabviews/home/index.jsx
+++ b/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 = () => {
@@ -70,45 +56,36 @@
       MenuID: this.props.MenuID
     }
     Api.getCacheConfig(_param).then(result => {
-      if (result.status) {
-        if (result.LongParam) {
-          let config = ''
+      let view = 'default'
+      if (result.status && result.LongParam) {
+        let config = ''
 
-          try { // 閰嶇疆淇℃伅瑙f瀽
-            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'
-          })
+        try { // 閰嶇疆淇℃伅瑙f瀽
+          config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
+        } catch (e) {
+          console.warn('Parse Failure')
+          config = ''
         }
+
+        if (config && config.enabled) {
+          view = 'custom'
+        }
+      }
+
+      if (view === 'default') {
+        this.setState({
+          loading: false,
+          waiting: false,
+          view: 'default'
+        })
       } else {
         this.setState({
           loading: false,
-          waitMenu: false,
-          waitAction: false,
-          view: 'default'
+          view: 'custom'
         })
+      }
+
+      if (!result.status) {
         notification.warning({
           top: 92,
           message: result.message,
@@ -119,9 +96,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="棣栭〉"/>)

--
Gitblit v1.8.0