From 0d8af0af44fa23d482fc3e20cf1a51e4f8862bea Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 18 七月 2023 15:07:54 +0800 Subject: [PATCH] 2023-07-18 --- src/tabviews/home/index.jsx | 55 +++++++++++++++++++------------------------------------ 1 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/tabviews/home/index.jsx b/src/tabviews/home/index.jsx index 23338d0..a6a8a60 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 = () => { @@ -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="棣栭〉"/>) -- Gitblit v1.8.0