index.js 1.43 KB
Newer Older
偏右's avatar
偏右 committed
1
import React, { createElement } from 'react';
2 3 4 5 6
import classNames from 'classnames';
import { Button } from 'antd';
import config from './typeConfig';
import styles from './index.less';

7 8 9 10
class Excrption extends React.PureComponent {
  static defaultProps = {
    backText: 'back to home',
  };
11

12 13 14 15
  constructor(props) {
    super(props);
    this.state = {};
  }
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  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 (
      <div className={clsString} {...rest}>
        <div className={styles.imgBlock}>
          <div
            className={styles.imgEle}
            style={{ backgroundImage: `url(${img || config[pageType].img})` }}
          />
        </div>
        <div className={styles.content}>
          <h1>{title || config[pageType].title}</h1>
          <div className={styles.desc}>{desc || config[pageType].desc}</div>
          <div className={styles.actions}>
            {actions ||
              createElement(
                linkElement,
                {
                  to: '/',
                  href: '/',
                },
                <Button type="primary">{backText}</Button>
              )}
          </div>
53 54
        </div>
      </div>
55 56 57
    );
  }
}
ZHAO Jinxiang's avatar
ZHAO Jinxiang committed
58

59
export default Excrption;