index.js 1.47 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 {
8 9
  static defaultProps = {
    backText: 'back to home',
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
10
    redirect: '/',
11
  };
12

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

18 19 20 21 22 23 24 25 26 27
  render() {
    const {
      className,
      backText,
      linkElement = 'a',
      type,
      title,
      desc,
      img,
      actions,
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
28
      redirect,
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
      ...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,
                {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
49 50
                  to: redirect,
                  href: redirect,
51 52 53 54
                },
                <Button type="primary">{backText}</Button>
              )}
          </div>
55 56
        </div>
      </div>
57 58 59
    );
  }
}
ZHAO Jinxiang's avatar
ZHAO Jinxiang committed
60

kenve's avatar
kenve committed
61
export default Exception;