From cdd5b449130ea4d7223fde4f414a11a7d0c33d6d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 07 三月 2024 17:52:16 +0800 Subject: [PATCH] 2024-03-07 --- src/tabviews/custom/components/chart/antv-dashboard/index.jsx | 148 +++++++++++++++++++++++++++++++------------------ 1 files changed, 93 insertions(+), 55 deletions(-) diff --git a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx index c8cec13..15cf833 100644 --- a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx +++ b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx @@ -3,7 +3,7 @@ import { is, fromJS } from 'immutable' import { Chart, registerShape } from '@antv/g2' import { Spin, notification, Modal } from 'antd' -import { DownloadOutlined } from '@ant-design/icons' +// import { DownloadOutlined } from '@ant-design/icons' import moment from 'moment' import Api from '@/api' @@ -84,18 +84,22 @@ BID = BData.$BID || '' } - if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { - this.data = window.GLOB.SyncData.get(_config.dataName) || [] + if (_config.setting.sync === 'true') { + _config.setting.onload = 'false' - if (_config.$cache) { - Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS()) + if (window.GLOB.SyncData.has(_config.dataName)) { + this.data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS(), BID) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } - - _config.setting.sync = 'false' - - this.loaded = true - - window.GLOB.SyncData.delete(_config.dataName) } if (_config.subtype !== 'ratioboard') { @@ -116,19 +120,8 @@ this.setState({ config: _config, BID: BID || '', - arr_field: _config.columns.map(col => col.field).join(','), plot: _config.plot - }, () => { - if (config.setting.sync !== 'true' && config.setting.onload === 'true') { - setTimeout(() => { - this.loadData() - }, _config.setting.delay || 0) - } }) - - if (config.setting.sync === 'true' && this.loaded) { - this.handleData() - } } shouldComponentUpdate (nextProps, nextState) { @@ -152,28 +145,11 @@ if (config.timer) { this.timer = new TimerTask() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { - this.loadData(true) + this.loadData('timer') }) } - if (config.$cache && !this.loaded) { - Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.loaded) return - - let _data = null - if (config.subtype === 'ratioboard') { - _data = res - } else { - _data = res[0] || {} - _data.value = _data[config.plot.valueField] || 0 - } - - if (!is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } - }) - } + this.initExec() } /** @@ -191,15 +167,79 @@ this.timer && this.timer.stop() } + initExec = () => { + const { config, BID } = this.state + + if (config.$cache) { + if (config.$time) { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => { + if (!res.valid && config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } + + if (!res.data || this.loaded) return + + this.data = res.data + + if (config.subtype !== 'ratioboard') { + if (Array.isArray(this.data)) { + this.data = this.data[0] || {} + } + this.data.value = this.data[config.plot.valueField] || 0 + } + + this.handleData() + }) + } else { + this.handleData() + } + } else { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, 0, BID).then(res => { + if (!res.data || this.loaded) return + + this.data = res.data + + if (config.subtype !== 'ratioboard') { + if (Array.isArray(this.data)) { + this.data = this.data[0] || {} + } + this.data.value = this.data[config.plot.valueField] || 0 + } + + this.handleData() + }) + } + + if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } else if (this.loaded) { + this.handleData() + } + } + } else if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } else if (this.loaded) { + this.handleData() + } + } + transferSyncData = (syncId) => { - const { config } = this.state + const { config, BID } = this.state if (config.$syncId !== syncId) return let _data = window.GLOB.SyncData.get(config.dataName) || [] if (config.$cache) { - Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID) } if (config.subtype !== 'ratioboard') { @@ -209,10 +249,8 @@ _data.value = _data[config.plot.valueField] || 0 } - if (!is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } + this.data = _data + this.handleData() this.loaded = true @@ -261,8 +299,8 @@ }, 100) } - async loadData (hastimer) { - const { config, arr_field, BID } = this.state + async loadData (type) { + const { config, BID } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� let _data = null @@ -290,19 +328,19 @@ return } - if (!hastimer) { + if (type !== 'timer') { this.setState({ loading: true }) } let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, '', '', BID) + let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, '', '', BID) let result = await Api.genericInterface(param) if (result.status) { - if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || []) + if (config.$cache && type === 'init') { + Api.writeCacheConfig(config.uuid, result.data || [], BID) } this.loaded = true @@ -312,7 +350,7 @@ _data = result.data || [] } else { _data = result.data && result.data[0] ? result.data && result.data[0] : {} - _data.value = _data.value[config.plot.valueField] || 0 + _data.value = _data[config.plot.valueField] || 0 } if (!is(fromJS(this.data), fromJS(_data))) { @@ -693,7 +731,7 @@ } <NormalHeader config={config} /> <div className="canvas-wrap"> - {config.plot.download === 'enable' && this.state.chart ? <DownloadOutlined onClick={this.downloadImage} className="system-color download"/> : null} + {/* {config.plot.download === 'enable' && this.state.chart ? <DownloadOutlined onClick={this.downloadImage} className="system-color download"/> : null} */} <div className="canvas" id={this.state.chartId}></div> </div> </div> -- Gitblit v1.8.0