king
2022-10-09 2f54651464414059b224181d713af2980e76d095
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
import {Component} from 'react'
import PropTypes from 'prop-types'
import { notification } from 'antd'
 
import Api from '@/api'
import UtilsDM from '@/utils/utils-datamanage.js'
import MKEmitter from '@/utils/events.js'
import TimerTask from '@/utils/timer-task.js'
 
// import './index.scss'
 
class MkInterItem extends Component {
  static propTpyes = {
    BID: PropTypes.any,        // 上级主键值
    config: PropTypes.object,  // 配置信息
  }
 
  state = {}
 
  componentDidMount () {
    const { config } = this.props
 
    if (config.setting.timer) {
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.setting.timer, config.setting.timerRepeats, () => {this.loadData()})
    }
    setTimeout(() => {
      this.loadData()
    }, config.setting.delay)
  }
 
  shouldComponentUpdate (nextProps, nextState) { return false }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    this.timer && this.timer.stop()
  }
 
  async loadData () {
    const { config, BID } = this.props
 
    let param = UtilsDM.getQueryDataParams(config.setting, config.columns.map(col => col.field).join(','), [], config.setting.order, 1, 1, BID)
 
    let result = await Api.genericInterface(param)
    if (result.status) {
      let _data = { $$empty: true }
 
      if (result.data && result.data[0]) {
        _data = result.data[0]
      }
      
      _data.$$loaded = true
 
      MKEmitter.emit('mkPublicData', config.uuid, _data)
    } else {
      this.timer && this.timer.stop()
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
    }
  }
 
  render() {return null}
}
 
export default MkInterItem