TriggerException.js 1.17 KB
Newer Older
1
import React, { PureComponent } from 'react';
2
import { Button, Spin, Card } from 'antd';
3 4 5 6 7 8
import { connect } from 'dva';
import styles from './style.less';

@connect(state => ({
  isloading: state.error.isloading,
}))
afc163's avatar
afc163 committed
9
class TriggerException extends PureComponent {
10
  state = {
11 12
    isloading: false,
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
13

jim's avatar
jim committed
14
  triggerError = code => {
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,
      },
24 25
    });
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
26

27
  render() {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
28
    const { isloading } = this.state;
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>
46 47 48
    );
  }
}
lijiehua's avatar
lijiehua committed
49 50

export default TriggerException;