king
2022-10-08 9c6795fd3c44e46cf3955fbfd8f8eeca23acb7a9
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 MKEmitter from '@/utils/events.js'
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'),
    waitMenu: true,
    waitAction: true,
    view: ''
  }
 
  componentDidMount () {
    this.loadHomeConfig()
    if (window.GLOB.mkThdMenus.length > 0) {
      this.setState({
        waitMenu: false
      })
    } else {
      MKEmitter.addListener('mkMenuLoaded', this.mkMenuLoaded)
    }
    if (window.GLOB.mkActions.loaded) {
      this.setState({
        waitAction: false
      })
    } else {
      MKEmitter.addListener('mkActionLoaded', this.mkActionLoaded)
    }
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('mkMenuLoaded', this.mkMenuLoaded)
    MKEmitter.removeListener('mkActionLoaded', this.mkActionLoaded)
  }
 
  mkMenuLoaded = () => {
    this.setState({
      waitMenu: false
    })
  }
 
  mkActionLoaded = () => {
    this.setState({
      waitAction: 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,
            waitMenu: false,
            waitAction: false,
            view: 'default'
          })
        }
      } else {
        this.setState({
          loading: false,
          view: 'default'
        })
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      }
    })
  }
 
  render() {
    const { loading, waitAction, waitMenu, view, background } = this.state
 
    if (loading || waitAction || waitMenu) {
      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