From 9fc16092931ca11ec8987992d29d21bb9b5ba688 Mon Sep 17 00:00:00 2001 From: nikogu <644506165@qq.com> Date: Thu, 7 Sep 2017 10:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9B=BE=E8=A1=A8=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E6=97=B6=E6=9C=BA=E7=9A=84=E6=AF=94=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/components/Charts/Bar/index.js | 3 ++- src/components/Charts/Gauge/index.js | 5 ++++- src/components/Charts/MiniArea/index.js | 3 ++- src/components/Charts/MiniBar/index.js | 3 ++- src/components/Charts/Pie/index.js | 3 ++- src/components/Charts/Radar/index.js | 3 ++- src/components/Charts/equal.js | 17 +++++++++++++++++ src/routes/Dashboard/Analysis.js | 14 ++++++-------- 9 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 src/components/Charts/equal.js diff --git a/package.json b/package.json index 4b7f7f15..ceef972c 100755 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "eslint-plugin-babel": "^4.0.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^5.0.1", + "eslint-plugin-markdown": "^1.0.0-beta.6", "eslint-plugin-react": "^7.0.1", "gh-pages": "^1.0.0", "husky": "^0.13.4", diff --git a/src/components/Charts/Bar/index.js b/src/components/Charts/Bar/index.js index 537c4fc4..765f5eb4 100644 --- a/src/components/Charts/Bar/index.js +++ b/src/components/Charts/Bar/index.js @@ -1,5 +1,6 @@ import React, { PureComponent } from 'react'; import G2 from 'g2'; +import equal from '../equal'; import styles from '../index.less'; class Bar extends PureComponent { @@ -8,7 +9,7 @@ class Bar extends PureComponent { } componentWillReceiveProps(nextProps) { - if (nextProps.data !== this.props.data) { + if (!equal(this.props, nextProps)) { this.renderChart(nextProps.data); } } diff --git a/src/components/Charts/Gauge/index.js b/src/components/Charts/Gauge/index.js index 0c53540e..dcd3779c 100644 --- a/src/components/Charts/Gauge/index.js +++ b/src/components/Charts/Gauge/index.js @@ -1,5 +1,6 @@ import React, { PureComponent } from 'react'; import G2 from 'g2'; +import equal from '../equal'; const Shape = G2.Shape; @@ -10,7 +11,9 @@ class Gauge extends PureComponent { } componentWillReceiveProps(nextProps) { - this.renderChart(nextProps); + if (!equal(this.props, nextProps)) { + this.renderChart(nextProps); + } } handleRef = (n) => { diff --git a/src/components/Charts/MiniArea/index.js b/src/components/Charts/MiniArea/index.js index d763649c..12fe4c45 100644 --- a/src/components/Charts/MiniArea/index.js +++ b/src/components/Charts/MiniArea/index.js @@ -1,5 +1,6 @@ import React, { PureComponent } from 'react'; import G2 from 'g2'; +import equal from '../equal'; import styles from '../index.less'; class MiniArea extends PureComponent { @@ -8,7 +9,7 @@ class MiniArea extends PureComponent { } componentWillReceiveProps(nextProps) { - if (nextProps.data !== this.props.data) { + if (!equal(this.props, nextProps)) { this.renderChart(nextProps.data); } } diff --git a/src/components/Charts/MiniBar/index.js b/src/components/Charts/MiniBar/index.js index d0553a7f..d71517f8 100644 --- a/src/components/Charts/MiniBar/index.js +++ b/src/components/Charts/MiniBar/index.js @@ -1,5 +1,6 @@ import React, { PureComponent } from 'react'; import G2 from 'g2'; +import equal from '../equal'; import styles from '../index.less'; class MiniBar extends PureComponent { @@ -8,7 +9,7 @@ class MiniBar extends PureComponent { } componentWillReceiveProps(nextProps) { - if (nextProps.data !== this.props.data) { + if (!equal(this.props, nextProps)) { this.renderChart(nextProps.data); } } diff --git a/src/components/Charts/Pie/index.js b/src/components/Charts/Pie/index.js index a06f06b4..af3f68a5 100644 --- a/src/components/Charts/Pie/index.js +++ b/src/components/Charts/Pie/index.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import G2 from 'g2'; +import equal from '../equal'; import styles from './index.less'; /* eslint react/no-danger:0 */ @@ -14,7 +15,7 @@ class Pie extends Component { } componentWillReceiveProps(nextProps) { - if (this.props.data !== nextProps.data) { + if (!equal(this.props, nextProps)) { this.renderChart(nextProps.data); } } diff --git a/src/components/Charts/Radar/index.js b/src/components/Charts/Radar/index.js index 1ac14375..12640774 100644 --- a/src/components/Charts/Radar/index.js +++ b/src/components/Charts/Radar/index.js @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; import G2 from 'g2'; import { Row, Col } from 'antd'; +import equal from '../equal'; import styles from './index.less'; /* eslint react/no-danger:0 */ @@ -14,7 +15,7 @@ class Radar extends PureComponent { } componentWillReceiveProps(nextProps) { - if (nextProps.data !== this.props.data) { + if (!equal(this.props, nextProps)) { this.renderChart(nextProps.data); } } diff --git a/src/components/Charts/equal.js b/src/components/Charts/equal.js new file mode 100644 index 00000000..ff3a4c70 --- /dev/null +++ b/src/components/Charts/equal.js @@ -0,0 +1,17 @@ +/* eslint eqeqeq: 0 */ + +function equal(old, target) { + let r = true; + for (const prop in old) { + if (typeof old[prop] === 'function' && typeof target[prop] === 'function') { + if (old[prop].toString() != target[prop].toString()) { + r = false; + } + } else if (old[prop] != target[prop]) { + r = false; + } + } + return r; +} + +export default equal; diff --git a/src/routes/Dashboard/Analysis.js b/src/routes/Dashboard/Analysis.js index f716fead..b720f5aa 100644 --- a/src/routes/Dashboard/Analysis.js +++ b/src/routes/Dashboard/Analysis.js @@ -60,10 +60,6 @@ export default class Analysis extends Component { this.setState({ rangePickerValue, }); - - this.props.dispatch({ - type: 'chart/fetchSalesData', - }); } selectDate = (type) => { @@ -88,7 +84,7 @@ export default class Analysis extends Component { salesTypeData, salesTypeDataOnline, salesTypeDataOffline, - } = chart; + } = chart; const salesPieData = salesType === 'all' ? salesTypeData @@ -144,6 +140,8 @@ export default class Analysis extends Component { }, ]; + const activeKey = currentTabKey || (offlineData[0] && offlineData[0].name); + const CustomTab = ({ data, currentTabKey: currentKey }) => ( @@ -156,7 +154,7 @@ export default class Analysis extends Component { { offlineData.map(shop => ( } + tab={} key={shop.name} >
-- GitLab