From a29d9d644a2a30e9ef4afcc6d728c20c218dc359 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 15 六月 2023 14:25:28 +0800 Subject: [PATCH] 2023-06-15 --- src/tabviews/custom/components/chart/custom-chart/index.jsx | 94 ++++++++++++++++++++++++++++++---------------- 1 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/tabviews/custom/components/chart/custom-chart/index.jsx b/src/tabviews/custom/components/chart/custom-chart/index.jsx index 2680e59..f2b717e 100644 --- a/src/tabviews/custom/components/chart/custom-chart/index.jsx +++ b/src/tabviews/custom/components/chart/custom-chart/index.jsx @@ -28,14 +28,14 @@ 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 = '' @@ -50,20 +50,20 @@ 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 } - _config.style.height = config.plot.height || 400 + _config.plot.height = Utils.getHeight(_config.plot.height) + _config.style.height = 'auto' 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, @@ -74,10 +74,12 @@ setTimeout(() => { this.loadData() }, _config.setting.delay || 0) - } else if (config.setting.sync === 'true' && _data) { - this.handleData() } }) + + if (this.data.length > 0) { + this.handleData() + } } /** @@ -92,10 +94,13 @@ _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() - }) - } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + } + + 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() }) @@ -107,7 +112,7 @@ } componentDidMount () { - const { config } = this.state + const { config, sync } = this.state MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) @@ -118,6 +123,18 @@ 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}) }) } } @@ -214,10 +231,13 @@ if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� this.setState({ - data: [] - }, () => { - this.handleData() + empty: true }) + + if (!is(fromJS(this.data), fromJS([]))) { + this.data = [] + this.handleData() + } return } @@ -247,20 +267,26 @@ 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 && config.setting.onload !== 'false') { + 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() + } + + if (config.timer && config.clearField && result.data && result.data[0]) { + let vals = (config.clearValue || '').split(',') + if (vals.includes(result.data[0][config.clearField])) { + this.timer && this.timer.stop() + } + } } else { this.setState({ loading: false @@ -286,14 +312,14 @@ setTimeout(() => { this.viewrender() - }, 150) + }, 100) } /** * @description 鍥捐〃娓叉煋鍒嗙粍 */ viewrender = () => { - const { config, data } = this.state + const { config } = this.state if (!config.plot.script) return @@ -301,7 +327,7 @@ 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) @@ -315,7 +341,7 @@ 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) @@ -346,8 +372,10 @@ <Spin /> </div> : null } - <NormalHeader config={config} BID={BID} refresh={this.refreshSearch} /> - <div className={'canvas' + (empty ? ' empty' : '')} ref={ref => this.wrap = ref}></div> + <NormalHeader config={config} BID={BID} refresh={this.refreshSearch}/> + <div className="canvas-wrap" style={{height: (config.plot.height + 30) + 'px'}}> + <div className={'canvas' + (empty ? ' empty' : '')} style={{height: config.plot.height + 'px'}} ref={ref => this.wrap = ref}></div> + </div> {empty ? <Empty description={false}/> : null} </div> ) -- Gitblit v1.8.0