From 004176924ce35c96600f5c18e85478944de8bec6 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 14 一月 2023 16:46:50 +0800 Subject: [PATCH] 2023-01-14 --- src/tabviews/custom/components/chart/antv-dashboard/index.jsx | 46 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx index 7252311..af28e52 100644 --- a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx +++ b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx @@ -156,9 +156,11 @@ } } - this.setState({sync: false, data: _data}, () => { + this.setState({sync: false, data: _data}) + + if (!is(fromJS(this.state.data), fromJS(_data))) { this.handleData() - }) + } } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { this.setState({}, () => { this.loadData() @@ -171,7 +173,7 @@ } componentDidMount () { - const { config } = this.state + const { config, sync } = this.state MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) @@ -180,6 +182,23 @@ 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) return + + let _data = null + if (config.subtype === 'ratioboard') { + _data = res + } else { + _data = {value: res[0][config.plot.valueField]} + } + + this.setState({data: _data}, () => { + this.handleData() + }) }) } } @@ -221,7 +240,10 @@ if (_element) { _element.innerHTML = '' } - this.viewrender() + + setTimeout(() => { + this.viewrender() + }, 100) } async loadData (hastimer) { @@ -255,6 +277,10 @@ let result = await Api.genericInterface(param) if (result.status) { + if (config.$cache) { + Api.writeCacheConfig(config.uuid, result.data || '') + } + let data = null if (config.subtype === 'ratioboard') { data = result.data || [] @@ -264,19 +290,15 @@ data.value = result.data[0][config.plot.valueField] } } - let reset = true - - if (hastimer && is(fromJS(data), fromJS(this.state.data))) { - reset = false - } this.setState({ data, loading: false - }, () => { - if (!reset) return - this.handleData() }) + + if (!is(fromJS(this.state.data), fromJS(data))) { + this.handleData() + } } else { this.setState({ loading: false -- Gitblit v1.8.0