king
2022-10-28 aa41be24e83653077d85860cb70882551912af24
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
import {Component} from 'react'
import PropTypes from 'prop-types'
import { notification, Modal } 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,  // 配置信息
  }
 
  loading = false
  
  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)
 
    MKEmitter.addListener('reloadData', this.reloadData)
  }
 
  shouldComponentUpdate (nextProps, nextState) { return false }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    this.timer && this.timer.stop()
    MKEmitter.removeListener('reloadData', this.reloadData)
  }
 
  reloadData = (publicId) => {
    if (this.props.config.uuid !== publicId) return
 
    this.loadData()
  }
 
  async loadData () {
    const { config, BID } = this.props
 
    if (this.loading) return
 
    this.loading = true
 
    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) {
      this.loading = false
      let _data = { $$empty: true, $$uuid: '' }
 
      if (result.data && result.data[0]) {
        _data = result.data[0]
        _data.$$uuid = _data[config.setting.primaryKey] || ''
      }
      
      _data.$$loaded = true
 
      window.GLOB.CacheData.set(config.uuid, _data)
 
      MKEmitter.emit('mkPublicData', config.uuid, _data)
      MKEmitter.emit('resetSelectLine', config.uuid, _data.$$uuid, _data)
    } else {
      this.loading = false
      this.timer && this.timer.stop()
      
      if (result.ErrCode === 'N') {
        Modal.error({
          title: result.message,
        })
      } else {
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
      }
    }
  }
 
  render() {return null}
}
 
export default MkInterItem