fix: 修复 ECharts 数据加载太快时渲染报错问题 (#3950)

* fix: 修复 ECharts 数据加载太快时渲染报错问题

* 补上 cancel
This commit is contained in:
吴多益 2022-04-06 13:53:52 +08:00 committed by GitHub
parent c6b10613a8
commit 6bb113e642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,7 @@ import {
} from '../Schema'; } from '../Schema';
import {ActionSchema} from './Action'; import {ActionSchema} from './Action';
import {isAlive} from 'mobx-state-tree'; import {isAlive} from 'mobx-state-tree';
import debounce from 'lodash/debounce';
/** /**
* Chart * Chart
@ -180,6 +181,7 @@ export class Chart extends React.Component<ChartProps> {
this.refFn = this.refFn.bind(this); this.refFn = this.refFn.bind(this);
this.reload = this.reload.bind(this); this.reload = this.reload.bind(this);
this.reloadEcharts = debounce(this.reloadEcharts.bind(this), 300); //过于频繁更新 ECharts 会报错
this.handleClick = this.handleClick.bind(this); this.handleClick = this.handleClick.bind(this);
this.mounted = true; this.mounted = true;
@ -225,6 +227,7 @@ export class Chart extends React.Component<ChartProps> {
componentWillUnmount() { componentWillUnmount() {
this.mounted = false; this.mounted = false;
(this.reloadEcharts as any).cancel();
clearTimeout(this.timer); clearTimeout(this.timer);
} }
@ -435,14 +438,17 @@ export class Chart extends React.Component<ChartProps> {
} else { } else {
this.echarts?.hideLoading(); this.echarts?.hideLoading();
} }
this.reloadEcharts(config);
this.echarts?.setOption(config!, this.props.replaceChartOption);
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);
} }
} }
} }
reloadEcharts(config: any) {
this.echarts?.setOption(config!, this.props.replaceChartOption);
}
render() { render() {
const { const {
className, className,