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 || '' })
|
}
|
}
|
|
setTimeout(() => {
|
this.loadData()
|
}, config.setting.delay)
|
|
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('reloadData', this.reloadData)
|
MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
|
}
|
|
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)
|
} 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
|