官网:https://protable.ant.design/
yarn add @ant-design/pro-table
自定义返回数据
request={async (params = {}) => {
const data = await request<GithubIssueItem[]>(
'https://api.github.com/repos/ant-design/ant-design-pro/issues',
{
params: {
...params,
page: params.current,
per_page: params.pageSize,
},
},
);
const totalObj = await request(
'https://api.github.com/repos/ant-design/ant-design-pro/issues?per_page=1',
{
params,
},
);
return {
data,
page: params.current,
success: true,
total: ((totalObj[0] || { number: 0 }).number - 56) as number,
};
}}
# 标准
const result = {
data: dataSource,
total: tableListDataSource.length,
success: true,
pageSize,
current: parseInt(`${params.currentPage}`, 10) || 1,
};
枚举-单选-渲染
renderFormItem: () => {
return (
<Radio.Group>
<Radio value={0}>albert</Radio>
<Radio value={1}>Blstm</Radio>
</Radio.Group>
);
},
valueEnum: {
0: { text: 'albert'},
1: { text: 'Blstm', status: 'Processing' }
},
状态可以不加
status: 'Success' | 'Error' | 'Processing' | 'Warning' | 'Default';
表单文件上传
1、升级版本
"@ant-design/pro-table": "^2.2.0"
2、渲染form
renderFormItem: (item, { defaultRender, ...rest }, form) => {
return (
<Upload action="/modelInfo/upload"
data={{"modelName": form.getFieldValue("modelName")}} // 额外的数据,可以不传
onChange={(info) => {
if (info.file.status === 'done') {
form.setFieldsValue({'modelFile': info.file.response.data});
message.success("上传成功");
} else if (info.file.status === 'error') {
message.success("上传失败");
}
}}>
<Button>
<UploadOutlined/> 上传
</Button>
</Upload>
)
},