import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { connect } from 'react-redux'
|
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()
|
if (this.props.permMenus.length > 0 && JSON.stringify(this.props.permAction) !== '{}') {
|
this.setState({
|
waiting: false
|
})
|
}
|
}
|
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
if (nextProps.permMenus.length > 0 && JSON.stringify(nextProps.permAction) !== '{}') {
|
this.setState({
|
waiting: false
|
})
|
}
|
}
|
|
loadHomeConfig = () => {
|
let _param = {
|
func: 'sPC_Get_LongParam',
|
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,
|
waiting: false,
|
view: 'default'
|
})
|
}
|
} else {
|
this.setState({
|
loading: false,
|
view: 'default'
|
})
|
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}/>)
|
} else {
|
return (<DefaultHome />)
|
}
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
permAction: state.permAction,
|
permMenus: state.permMenus
|
}
|
}
|
|
const mapDispatchToProps = () => {
|
return {}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Home)
|