From c98e45bfac25e9110ad0383faac54a54d98ea9d5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 18 十一月 2021 20:47:04 +0800 Subject: [PATCH] 2021-11-18 --- src/tabviews/custom/components/chart/antv-dashboard/index.jsx | 80 +++++++++++++++++++-------------------- 1 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx index 6fcdc2f..df4fba4 100644 --- a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx +++ b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx @@ -7,12 +7,13 @@ import Api from '@/api' import Utils from '@/utils/utils.js' -import asyncComponent from '@/utils/asyncComponent' +// import asyncComponent from '@/utils/asyncComponent' import UtilsDM from '@/utils/utils-datamanage.js' import MKEmitter from '@/utils/events.js' +import NormalHeader from '@/tabviews/custom/components/share/normalheader' import './index.scss' -const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader')) +// const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader')) registerShape('point', 'pointer', { draw(cfg, container) { @@ -68,7 +69,7 @@ title: '', // 缁勪欢鏍囬 sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 plot: null, // 鍥捐〃璁剧疆 - data: null, // 鏁版嵁 + data: {}, // 鏁版嵁 } UNSAFE_componentWillMount () { @@ -96,13 +97,7 @@ } } - let height = config.plot.height || 400 - if (config.plot.title) { - _config.plot.height = height - 75 - } else { - _config.plot.height = height - 30 - } - _config.style.height = height + _config.style.height = config.plot.height || 400 this.setState({ config: _config, @@ -148,12 +143,10 @@ this.setState({sync: false, data: _data}, () => { this.handleData() }) - } else if (nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - if (config.setting.syncRefresh === 'true') { - this.setState({}, () => { - this.loadData() - }) - } + } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + this.setState({}, () => { + this.loadData() + }) } } @@ -184,7 +177,7 @@ if (!config.timer) return - const _change = { '15s': 15000, '30s': 30000, '1min': 60000, '5min': 300000, '10min': 600000, '15min': 900000, '30min': 1800000, '1hour': 3600000 } + const _change = { '5s': 5000, '15s': 15000, '30s': 30000, '1min': 60000, '5min': 300000, '10min': 600000, '15min': 900000, '30min': 1800000, '1hour': 3600000 } let timer = _change[config.timer] @@ -241,7 +234,7 @@ const { config } = this.state if (!config.setting.supModule || config.setting.supModule !== MenuID) return - if (id !== this.state.BID) { + if (id !== this.state.BID || id !== '') { this.setState({ BID: id }, () => { this.loadData() }) @@ -269,21 +262,10 @@ return } - let searches = [] - if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = [] - mainSearch.forEach(item => { - if (!keys.includes(item.key)) { - searches.push(item) - } - }) - } + let searches = config.setting.useMSearch && mainSearch ? mainSearch : [] - let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0)) + let requireFields = searches.filter(item => item.required && item.value === '') if (requireFields.length > 0) { - this.setState({ - loading: false - }) return } @@ -302,16 +284,22 @@ if (config.subtype === 'ratioboard') { data = result.data || [] } else { - let data = {} + data = {} if (result.data && result.data[0] && result.data[0].hasOwnProperty(config.plot.valueField)) { 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() }) } else { @@ -363,13 +351,12 @@ ratioboardrender = () => { const { plot, chartId } = this.state - const data = this.getratiodata() const chart = new Chart({ container: chartId, autoFit: true, - height: plot.height, + height: this.wrap.offsetHeight - 30, }) chart.data(data) @@ -458,17 +445,28 @@ const { plot, chartId, data } = this.state let _data = fromJS(data).toJS() - if (_data.value && _data.value > plot.maxValue) { - _data.value = plot.maxValue + + if (_data.hasOwnProperty('value')) { + if (_data.value === '' || _data.value === null) { + delete _data.value + } else { + _data.value = +_data.value + + if (isNaN(_data.value)) { + delete _data.value + } else if (_data.value > plot.maxValue) { + _data.value = plot.maxValue + } + } } const chart = new Chart({ container: chartId, autoFit: true, - height: plot.height, + height: this.wrap.offsetHeight - 30, padding: [0, 0, 0, 0], }) - chart.data([_data]); + chart.data([_data]) chart.scale('value', { min: 0, max: plot.maxValue, @@ -480,7 +478,7 @@ radius: 0.75, }) - chart.axis('1', false); + chart.axis('1', false) chart.axis('value', { line: null, label: { @@ -610,8 +608,8 @@ </div> : null } <NormalHeader config={config} /> - <div className="canvas-wrap"> - <div className={'canvas' + (empty ? ' empty' : '')} style={{height: config.plot.height + 30}} id={this.state.chartId}></div> + <div className="canvas-wrap" ref={ref => this.wrap = ref}> + <div className={'canvas' + (empty ? ' empty' : '')} id={this.state.chartId}></div> </div> </div> ) -- Gitblit v1.8.0