king
2025-05-12 d0764c7facff9abf00af6f3ff06a26260d1d8770
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
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') || 'unset',
    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 if (!window.GLOB.$error) {
      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