| | |
| | | config: _config, |
| | | arr_field: _config.columns.map(col => col.field).join(','), |
| | | search: _config.$searches |
| | | }, () => { |
| | | if (_config.setting.onload === 'true') { |
| | | setTimeout(() => { |
| | | this.loadData() |
| | | }, _config.setting.delay || 0) |
| | | } |
| | | }) |
| | | } |
| | | |
| | |
| | | MKEmitter.addListener('searchRefresh', this.searchRefresh) |
| | | } |
| | | |
| | | if (config.$cache && !this.loaded) { |
| | | Api.getLCacheConfig(config.uuid).then(res => { |
| | | if (!res.data || this.loaded) return |
| | | |
| | | let data = [] |
| | | res.data.forEach((item, index) => { |
| | | item.key = index |
| | | item.$$uuid = item[config.setting.primaryKey] || '' |
| | | |
| | | let pass = this.resetLine(item) |
| | | |
| | | if (pass) { |
| | | data.push(item) |
| | | } |
| | | }) |
| | | |
| | | this.setState({data: data}) |
| | | }) |
| | | } |
| | | this.initExec() |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | MKEmitter.removeListener('searchRefresh', this.searchRefresh) |
| | | MKEmitter.removeListener('resetSelectLine', this.resetParentParam) |
| | | MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) |
| | | } |
| | | |
| | | initExec = () => { |
| | | const { config } = this.state |
| | | |
| | | if (config.$cache) { |
| | | if (config.$time) { |
| | | Api.getLCacheConfig(config.uuid, config.$time).then(res => { |
| | | if (!res.valid && config.setting.onload === 'true') { |
| | | setTimeout(() => { |
| | | this.loadData('init') |
| | | }, config.setting.delay || 0) |
| | | } |
| | | |
| | | if (!res.data) return |
| | | |
| | | let _data = [] |
| | | res.data.forEach((item, index) => { |
| | | item.key = index |
| | | item.$$uuid = item[config.setting.primaryKey] || '' |
| | | |
| | | let pass = this.resetLine(item) |
| | | |
| | | if (pass) { |
| | | _data.push(item) |
| | | } |
| | | }) |
| | | |
| | | this.setState({data: _data}) |
| | | }) |
| | | } else { |
| | | Api.getLCacheConfig(config.uuid, 0).then(res => { |
| | | if (!res.data || this.loaded) return |
| | | |
| | | let _data = [] |
| | | res.data.forEach((item, index) => { |
| | | item.key = index |
| | | item.$$uuid = item[config.setting.primaryKey] || '' |
| | | |
| | | let pass = this.resetLine(item) |
| | | |
| | | if (pass) { |
| | | _data.push(item) |
| | | } |
| | | }) |
| | | |
| | | this.setState({data: _data}) |
| | | }) |
| | | |
| | | if (config.setting.onload === 'true') { |
| | | setTimeout(() => { |
| | | this.loadData('init') |
| | | }, config.setting.delay || 0) |
| | | } |
| | | } |
| | | } else if (config.setting.onload === 'true') { |
| | | setTimeout(() => { |
| | | this.loadData() |
| | | }, config.setting.delay || 0) |
| | | } |
| | | } |
| | | |
| | | searchRefresh = (searchId) => { |
| | |
| | | this.loadData() |
| | | } |
| | | |
| | | async loadData () { |
| | | async loadData (type) { |
| | | const { config, arr_field, BID, search, year } = this.state |
| | | |
| | | if (config.setting.supModule && !BID) { // BID 不存在时,不做查询 |
| | |
| | | let result = await Api.genericInterface(param) |
| | | if (result.status) { |
| | | this.loaded = true |
| | | if (config.$cache && config.setting.onload !== 'false') { |
| | | if (config.$cache && type === 'init') { |
| | | Api.writeCacheConfig(config.uuid, result.data || []) |
| | | } |
| | | |