diff --git a/package.json b/package.json index 4b7f7f15f1a6eaef084ddca81a5bbe1aeb58497a..ceef972cfd8bc30d1bcc239eb2347ecf411b5677 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 537c4fc49406ea47f4e15ffdbf0099d8d2cb35f6..765f5eb457d72bd4f4dcd1d2daf0ac8444d47ebb 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 0c53540e63900620579cc61cbd444f20d61f51f0..dcd3779c1a08bca1e502508fddbe99dbae37ad10 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 d763649c688e9c8f3956408fe95e90033bc67186..12fe4c45f33740fafff0bbc468c8bdd60cc18532 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 d0553a7f185f77fca9fa11347978cc25124df943..d71517f84fc6b86be90d32d43ccb47e33fd62bcd 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 a06f06b4362f96dcb637d86f220d3521dbfadc20..af3f68a5e18906af6e75430819c701617b77adfa 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 1ac14375e6561cac72ff1c976a4dc872fdb09c64..12640774de940a9ed9832b85a753419e46c89272 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 0000000000000000000000000000000000000000..ff3a4c70a8fd689fa7633d209b45039bb29ecc08 --- /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 b8770b3d5252f94f14e43c50b36dc07d39d5cc80..c794d995a00ff558c706418ed013dab220865d23 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} >