From cb9ade2afd2a367ad767bc605ab7086c695dd010 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 09 十二月 2022 15:53:32 +0800
Subject: [PATCH] 2022-12-09

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

diff --git a/src/tabviews/home/index.jsx b/src/tabviews/home/index.jsx
index ae14a8f..23338d0 100644
--- a/src/tabviews/home/index.jsx
+++ b/src/tabviews/home/index.jsx
@@ -1,10 +1,10 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { connect } from 'react-redux'
 import { notification, Spin } from 'antd'
 
 import Api from '@/api'
 import asyncComponent from '@/utils/asyncComponent'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 const DefaultHome = asyncComponent(() => import('./defaulthome'))
@@ -18,25 +18,50 @@
   state = {
     loading: true,
     background: sessionStorage.getItem('home_background'),
-    waiting: true,
+    waitMenu: true,
+    waitAction: true,
     view: ''
   }
 
   componentDidMount () {
     this.loadHomeConfig()
-    if (this.props.permMenus.length > 0 && JSON.stringify(this.props.permAction) !== '{}') {
+    if (window.GLOB.mkThdMenus.length > 0) {
       this.setState({
-        waiting: false
+        waitMenu: false
       })
+    } else {
+      MKEmitter.addListener('mkMenuLoaded', this.mkMenuLoaded)
+    }
+    if (window.GLOB.mkActions.loaded) {
+      this.setState({
+        waitAction: false
+      })
+    } else {
+      MKEmitter.addListener('mkActionLoaded', this.mkActionLoaded)
     }
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    if (nextProps.permMenus.length > 0 && JSON.stringify(nextProps.permAction) !== '{}') {
-      this.setState({
-        waiting: false
-      })
+  /**
+   * @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 = () => {
@@ -47,20 +72,41 @@
     Api.getCacheConfig(_param).then(result => {
       if (result.status) {
         if (result.LongParam) {
-          this.setState({
-            loading: false,
-            view: 'custom'
-          })
+          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,
-            waiting: false,
+            waitMenu: false,
+            waitAction: false,
             view: 'default'
           })
         }
       } else {
         this.setState({
           loading: false,
+          waitMenu: false,
+          waitAction: false,
           view: 'default'
         })
         notification.warning({
@@ -73,9 +119,9 @@
   }
 
   render() {
-    const { loading, waiting, view, background } = this.state
+    const { loading, waitAction, waitMenu, view, background } = this.state
 
-    if (loading || waiting) {
+    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} MenuName="棣栭〉"/>)
@@ -85,15 +131,4 @@
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    permAction: state.permAction,
-    permMenus: state.permMenus
-  }
-}
-
-const mapDispatchToProps = () => {
-  return {}
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(Home)
\ No newline at end of file
+export default Home
\ No newline at end of file

--
Gitblit v1.8.0