Result结果

用于反馈一系列操作任务的处理结果。

何时使用

当有重要操作需告知用户处理结果,且反馈内容较为复杂时使用。

代码演示

Result结果 - 图1

基本

默认支持的各种状态的展示。

  1. import { Result, Radio, Button } from 'antd';
  2. const StatusMap = {
  3. '403': {
  4. title: '403',
  5. subTitle: 'Sorry, you are not authorized to access this page.',
  6. extra: <Button type="primary">Back Home</Button>,
  7. },
  8. '404': {
  9. title: '404',
  10. subTitle: 'Sorry, the page you visited does not exist.',
  11. extra: <Button type="primary">Back Home</Button>,
  12. },
  13. '500': {
  14. title: '500',
  15. subTitle: 'Sorry, the server is wrong.',
  16. extra: <Button type="primary">Back Home</Button>,
  17. },
  18. success: {
  19. title: 'Successfully Purchased Cloud Server ECS!',
  20. subTitle:
  21. 'Order number: 2017182818828182881 Cloud server configuration takes 1-5 minutes, please wait.',
  22. extra: [
  23. <Button type="primary" key="console">
  24. Go Console
  25. </Button>,
  26. <Button key="buy">Buy Again</Button>,
  27. ],
  28. },
  29. info: {
  30. title: 'Your operation has been executed',
  31. extra: (
  32. <Button type="primary" key="console">
  33. Go Console
  34. </Button>
  35. ),
  36. },
  37. error: {
  38. title: 'Submission Failed',
  39. subTitle: 'Please check and modify the following information before resubmitting.',
  40. extra: [
  41. <Button type="primary" key="console">
  42. Go Console
  43. </Button>,
  44. ],
  45. },
  46. warning: {
  47. title: 'There are some problems with your operation.',
  48. extra: (
  49. <Button type="primary" key="console">
  50. Go Console
  51. </Button>
  52. ),
  53. },
  54. };
  55. const StatusArray = Object.keys(StatusMap);
  56. class ResultDemo extends React.Component {
  57. state = {
  58. status: '403',
  59. };
  60. onChange = e => {
  61. console.log('status checked', e.target.value);
  62. this.setState({
  63. status: e.target.value,
  64. });
  65. };
  66. render() {
  67. const { status } = this.state;
  68. const resultProps = StatusMap[status];
  69. return (
  70. <div>
  71. <p>
  72. <Radio.Group onChange={this.onChange} value={status}>
  73. {StatusArray.map(statusItem => (
  74. <Radio value={statusItem}>{statusItem}</Radio>
  75. ))}
  76. </Radio.Group>
  77. </p>
  78. <Result status={status} {...resultProps} />
  79. </div>
  80. );
  81. }
  82. }
  83. ReactDOM.render(<ResultDemo />, mountNode);

Result结果 - 图2

复杂的例子

提供更加复杂的反馈。

  1. import { Result, Button, Icon, Typography } from 'antd';
  2. const { Title, Paragraph } = Typography;
  3. ReactDOM.render(
  4. <Result
  5. status="error"
  6. title="Submission Failed"
  7. subTitle="Please check and modify the following information before resubmitting."
  8. extra={[
  9. <Button type="primary" key="console">
  10. Go Console
  11. </Button>,
  12. <Button key="buy">Buy Again</Button>,
  13. ]}
  14. >
  15. <div className="desc">
  16. <Title level={4}>The content you submitted has the following error:</Title>
  17. <Paragraph>
  18. <Icon style={{ color: 'red' }} type="close-circle" /> Your account has been frozen{' '}
  19. <a>Thaw immediately &gt;</a>
  20. </Paragraph>
  21. <Paragraph>
  22. <Icon type="close-circle" /> Your account is not yet eligible to apply{' '}
  23. <a>Apply immediately &gt;</a>
  24. </Paragraph>
  25. </div>
  26. </Result>,
  27. mountNode,
  28. );

Result结果 - 图3

自定义 icon

自定义 icon。

  1. import { Result, Icon, Button } from 'antd';
  2. ReactDOM.render(
  3. <Result
  4. icon={<Icon type="smile" theme="twoTone" />}
  5. title="Great, we have done all the operations!"
  6. extra={<Button type="primary">Next</Button>}
  7. />,
  8. mountNode,
  9. );

API

参数说明类型默认值版本
titletitle 文字ReactNode-3.20.0
subTitlesubTitle 文字ReactNode-3.20.0
status结果的状态,决定图标和颜色'success' | 'error' | 'info' | 'warning'| '404' | '403' | '500''info'3.20.0
icon自定义 iconstring | ReactNode-3.20.0
extra操作区ReactNode-3.20.0