Unverified Commit 10ef3eaf authored by 陈帅's avatar 陈帅 Committed by GitHub

pref: optimize performance (#3542)

* pref: optimize performance

* pref: use less img

* pref: use less img
parent 9f84663b
...@@ -24,6 +24,7 @@ const plugins = [ ...@@ -24,6 +24,7 @@ const plugins = [
dynamicImport: { dynamicImport: {
loadingComponent: './components/PageLoading/index', loadingComponent: './components/PageLoading/index',
webpackChunkName: true, webpackChunkName: true,
level: 3,
}, },
pwa: pwa pwa: pwa
? { ? {
...@@ -76,10 +77,7 @@ export default { ...@@ -76,10 +77,7 @@ export default {
}, },
externals: { externals: {
'@antv/data-set': 'DataSet', '@antv/data-set': 'DataSet',
// if is production externals react react-dom and bizcharts bizcharts: 'BizCharts',
...(NODE_ENV === 'production'
? { react: 'React', 'react-dom': 'ReactDOM', bizcharts: 'BizCharts' }
: {}),
}, },
// proxy: { // proxy: {
// '/server/api/': { // '/server/api/': {
......
...@@ -22,7 +22,7 @@ const avatars = [ ...@@ -22,7 +22,7 @@ const avatars = [
]; ];
const avatars2 = [ const avatars2 = [
'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png', 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png', 'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png',
'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png', 'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png',
'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png', 'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png',
......
...@@ -3,7 +3,7 @@ export default { ...@@ -3,7 +3,7 @@ export default {
// 支持值为 Object 和 Array // 支持值为 Object 和 Array
'GET /api/currentUser': { 'GET /api/currentUser': {
name: 'Serati Ma', name: 'Serati Ma',
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png', avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
userid: '00000001', userid: '00000001',
email: 'antdesign@alipay.com', email: 'antdesign@alipay.com',
signature: '海纳百川,有容乃大', signature: '海纳百川,有容乃大',
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { MiniArea } from '../Charts'; import { MiniArea } from '../Charts';
import NumberInfo from '../NumberInfo'; import NumberInfo from '../NumberInfo';
import styles from './index.less'; import styles from './index.less';
function fixedZero(val) { function fixedZero(val) {
......
import React from 'react';
import PageLoading from '../PageLoading';
import { importCDN } from '@/utils/utils';
let isLoaderBizChart = false;
const loadBizCharts = async () => {
if (isLoaderBizChart) {
return Promise.resolve(true);
}
await Promise.all([
importCDN('//gw.alipayobjects.com/os/lib/bizcharts/3.4.3/umd/BizCharts.min.js'),
importCDN('//gw.alipayobjects.com/os/lib/antv/data-set/0.10.1/dist/data-set.min.js'),
]);
// eslint-disable-next-line no-console
console.log('bizCharts load success');
isLoaderBizChart = true;
return Promise.resolve(true);
};
class AsyncLoadBizCharts extends React.Component {
state = {
loading: !isLoaderBizChart,
};
async componentDidMount() {
await loadBizCharts();
this.setState({
loading: false,
});
}
render() {
const { children } = this.props;
const { loading } = this.state;
if (!loading) {
return children;
}
return <PageLoading />;
}
}
export { loadBizCharts, AsyncLoadBizCharts };
// 全局 G2 设置
import { track, setTheme } from 'bizcharts';
track(false);
const config = {
defaultColor: '#1089ff',
shape: {
interval: {
fillOpacity: 1,
},
},
};
setTheme(config);
import React, { Suspense } from 'react';
import numeral from 'numeral'; import numeral from 'numeral';
import './g2';
import ChartCard from './ChartCard'; import ChartCard from './ChartCard';
import Bar from './Bar';
import Pie from './Pie'; const getComponent = Component => {
import Radar from './Radar'; return props => {
import Gauge from './Gauge'; return (
import MiniArea from './MiniArea'; <Suspense fallback={null}>
import MiniBar from './MiniBar'; <Component {...props} />
import MiniProgress from './MiniProgress'; </Suspense>
import Field from './Field'; );
import WaterWave from './WaterWave'; };
import TagCloud from './TagCloud'; };
import TimelineChart from './TimelineChart';
const Bar = getComponent(React.lazy(() => import('./Bar')));
const Pie = getComponent(React.lazy(() => import('./Pie')));
const Radar = getComponent(React.lazy(() => import('./Radar')));
const Gauge = getComponent(React.lazy(() => import('./Gauge')));
const MiniArea = getComponent(React.lazy(() => import('./MiniArea')));
const MiniBar = getComponent(React.lazy(() => import('./MiniBar')));
const MiniProgress = getComponent(React.lazy(() => import('./MiniProgress')));
const Field = getComponent(React.lazy(() => import('./Field')));
const WaterWave = getComponent(React.lazy(() => import('./WaterWave')));
const TagCloud = getComponent(React.lazy(() => import('./TagCloud')));
const TimelineChart = getComponent(React.lazy(() => import('./TimelineChart')));
const yuan = val => ${numeral(val).format('0,0')}`; const yuan = val => ${numeral(val).format('0,0')}`;
......
...@@ -3,6 +3,8 @@ import { notification, Button, message } from 'antd'; ...@@ -3,6 +3,8 @@ import { notification, Button, message } from 'antd';
import { formatMessage } from 'umi/locale'; import { formatMessage } from 'umi/locale';
import defaultSettings from './defaultSettings'; import defaultSettings from './defaultSettings';
window.React = React;
const { pwa } = defaultSettings; const { pwa } = defaultSettings;
// if pwa is true // if pwa is true
if (pwa) { if (pwa) {
......
...@@ -74,7 +74,7 @@ class BaseView extends Component { ...@@ -74,7 +74,7 @@ class BaseView extends Component {
if (currentUser.avatar) { if (currentUser.avatar) {
return currentUser.avatar; return currentUser.avatar;
} }
const url = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'; const url = 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png';
return url; return url;
} }
......
import React, { Component, Suspense } from 'react'; import React, { Component, Suspense } from 'react';
import { connect } from 'dva'; import { connect } from 'dva';
import { Row, Col, Icon, Menu, Dropdown } from 'antd'; import { Row, Col, Icon, Menu, Dropdown } from 'antd';
import GridContent from '@/components/PageHeaderWrapper/GridContent'; import GridContent from '@/components/PageHeaderWrapper/GridContent';
import { getTimeDistance } from '@/utils/utils'; import { getTimeDistance } from '@/utils/utils';
import styles from './Analysis.less'; import styles from './Analysis.less';
import PageLoading from '@/components/PageLoading'; import PageLoading from '@/components/PageLoading';
import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts';
const IntroduceRow = React.lazy(() => import('./IntroduceRow')); const IntroduceRow = React.lazy(() => import('./IntroduceRow'));
const SalesCard = React.lazy(() => import('./SalesCard')); const SalesCard = React.lazy(() => import('./SalesCard'));
...@@ -26,6 +25,7 @@ class Analysis extends Component { ...@@ -26,6 +25,7 @@ class Analysis extends Component {
}; };
componentDidMount() { componentDidMount() {
console.log('run');
const { dispatch } = this.props; const { dispatch } = this.props;
this.reqRef = requestAnimationFrame(() => { this.reqRef = requestAnimationFrame(() => {
dispatch({ dispatch({
...@@ -184,4 +184,8 @@ class Analysis extends Component { ...@@ -184,4 +184,8 @@ class Analysis extends Component {
} }
} }
export default Analysis; export default props => (
<AsyncLoadBizCharts>
<Analysis {...props} />
</AsyncLoadBizCharts>
);
import React, { PureComponent } from 'react'; import React, { Component } from 'react';
import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts';
import { connect } from 'dva'; import { connect } from 'dva';
import { formatMessage, FormattedMessage } from 'umi/locale'; import { formatMessage, FormattedMessage } from 'umi/locale';
import { Row, Col, Card, Tooltip } from 'antd'; import { Row, Col, Card, Tooltip } from 'antd';
...@@ -8,7 +9,6 @@ import CountDown from '@/components/CountDown'; ...@@ -8,7 +9,6 @@ import CountDown from '@/components/CountDown';
import ActiveChart from '@/components/ActiveChart'; import ActiveChart from '@/components/ActiveChart';
import numeral from 'numeral'; import numeral from 'numeral';
import GridContent from '@/components/PageHeaderWrapper/GridContent'; import GridContent from '@/components/PageHeaderWrapper/GridContent';
import Authorized from '@/utils/Authorized'; import Authorized from '@/utils/Authorized';
import styles from './Monitor.less'; import styles from './Monitor.less';
...@@ -27,7 +27,7 @@ const havePermissionAsync = new Promise(resolve => { ...@@ -27,7 +27,7 @@ const havePermissionAsync = new Promise(resolve => {
monitor, monitor,
loading: loading.models.monitor, loading: loading.models.monitor,
})) }))
class Monitor extends PureComponent { class Monitor extends Component {
componentDidMount() { componentDidMount() {
const { dispatch } = this.props; const { dispatch } = this.props;
dispatch({ dispatch({
...@@ -110,7 +110,7 @@ class Monitor extends PureComponent { ...@@ -110,7 +110,7 @@ class Monitor extends PureComponent {
} }
> >
<img <img
src="https://gw.alipayobjects.com/zos/rmsportal/HBWnDEUXCnGnGrRfrpKa.png" src="https://gw.alipayobjects.com/zos/antfincdn/h%24wFbzuuzz/HBWnDEUXCnGnGrRfrpKa.png"
alt="map" alt="map"
/> />
</Tooltip> </Tooltip>
...@@ -242,4 +242,8 @@ class Monitor extends PureComponent { ...@@ -242,4 +242,8 @@ class Monitor extends PureComponent {
} }
} }
export default Monitor; export default props => (
<AsyncLoadBizCharts>
<Monitor {...props} />
</AsyncLoadBizCharts>
);
...@@ -3,7 +3,7 @@ import moment from 'moment'; ...@@ -3,7 +3,7 @@ import moment from 'moment';
import { connect } from 'dva'; import { connect } from 'dva';
import Link from 'umi/link'; import Link from 'umi/link';
import { Row, Col, Card, List, Avatar } from 'antd'; import { Row, Col, Card, List, Avatar } from 'antd';
import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts';
import { Radar } from '@/components/Charts'; import { Radar } from '@/components/Charts';
import EditableLinkGroup from '@/components/EditableLinkGroup'; import EditableLinkGroup from '@/components/EditableLinkGroup';
import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import PageHeaderWrapper from '@/components/PageHeaderWrapper';
...@@ -253,4 +253,8 @@ class Workplace extends PureComponent { ...@@ -253,4 +253,8 @@ class Workplace extends PureComponent {
} }
} }
export default Workplace; export default props => (
<AsyncLoadBizCharts>
<Workplace {...props} />
</AsyncLoadBizCharts>
);
...@@ -9,12 +9,6 @@ ...@@ -9,12 +9,6 @@
/> />
<title>Ant Design Pro</title> <title>Ant Design Pro</title>
<link rel="icon" href="/favicon.png" type="image/x-icon" /> <link rel="icon" href="/favicon.png" type="image/x-icon" />
<% if(context.env === 'production') { %>
<script src="//gw.alipayobjects.com/os/lib/react/16.8.1/umd/react.production.min.js"></script>
<script src="//gw.alipayobjects.com/os/lib/react-dom/16.8.1/umd/react-dom.production.min.js"></script>
<script src="//gw.alipayobjects.com/os/lib/bizcharts/3.4.3/umd/BizCharts.min.js"></script>
<% }%>
<script src="https://gw.alipayobjects.com/os/lib/antv/data-set/0.10.1/dist/data-set.min.js"></script>
</head> </head>
<body> <body>
<noscript>Sorry, we need js to run correctly!</noscript> <noscript>Sorry, we need js to run correctly!</noscript>
......
...@@ -181,3 +181,14 @@ export function formatWan(val) { ...@@ -181,3 +181,14 @@ export function formatWan(val) {
export function isAntdPro() { export function isAntdPro() {
return window.location.hostname === 'preview.pro.ant.design'; return window.location.hostname === 'preview.pro.ant.design';
} }
export const importCDN = (url, name) =>
new Promise(resolve => {
const dom = document.createElement('script');
dom.src = url;
dom.type = 'text/javascript';
dom.onload = () => {
resolve(window[name]);
};
document.head.appendChild(dom);
});
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