import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { notification, Spin } from 'antd'
|
|
import Api from '@/api'
|
import asyncComponent from '@/utils/asyncComponent'
|
import './index.scss'
|
|
const DefaultHome = asyncComponent(() => import('./defaulthome'))
|
const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
|
|
class Home extends Component {
|
static propTpyes = {
|
MenuID: PropTypes.string, // 菜单Id
|
}
|
|
state = {
|
loading: true,
|
background: sessionStorage.getItem('home_background'),
|
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 {
|
setTimeout(() => {
|
this.check(times)
|
}, 200)
|
}
|
}
|
|
loadHomeConfig = () => {
|
let _param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: this.props.MenuID
|
}
|
Api.getCacheConfig(_param).then(result => {
|
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: 'custom'
|
})
|
}
|
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
render() {
|
const { loading, waiting, view, background } = this.state
|
|
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="首页"/>)
|
} else {
|
return (<DefaultHome />)
|
}
|
}
|
}
|
|
export default Home
|