triggerException.js 1.1 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 18
    this.setState({
      isloading: true,
    });
    this.props.dispatch({
19 20 21 22
      type: 'error/query',
      payload: {
        code,
      },
陈帅's avatar
陈帅 committed
23 24
    });
  };
陈帅's avatar
陈帅 committed
25

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