king
2023-02-13 32f1d2179f6d7ccb5b167aa40116a59e68851a90
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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) {
          let config = ''
 
          try { // 配置信息解析
            config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
          } catch (e) {
            console.warn('Parse Failure')
            config = ''
          }
 
          if (!config || !config.enabled) {
            this.setState({
              loading: false,
              waitMenu: false,
              waitAction: false,
              view: 'default'
            })
          } else {
            this.setState({
              loading: false,
              view: 'custom'
            })
          }
        } else {
          this.setState({
            loading: false,
            waitMenu: false,
            waitAction: false,
            view: 'default'
          })
        }
      } else {
        this.setState({
          loading: false,
          waitMenu: false,
          waitAction: 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