triggerException.js 1.15 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import React, { PureComponent } from 'react';
2
import { Button, Spin, Card } from 'antd';
陈帅's avatar
陈帅 committed
3 4 5 6 7 8 9
import { connect } from 'dva';
import styles from './style.less';

@connect(state => ({
  isloading: state.error.isloading,
}))
export default class TriggerException extends PureComponent {
10
  state = {
陈帅's avatar
陈帅 committed
11 12
    isloading: false,
  };
陈帅's avatar
陈帅 committed
13

jim's avatar
jim committed
14
  triggerError = code => {
陈帅's avatar
陈帅 committed
15 16 17
    this.setState({
      isloading: true,
    });
陈帅's avatar
陈帅 committed
18 19
    const { dispatch } = this.props;
    dispatch({
20 21 22 23
      type: 'error/query',
      payload: {
        code,
      },
陈帅's avatar
陈帅 committed
24 25
    });
  };
陈帅's avatar
陈帅 committed
26

陈帅's avatar
陈帅 committed
27
  render() {
陈帅's avatar
陈帅 committed
28
    const { isloading } = this.state;
陈帅's avatar
陈帅 committed
29
    return (
30
      <Card>
陈帅's avatar
陈帅 committed
31
        <Spin spinning={isloading} wrapperClassName={styles.trigger}>
32
          <Button type="danger" onClick={() => this.triggerError(401)}>
33 34
            触发401
          </Button>
35
          <Button type="danger" onClick={() => this.triggerError(403)}>
36 37
            触发403
          </Button>
38
          <Button type="danger" onClick={() => this.triggerError(500)}>
39 40
            触发500
          </Button>
41
          <Button type="danger" onClick={() => this.triggerError(404)}>
42 43 44 45
            触发404
          </Button>
        </Spin>
      </Card>
陈帅's avatar
陈帅 committed
46 47 48
    );
  }
}