From 5684b5d579e6b25cfdb0962719b1755e3f7561d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Wed, 13 Mar 2019 14:31:46 +0800 Subject: [PATCH] feat: remove import lib (#3736) --- config/config.js | 2 +- src/components/Charts/AsyncLoadBizCharts.js | 44 --------------------- src/components/Charts/index.js | 28 +++++-------- src/pages/Dashboard/Analysis.js | 7 +--- src/pages/Dashboard/Monitor.js | 7 +--- src/pages/Dashboard/Workplace.js | 7 +--- 6 files changed, 14 insertions(+), 81 deletions(-) delete mode 100644 src/components/Charts/AsyncLoadBizCharts.js diff --git a/config/config.js b/config/config.js index 1ffa812e..9317a5b3 100644 --- a/config/config.js +++ b/config/config.js @@ -6,7 +6,7 @@ import defaultSettings from '../src/defaultSettings'; import slash from 'slash2'; const { pwa, primaryColor } = defaultSettings; -const { NODE_ENV, APP_TYPE, TEST } = process.env; +const { APP_TYPE, TEST } = process.env; const plugins = [ [ diff --git a/src/components/Charts/AsyncLoadBizCharts.js b/src/components/Charts/AsyncLoadBizCharts.js deleted file mode 100644 index 8d9a2cd0..00000000 --- a/src/components/Charts/AsyncLoadBizCharts.js +++ /dev/null @@ -1,44 +0,0 @@ -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(); - requestAnimationFrame(() => { - this.setState({ - loading: false, - }); - }); - } - - render() { - const { children } = this.props; - const { loading } = this.state; - if (!loading) { - return children; - } - return ; - } -} - -export { loadBizCharts, AsyncLoadBizCharts }; diff --git a/src/components/Charts/index.js b/src/components/Charts/index.js index 6fbcb743..294eeb65 100644 --- a/src/components/Charts/index.js +++ b/src/components/Charts/index.js @@ -1,24 +1,16 @@ -import React, { Suspense } from 'react'; import numeral from 'numeral'; import ChartCard from './ChartCard'; import Field from './Field'; - -const getComponent = Component => props => ( - - - -); - -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 WaterWave = getComponent(React.lazy(() => import('./WaterWave'))); -const TagCloud = getComponent(React.lazy(() => import('./TagCloud'))); -const TimelineChart = getComponent(React.lazy(() => import('./TimelineChart'))); +import Bar from './Bar'; +import Pie from './Pie'; +import Radar from './Radar'; +import Gauge from './Gauge'; +import MiniArea from './MiniArea'; +import MiniBar from './MiniBar'; +import MiniProgress from './MiniProgress'; +import WaterWave from './WaterWave'; +import TagCloud from './TagCloud'; +import TimelineChart from './TimelineChart'; const yuan = val => `¥ ${numeral(val).format('0,0')}`; diff --git a/src/pages/Dashboard/Analysis.js b/src/pages/Dashboard/Analysis.js index 07172cc8..0d222cc3 100644 --- a/src/pages/Dashboard/Analysis.js +++ b/src/pages/Dashboard/Analysis.js @@ -5,7 +5,6 @@ import GridContent from '@/components/PageHeaderWrapper/GridContent'; import { getTimeDistance } from '@/utils/utils'; import styles from './Analysis.less'; import PageLoading from '@/components/PageLoading'; -import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts'; const IntroduceRow = React.lazy(() => import('./IntroduceRow')); const SalesCard = React.lazy(() => import('./SalesCard')); @@ -182,8 +181,4 @@ class Analysis extends Component { } } -export default props => ( - - - -); +export default Analysis; diff --git a/src/pages/Dashboard/Monitor.js b/src/pages/Dashboard/Monitor.js index d9bb87c6..a2d812ab 100644 --- a/src/pages/Dashboard/Monitor.js +++ b/src/pages/Dashboard/Monitor.js @@ -1,5 +1,4 @@ import React, { Component } from 'react'; -import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts'; import { connect } from 'dva'; import { formatMessage, FormattedMessage } from 'umi/locale'; import { Row, Col, Card, Tooltip } from 'antd'; @@ -242,8 +241,4 @@ class Monitor extends Component { } } -export default props => ( - - - -); +export default Monitor; diff --git a/src/pages/Dashboard/Workplace.js b/src/pages/Dashboard/Workplace.js index 3e7ff986..d71b122a 100644 --- a/src/pages/Dashboard/Workplace.js +++ b/src/pages/Dashboard/Workplace.js @@ -3,7 +3,6 @@ import moment from 'moment'; import { connect } from 'dva'; import Link from 'umi/link'; import { Row, Col, Card, List, Avatar } from 'antd'; -import { AsyncLoadBizCharts } from '@/components/Charts/AsyncLoadBizCharts'; import { Radar } from '@/components/Charts'; import EditableLinkGroup from '@/components/EditableLinkGroup'; import PageHeaderWrapper from '@/components/PageHeaderWrapper'; @@ -253,8 +252,4 @@ class Workplace extends PureComponent { } } -export default props => ( - - - -); +export default Workplace; -- GitLab