king
8 天以前 a1e9b18a4dbfd21e1bf4d5cb60974ac2f0115efd
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { Component } from 'react'
import PropTypes from 'prop-types'
 
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
  loadTimer = null
  
  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') {
      this.loadData()
    } else {
      MKEmitter.addListener('initFinish', this.initFinish)
    }
 
    if (config.setting.useMSearch) {
      MKEmitter.addListener('searchRefresh', this.searchRefresh)
    }
 
    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('searchRefresh', this.searchRefresh)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
  }
 
  searchRefresh = (searchId) => {
    const { config } = this.props
 
    if (config.$searchId !== searchId) return
    
    this.loadData()
  }
 
  initFinish = (MenuID) => {
    const { config } = this.props
 
    if (config.MenuID !== MenuID) return
 
    if (config.setting.onload === 'false') {
      this.loadData()
    }
  }
 
  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()
  }
 
  loadData = () => {
    const { config } = this.props
 
    this.loadTimer && clearTimeout(this.loadTimer)
 
    this.loadTimer = setTimeout(() => {
      this.execLoadData()
    }, config.setting.delay)
  }
 
  async execLoadData () {
    const { config } = this.props
    const { BID } = this.state
 
    if (config.setting.supModule && !BID) {
      setTimeout(() => {
        MKEmitter.emit('mkPublicData', config.uuid, { $$empty: true, $$uuid: '' })
        MKEmitter.emit('resetSelectLine', config.uuid, '', { $$empty: true, $$uuid: '' })
      }, 20)
      this.loading = false
      return
    }
 
    if (this.loading) return
 
    let searches = []
    if (config.setting.useMSearch) {
      searches = window.GLOB.SearchBox.get(config.$searchId) || []
 
      if (window.GLOB.SearchBox.has(config.$searchId + 'required') && searches.filter(item => item.required && item.value === '').length > 0) {
        return
      }
    }
 
    this.loading = true
 
    let param = UtilsDM.getQueryDataParams(config.setting, searches, 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] || ''
      }
      
      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)
      }
 
      UtilsDM.querySuccess(result)
    } else {
      this.loading = false
      this.timer && this.timer.stop()
 
      if (config.setting.loadlevel === 'init') {
        MKEmitter.emit('interFinish', config.MenuID, config.uuid)
      }
 
      UtilsDM.queryFail(result)
    }
  }
 
  render() {return null}
}
 
export default MkInterItem