| | |
| | | loading: false, // 数据加载状态 |
| | | sync: false, // 是否统一请求数据 |
| | | plot: null, // 图表设置 |
| | | data: null, // 数据 |
| | | search: null, // 搜索条件 |
| | | } |
| | | |
| | | data = [] |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { config, data, initdata } = this.props |
| | | let _config = fromJS(config).toJS() |
| | | let _data = null |
| | | let _sync = config.setting.sync === 'true' |
| | | |
| | | let BID = '' |
| | |
| | | BID = BData.$BID || '' |
| | | } |
| | | |
| | | if (config.setting.sync === 'true' && data) { |
| | | _data = data[config.dataName] || [] |
| | | if (_sync && data) { |
| | | this.data = data[config.dataName] || [] |
| | | _sync = false |
| | | } else if (config.setting.sync === 'true' && initdata) { |
| | | _data = initdata || [] |
| | | } else if (_sync && initdata) { |
| | | this.data = initdata || [] |
| | | _sync = false |
| | | } |
| | | |
| | |
| | | |
| | | this.setState({ |
| | | config: _config, |
| | | data: _data, |
| | | empty: !_data || _data.length === 0, |
| | | empty: this.data.length === 0, |
| | | BID: BID || '', |
| | | arr_field: _config.columns.map(col => col.field).join(','), |
| | | plot: _config.plot, |
| | |
| | | setTimeout(() => { |
| | | this.loadData() |
| | | }, _config.setting.delay || 0) |
| | | } else if (config.setting.sync === 'true' && _data) { |
| | | this.handleData() |
| | | } |
| | | }) |
| | | |
| | | if (this.data.length > 0) { |
| | | this.handleData() |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | _data = nextProps.data[config.dataName] || [] |
| | | } |
| | | |
| | | this.setState({sync: false, data: _data, empty: _data.length === 0}, () => { |
| | | if (!is(fromJS(this.data), fromJS(_data))) { |
| | | this.data = _data |
| | | this.handleData() |
| | | }) |
| | | } |
| | | |
| | | this.setState({sync: false, empty: _data.length === 0}) |
| | | } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { |
| | | this.setState({}, () => { |
| | | this.loadData() |
| | |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { config } = this.state |
| | | const { config, sync } = this.state |
| | | |
| | | MKEmitter.addListener('reloadData', this.reloadData) |
| | | MKEmitter.addListener('resetSelectLine', this.resetParentParam) |
| | |
| | | this.timer = new TimerTask() |
| | | this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { |
| | | this.loadData(true) |
| | | }) |
| | | } |
| | | |
| | | if (config.$cache && (config.setting.sync !== 'true' || sync)) { |
| | | Api.getLCacheConfig(config.uuid).then(res => { |
| | | if (!res || this.data.length > 0) return |
| | | |
| | | if (!is(fromJS(this.data), fromJS(res))) { |
| | | this.data = res |
| | | this.handleData() |
| | | } |
| | | this.setState({empty: false}) |
| | | }) |
| | | } |
| | | } |
| | |
| | | |
| | | if (config.setting.supModule && !BID) { // BID 不存在时,不做查询 |
| | | this.setState({ |
| | | data: [] |
| | | }, () => { |
| | | this.handleData() |
| | | empty: true |
| | | }) |
| | | |
| | | if (!is(fromJS(this.data), fromJS([]))) { |
| | | this.data = [] |
| | | this.handleData() |
| | | } |
| | | return |
| | | } |
| | | |
| | |
| | | |
| | | let result = await Api.genericInterface(param) |
| | | if (result.status) { |
| | | let reset = true |
| | | |
| | | if (hastimer && is(fromJS(result.data), fromJS(this.state.data))) { |
| | | reset = false |
| | | if (config.$cache) { |
| | | Api.writeCacheConfig(config.uuid, result.data || '') |
| | | } |
| | | |
| | | this.setState({ |
| | | data: result.data, |
| | | loading: false, |
| | | empty: result.data.length === 0 |
| | | }, () => { |
| | | if (!reset) return |
| | | this.handleData() |
| | | empty: !result.data || result.data.length === 0 |
| | | }) |
| | | |
| | | if (!is(fromJS(this.data), fromJS(result.data || []))) { |
| | | this.data = result.data || [] |
| | | this.handleData() |
| | | } |
| | | } else { |
| | | this.setState({ |
| | | loading: false |
| | |
| | | |
| | | setTimeout(() => { |
| | | this.viewrender() |
| | | }, 150) |
| | | }, 100) |
| | | } |
| | | |
| | | /** |
| | | * @description 图表渲染分组 |
| | | */ |
| | | viewrender = () => { |
| | | const { config, data } = this.state |
| | | const { config } = this.state |
| | | |
| | | if (!config.plot.script) return |
| | | |
| | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('Chart', 'DataSet', 'wrap', 'data', 'config', config.plot.script) |
| | | func(Chart, DataSet, this.wrap, data, config) |
| | | func(Chart, DataSet, this.wrap, this.data, config) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | |
| | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('echarts', 'DataSet', 'wrap', 'data', 'config', config.plot.script) |
| | | func(echarts, DataSet, this.wrap, data, config) |
| | | func(echarts, DataSet, this.wrap, this.data, config) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | |