| | |
| | | |
| | | state = { |
| | | loading: true, |
| | | background: sessionStorage.getItem('home_background'), |
| | | background: sessionStorage.getItem('home_background') || 'unset', |
| | | waiting: true, |
| | | view: '' |
| | | } |
| | | |
| | | componentDidMount () { |
| | | this.loadHomeConfig() |
| | | |
| | | this.check(0) |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新 |
| | | */ |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | } |
| | | |
| | | check = (times) => { |
| | | times++ |
| | | |
| | | if ((window.GLOB.mkThdMenus.size > 0 && window.GLOB.mkActions.loaded) || times > 50) { |
| | | this.setState({ |
| | | waiting: false |
| | | }) |
| | | } else if (!window.GLOB.$error) { |
| | | setTimeout(() => { |
| | | this.check(times) |
| | | }, 200) |
| | | } |
| | | } |
| | | |
| | | loadHomeConfig = () => { |
| | |
| | | MenuID: this.props.MenuID |
| | | } |
| | | Api.getCacheConfig(_param).then(result => { |
| | | if (result.status) { |
| | | if (result.LongParam) { |
| | | this.setState({ |
| | | loading: false, |
| | | view: 'custom' |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | loading: false, |
| | | view: 'default' |
| | | }) |
| | | 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) { |
| | | view = 'custom' |
| | | } |
| | | } |
| | | |
| | | if (view === 'default') { |
| | | this.setState({ |
| | | loading: false, |
| | | waiting: false, |
| | | view: 'default' |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | loading: false, |
| | | view: 'default' |
| | | view: 'custom' |
| | | }) |
| | | } |
| | | |
| | | if (!result.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: result.message, |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { loading, view, background } = this.state |
| | | const { loading, waiting, view, background } = this.state |
| | | |
| | | if (loading) { |
| | | 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 />) |
| | | } |