| | |
| | | |
| | | import Api from '@/api' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | const DefaultHome = asyncComponent(() => import('./defaulthome')) |
| | |
| | | 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) |
| | | } |
| | | |
| | | /** |
| | |
| | | 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 = () => { |
| | |
| | | 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 { // 配置信息解析 |
| | | 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 { // 配置信息解析 |
| | | 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, |
| | |
| | | } |
| | | |
| | | 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="首页"/>) |