From 3928e0d61b93ae4d7b713208a981f571b1cff774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Sat, 18 Aug 2018 00:10:37 +0800 Subject: [PATCH] feat:Decoupling component dependency --- src/components/Exception/index.js | 79 +++++++++++++++++++------------ src/locales/en-US.js | 2 +- src/pages/Exception/403.js | 1 + src/pages/Exception/404.js | 1 + src/pages/Exception/500.js | 1 + 5 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/components/Exception/index.js b/src/components/Exception/index.js index e64a961a..d514cf8c 100644 --- a/src/components/Exception/index.js +++ b/src/components/Exception/index.js @@ -1,40 +1,57 @@ import React, { createElement } from 'react'; -import { injectIntl, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import { Button } from 'antd'; import config from './typeConfig'; import styles from './index.less'; -const Exception = ({ className, linkElement = 'a', type, title, desc, img, actions, ...rest }) => { - const pageType = type in config ? type : '404'; - const clsString = classNames(styles.exception, className); - return ( -
-
-
-
-
-

{title || config[pageType].title}

-
{desc || config[pageType].desc}
-
- {actions || - createElement( - linkElement, - { - to: '/', - href: '/', - }, - - )} +class Excrption extends React.PureComponent { + static defaultProps = { + backText: 'back to home', + }; + constructor(props) { + super(props); + this.state = {}; + } + render() { + const { + className, + backText, + linkElement = 'a', + type, + title, + desc, + img, + actions, + ...rest + } = this.props; + const pageType = type in config ? type : '404'; + const clsString = classNames(styles.exception, className); + return ( +
+
+
+
+
+

{title || config[pageType].title}

+
{desc || config[pageType].desc}
+
+ {actions || + createElement( + linkElement, + { + to: '/', + href: '/', + }, + + )} +
-
- ); -}; + ); + } +} -export default injectIntl(Exception); +export default Excrption; diff --git a/src/locales/en-US.js b/src/locales/en-US.js index a9f37a99..63a16bd9 100644 --- a/src/locales/en-US.js +++ b/src/locales/en-US.js @@ -36,7 +36,7 @@ export default { 'menu.account.settings': 'Account Settings', 'menu.account.trigger': 'Trigger Error', 'app.home.introduce': 'introduce', - 'app.analysis.test': 'Gongzhuan road No.{no} shop', + 'app.analysis.test': 'Gongzhuan No.{no} shop', 'app.analysis.introduce': 'Introduce', 'app.analysis.total-sales': 'total sales', 'app.analysis.day-sales': 'Day Sales', diff --git a/src/pages/Exception/403.js b/src/pages/Exception/403.js index b1c996e2..84ee0fdc 100644 --- a/src/pages/Exception/403.js +++ b/src/pages/Exception/403.js @@ -11,6 +11,7 @@ class Exception403 extends Component { desc={formatMessage({ id: 'app.exception.description.403' }, {})} style={{ minHeight: 500, height: '80%' }} linkElement={Link} + backText={formatMessage({ id: 'app.exception.back' })} /> ); } diff --git a/src/pages/Exception/404.js b/src/pages/Exception/404.js index 409fd3a1..ebec5032 100644 --- a/src/pages/Exception/404.js +++ b/src/pages/Exception/404.js @@ -11,6 +11,7 @@ class Exception404 extends Component { desc={formatMessage({ id: 'app.exception.description.404' }, {})} style={{ minHeight: 500, height: '80%' }} linkElement={Link} + backText={formatMessage({ id: 'app.exception.back' })} /> ); } diff --git a/src/pages/Exception/500.js b/src/pages/Exception/500.js index c275e8f5..e7b36ae0 100644 --- a/src/pages/Exception/500.js +++ b/src/pages/Exception/500.js @@ -11,6 +11,7 @@ class Exception500 extends Component { desc={formatMessage({ id: 'app.exception.description.500' }, {})} style={{ minHeight: 500, height: '80%' }} linkElement={Link} + backText={formatMessage({ id: 'app.exception.back' })} /> ); } -- GitLab