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';

kenve's avatar
kenve committed
7
class Exception extends React.PureComponent {
陈帅's avatar
陈帅 committed
8 9 10
  static defaultProps = {
    backText: 'back to home',
  };
11

陈帅's avatar
陈帅 committed
12 13 14 15
  constructor(props) {
    super(props);
    this.state = {};
  }
16

陈帅's avatar
陈帅 committed
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>
陈帅's avatar
陈帅 committed
55 56 57
    );
  }
}
ZHAO Jinxiang's avatar
ZHAO Jinxiang committed
58

kenve's avatar
kenve committed
59
export default Exception;