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
|