官网:https://protable.ant.design/

  1. yarn add @ant-design/pro-table

自定义返回数据

  1. request={async (params = {}) => {
  2. const data = await request<GithubIssueItem[]>(
  3. 'https://api.github.com/repos/ant-design/ant-design-pro/issues',
  4. {
  5. params: {
  6. ...params,
  7. page: params.current,
  8. per_page: params.pageSize,
  9. },
  10. },
  11. );
  12. const totalObj = await request(
  13. 'https://api.github.com/repos/ant-design/ant-design-pro/issues?per_page=1',
  14. {
  15. params,
  16. },
  17. );
  18. return {
  19. data,
  20. page: params.current,
  21. success: true,
  22. total: ((totalObj[0] || { number: 0 }).number - 56) as number,
  23. };
  24. }}
  25. # 标准
  26. const result = {
  27. data: dataSource,
  28. total: tableListDataSource.length,
  29. success: true,
  30. pageSize,
  31. current: parseInt(`${params.currentPage}`, 10) || 1,
  32. };

枚举-单选-渲染

  1. renderFormItem: () => {
  2. return (
  3. <Radio.Group>
  4. <Radio value={0}>albert</Radio>
  5. <Radio value={1}>Blstm</Radio>
  6. </Radio.Group>
  7. );
  8. },
  9. valueEnum: {
  10. 0: { text: 'albert'},
  11. 1: { text: 'Blstm', status: 'Processing' }
  12. },

状态可以不加

  1. status: 'Success' | 'Error' | 'Processing' | 'Warning' | 'Default';

image.png

表单文件上传

1、升级版本

  1. "@ant-design/pro-table": "^2.2.0"

2、渲染form

  1. renderFormItem: (item, { defaultRender, ...rest }, form) => {
  2. return (
  3. <Upload action="/modelInfo/upload"
  4. data={{"modelName": form.getFieldValue("modelName")}} // 额外的数据,可以不传
  5. onChange={(info) => {
  6. if (info.file.status === 'done') {
  7. form.setFieldsValue({'modelFile': info.file.response.data});
  8. message.success("上传成功");
  9. } else if (info.file.status === 'error') {
  10. message.success("上传失败");
  11. }
  12. }}>
  13. <Button>
  14. <UploadOutlined/> 上传
  15. </Button>
  16. </Upload>
  17. )
  18. },