Commit 782b8035 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

Optimize performance

parent e9799a33
...@@ -28,4 +28,23 @@ export default { ...@@ -28,4 +28,23 @@ export default {
publicPath: '/', publicPath: '/',
disableDynamicImport: true, disableDynamicImport: true,
hash: true, hash: true,
cssLoaderOptions: {
modules: true,
getLocalIdent: (context, localIdentName, localName) => {
if (context.resourcePath.includes('node_modules')) {
return localName;
}
let antdProPath = context.resourcePath.match(/src(.*)/)[1];
if (context.resourcePath.includes('components')) {
antdProPath = antdProPath.replace('components/', '');
}
const arr = antdProPath
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
arr.pop();
return `antd-pro${arr.join('-')}-${localName}`.replace('--', '-');
},
},
}; };
...@@ -25,7 +25,6 @@ class Bar extends Component { ...@@ -25,7 +25,6 @@ class Bar extends Component {
if (!this.node) { if (!this.node) {
return; return;
} }
requestAnimationFrame(() => {
const canvasWidth = this.node.parentNode.clientWidth; const canvasWidth = this.node.parentNode.clientWidth;
const { data = [], autoLabel = true } = this.props; const { data = [], autoLabel = true } = this.props;
if (!autoLabel) { if (!autoLabel) {
...@@ -45,7 +44,6 @@ class Bar extends Component { ...@@ -45,7 +44,6 @@ class Bar extends Component {
autoHideXLabels: false, autoHideXLabels: false,
}); });
} }
});
} }
handleRoot = n => { handleRoot = n => {
......
import React from 'react'; import React from 'react';
import { Card, Spin } from 'antd'; import { Card } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import styles from './index.less'; import styles from './index.less';
...@@ -19,18 +19,23 @@ const renderTotal = total => { ...@@ -19,18 +19,23 @@ const renderTotal = total => {
return totalDom; return totalDom;
}; };
const ChartCard = ({ class ChartCard extends React.PureComponent {
loading = false, state = {
contentHeight, loading: true,
title, };
avatar, componentDidMount() {
action, requestAnimationFrame(() => {
total, this.setState({
footer, loading: false,
children, });
...rest });
}) => { }
const content = ( renderConnet = () => {
const { contentHeight, title, avatar, action, total, footer, children, loading } = this.props;
if (loading || this.state.loading) {
return false;
}
return (
<div className={styles.chartCard}> <div className={styles.chartCard}>
<div <div
className={classNames(styles.chartTop, { className={classNames(styles.chartTop, {
...@@ -62,16 +67,29 @@ const ChartCard = ({ ...@@ -62,16 +67,29 @@ const ChartCard = ({
)} )}
</div> </div>
); );
};
render() {
const {
loading = false,
contentHeight,
title,
avatar,
action,
total,
footer,
children,
...rest
} = this.props;
return ( return (
<Card bodyStyle={{ padding: '20px 24px 8px 24px' }} {...rest}> <Card
{ loading={loading || this.state.loading}
<Spin spinning={loading} wrapperClassName={styles.spin}> bodyStyle={{ padding: '20px 24px 8px 24px' }}
{content} {...rest}
</Spin> >
} {this.renderConnet()}
</Card> </Card>
); );
}; }
}
export default ChartCard; export default ChartCard;
...@@ -19,7 +19,13 @@ export default class Pie extends Component { ...@@ -19,7 +19,13 @@ export default class Pie extends Component {
}; };
componentDidMount() { componentDidMount() {
window.addEventListener('resize', this.resize, { passive: true }); window.addEventListener(
'resize',
() => {
requestAnimationFrame(() => this.resize());
},
{ passive: true }
);
} }
componentDidUpdate(preProps) { componentDidUpdate(preProps) {
...@@ -66,7 +72,6 @@ export default class Pie extends Component { ...@@ -66,7 +72,6 @@ export default class Pie extends Component {
@Bind() @Bind()
@Debounce(300) @Debounce(300)
resize() { resize() {
requestAnimationFrame(() => {
const { hasLegend } = this.props; const { hasLegend } = this.props;
if (!hasLegend || !this.root) { if (!hasLegend || !this.root) {
window.removeEventListener('resize', this.resize); window.removeEventListener('resize', this.resize);
...@@ -83,7 +88,6 @@ export default class Pie extends Component { ...@@ -83,7 +88,6 @@ export default class Pie extends Component {
legendBlock: false, legendBlock: false,
}); });
} }
});
} }
handleRoot = n => { handleRoot = n => {
......
...@@ -17,7 +17,13 @@ export default class WaterWave extends PureComponent { ...@@ -17,7 +17,13 @@ export default class WaterWave extends PureComponent {
this.renderChart(); this.renderChart();
this.resize(); this.resize();
}); });
window.addEventListener('resize', this.resize, { passive: true }); window.addEventListener(
'resize',
() => {
requestAnimationFrame(() => this.resize());
},
{ passive: true }
);
} }
componentWillUnmount() { componentWillUnmount() {
...@@ -29,7 +35,6 @@ export default class WaterWave extends PureComponent { ...@@ -29,7 +35,6 @@ export default class WaterWave extends PureComponent {
} }
resize = () => { resize = () => {
requestAnimationFrame(() => {
if (this.root) { if (this.root) {
const { height } = this.props; const { height } = this.props;
const { offsetWidth } = this.root.parentNode; const { offsetWidth } = this.root.parentNode;
...@@ -37,7 +42,6 @@ export default class WaterWave extends PureComponent { ...@@ -37,7 +42,6 @@ export default class WaterWave extends PureComponent {
radio: offsetWidth < height ? offsetWidth / height : 1, radio: offsetWidth < height ? offsetWidth / height : 1,
}); });
} }
});
}; };
renderChart() { renderChart() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment