| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { connect } from 'react-redux' |
| | | import { notification, Spin } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | |
| | | |
| | | componentDidMount () { |
| | | this.loadHomeConfig() |
| | | if (this.props.permMenus.length > 0 && JSON.stringify(this.props.permAction) !== '{}') { |
| | | this.setState({ |
| | | waiting: false |
| | | }) |
| | | |
| | | this.check(0) |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新 |
| | | */ |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (nextProps.permMenus.length > 0 && JSON.stringify(nextProps.permAction) !== '{}') { |
| | | check = (times) => { |
| | | times++ |
| | | |
| | | if ((window.GLOB.mkThdMenus.length > 0 && window.GLOB.mkActions.loaded) || times > 50) { |
| | | this.setState({ |
| | | waiting: false |
| | | }) |
| | | } else { |
| | | setTimeout(() => { |
| | | this.check(times) |
| | | }, 200) |
| | | } |
| | | } |
| | | |
| | |
| | | Api.getCacheConfig(_param).then(result => { |
| | | if (result.status) { |
| | | if (result.LongParam) { |
| | | this.setState({ |
| | | loading: false, |
| | | view: 'custom' |
| | | }) |
| | | 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, |
| | | waiting: false, |
| | | view: 'default' |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | loading: false, |
| | | view: 'custom' |
| | | }) |
| | | } |
| | | } else { |
| | | this.setState({ |
| | | loading: false, |
| | |
| | | } else { |
| | | this.setState({ |
| | | loading: false, |
| | | waiting: false, |
| | | view: 'default' |
| | | }) |
| | | notification.warning({ |
| | |
| | | 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}/>) |
| | | return (<CustomPage MenuID={this.props.MenuID} MenuName="首页"/>) |
| | | } else { |
| | | return (<DefaultHome />) |
| | | } |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | permAction: state.permAction, |
| | | permMenus: state.permMenus |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(Home) |
| | | export default Home |