king
2022-06-02 94fe37551855f542d1cbad8b7af7fe3311daeddb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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} MenuName="首页"/>)
    } else {
      return (<DefaultHome />)
    }
  }
}
 
const mapStateToProps = (state) => {
  return {
    permAction: state.permAction,
    permMenus: state.permMenus
  }
}
 
const mapDispatchToProps = () => {
  return {}
}
 
export default connect(mapStateToProps, mapDispatchToProps)(Home)