king
2023-04-27 6dd965723be9dc245105296198c25a80cfe51b54
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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 = {
    BID: ''
  }
 
  componentDidMount () {
    const { config, BID } = this.props
 
    if (config.setting.timer) {
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.setting.timer, config.setting.timerRepeats, () => {this.loadData()})
    }
 
    if (!config.setting.supModule) {
      this.setState({ BID: BID || '' })
    } else {
      let BData = window.GLOB.CacheData.get(config.setting.supModule)
 
      if (BData) {
        this.setState({ BID: BData.$BID || '' })
      }
    }
 
    if (config.setting.onload !== 'false') {
      setTimeout(() => {
        this.loadData()
      }, config.setting.delay)
    } else {
      MKEmitter.addListener('initFinish', this.initFinish)
    }
 
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
  }
 
  shouldComponentUpdate (nextProps, nextState) { return false }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    this.timer && this.timer.stop()
    MKEmitter.removeListener('initFinish', this.initFinish)
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
  }
 
  initFinish = (MenuID) => {
    const { config } = this.props
 
    if (config.MenuID !== MenuID) return
 
    if (config.setting.onload === 'false') {
      setTimeout(() => {
        this.loadData()
      }, config.setting.delay)
    }
  }
 
  resetParentParam = (MenuID, id) => {
    const { config } = this.props
 
    if (!config.setting.supModule || config.setting.supModule !== MenuID) return
    if (id !== this.state.BID || id !== '') {
      this.setState({ BID: id }, () => {
        this.loadData()
      })
    }
  }
 
  reloadData = (publicId) => {
    if (this.props.config.uuid !== publicId) return
 
    this.loadData()
  }
 
  async loadData () {
    const { config } = this.props
    const { BID } = this.state
 
    if (config.setting.supModule && !BID) {
      MKEmitter.emit('mkPublicData', config.uuid, { $$empty: true, $$uuid: '' })
      MKEmitter.emit('resetSelectLine', config.uuid, '', { $$empty: true, $$uuid: '' })
      this.loading = false
      return
    }
 
    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)
 
      if (config.setting.loadlevel === 'init') {
        MKEmitter.emit('interFinish', config.MenuID, config.uuid)
      }
    } 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
        })
      }
 
      if (config.setting.loadlevel === 'init') {
        MKEmitter.emit('interFinish', config.MenuID, config.uuid)
      }
    }
  }
 
  render() {return null}
}
 
export default MkInterItem