ProDescriptions - Advanced Definition List
When to use
The advanced description list component provides a more convenient and faster solution to build a description list.
ProDescriptions was born to solve the problem of writing a lot of boilerplate code of Descriptions in the project, so many common logics are encapsulated in it. Writing a Descriptions in React will inevitably need to define some similar properties. So ProDescriptions encapsulates the request network by default, and the logic shown in the columns column.
For example, ProDescriptions encapsulates the behavior of the request network, and ProDescriptions will bring the data in props.params into the request by default. If the interface happens to be the same as our definition, it will be very simple to implement a query.
We agree that request has a parameter, and params will carry the params in props. The types are as follows:
There are also some conventions on the ProDescriptions of the results returned by the request, the types are as follows:
Code Demo
Basic definition list
Basic usage
订单备注客户要求在一季度内完成全部部署上线工作,优先安排专属技术支持团队跟进对接,确保各环节顺利推进客户要求在一季度内完成全部部署上线工作,优先安排专属技术支持团队跟进对接,确保各环节顺利推进 | |
合同金额 | 完成进度75.00% |
订单状态处理中 | 付款方式bank |
交付进度 75% | 下单时间2024-01-15 00:00:00 |
签约日期2024-01-15 | 服务周期 2024-01-15 00:00:00 ~ 2025-01-14 00:00:00 |
创建时间00:00:00 | 部署脚本 |
服务配置 | |
Array type dataIndex
Format configuration
Format the date according to format
日期2024.01.15 | 日期区间 2024.01.14 00:00:00 ~ 2024.01.15 00:00:00 |
时间2024.01.15 | 时间日期2024.01.15 00:00:00 |
更新时间3 years ago | |
ProDescriptions 格式化配置 Props 说明:
- column: 列数,设置为 2 表示每行显示 2 列
- title: 描述列表标题
- tooltip: 标题提示信息
列配置(columns)常用项:
- label: 标签文本
- valueType: 值类型,决定如何渲染数据
- fieldProps: 字段属性配置
- children: 数据内容(无 dataIndex 时作为展示值)
FieldProps 格式化配置:
- format: 格式化字符串,定义显示格式
- 自定义格式: 支持 dayjs 的所有格式化选项
ValueType 日期时间类型:
- date: 日期格式,显示年月日
- dateTime: 日期时间格式,显示年月日时分秒
- dateTimeRange: 日期时间区间格式
- time: 时间格式,显示时分秒
- fromNow: 相对时间格式,显示多久之前
格式化字符串说明:
- YYYY: 四位年份
- MM: 两位月份
- DD: 两位日期
- HH: 24小时制小时
- mm: 分钟
- ss: 秒
数据格式:
- 时间戳: 使用 dayjs().valueOf() 获取时间戳
- 数组格式: 日期区间使用数组 [start, end]
- 相对时间: fromNow 类型支持相对时间计算
Dayjs 操作:
- add: 添加时间,如 add(-1, 'month') 表示一个月前
- valueOf: 获取时间戳
- 格式化: 通过 format 方法格式化时间
使用场景:
- 日期展示: 展示各种格式的日期时间
- 时间区间: 展示时间范围
- 相对时间: 展示相对时间,如"一个月前"
- 格式化定制: 根据需求定制显示格式
最佳实践:
- 格式统一: 在项目中保持日期格式的一致性
- 用户友好: 选择用户容易理解的格式
- 国际化: 考虑不同地区的日期格式习惯
- 性能考虑: 避免频繁的时间格式化操作
Remote request data
Display the definition list by requesting interface data
ProDescriptions Request 请求 Props 说明:
- actionRef: 操作引用,用于调用组件方法
- title: 描述列表标题
- request: 异步请求函数,返回数据
- extra: 右上角额外内容
Request 请求配置:
- 异步函数: 返回 Promise 对象
- 数据格式: { success: boolean, data: object }
- 自动加载: 组件挂载时自动请求数据
- 错误处理: 自动处理请求错误
columns 与 request 配合:
- dataIndex: 数据字段名,自动绑定到 request 返回的数据
- label: 标签文本
- valueType: 值类型,决定如何渲染数据
- render: 自定义内容,如操作按钮(valueType 为 option 时放入 extra 区域)
ActionRef 操作方法:
- reload: 重新加载数据
- reset: 重置数据
- clearSelected: 清除选中状态
ValueType 类型:
- date: 日期格式,自动格式化显示
- money: 金额格式,自动添加货币符号
- option: 操作按钮,支持自定义组件
Extra 额外内容:
- React 节点: 支持任何 React 组件
- 操作按钮: 常用于添加操作按钮
- 样式控制: 可以自定义样式和交互
数据绑定特点:
- 自动绑定: 通过 dataIndex 自动绑定数据
- 类型安全: 提供完整的类型检查
- 响应式更新: 数据变化时自动更新显示
使用场景:
- 数据展示: 从 API 获取数据并展示
- 动态刷新: 通过按钮刷新数据
- 操作控制: 通过 actionRef 控制组件行为
- 用户交互: 提供用户操作界面
最佳实践:
- 错误处理: 在 request 中处理请求错误
- 加载状态: 提供加载状态反馈
- 数据验证: 验证返回数据的格式
- 用户体验: 提供清晰的操作反馈
Columns configuration
Display the definition list by requesting interface data and columns
ProDescriptions Columns 配置 Props 说明:
- title: 描述列表标题
- request: 异步请求函数,返回数据
- emptyText: 空数据时显示的文本
- columns: 列配置数组,定义每列的属性
Column 配置项:
- title: 列标题
- key: 列的唯一标识
- dataIndex: 数据字段名
- valueType: 值类型,决定如何渲染
- valueEnum: 枚举值配置
- fieldProps: 字段属性配置
- render: 自定义渲染函数
ValueType 类型:
- select: 选择框,配合 valueEnum 使用
- date: 日期格式
- switch: 开关组件
- money: 金额格式
- option: 操作按钮
- percent: 百分比格式
FieldProps 字段属性:
- format: 日期格式化字符串,如 'DD.MM.YYYY'
- moneySymbol: 货币符号,可以是字符串或 false
- 自定义属性: 根据 valueType 传递相应属性
ValueEnum 枚举配置:
- text: 显示的文本
- status: 状态类型,影响显示样式
- 支持状态: Default, Error, Success, Processing
Render 自定义渲染:
- 函数返回: 返回 React 节点数组
- 操作按钮: 常用于渲染操作链接或按钮
- 样式控制: 完全控制渲染内容的样式
列配置方式:
- columns: 通过 columns 数组统一定义全部展示项
使用场景:
- 动态列: 根据数据动态生成列配置
- 复杂展示: 展示各种类型的数据
- 操作列: 添加操作按钮或链接
- 格式化显示: 自定义数据格式化方式
最佳实践:
- 列配置: 使用 columns 配置批量定义列
- 字段属性: 通过 fieldProps 传递组件属性
- 自定义渲染: 使用 render 函数实现复杂渲染
- 类型匹配: 选择合适的 valueType 展示数据
dataSource configuration data
ProDescriptions supports the same dataSource as Table
文本这是一段文本columns | 状态全部 | 状态2open |
时间2020-08-09 | money¥1,212,100.00 | 百分比100.00% |
ProDescriptions DataSource 数据源 Props 说明:
- title: 描述列表标题
- dataSource: 数据源对象,直接提供数据
- columns: 列配置数组,定义每列的属性
DataSource 数据源配置:
- 对象格式: 直接提供数据对象
- 字段映射: 通过 dataIndex 映射到数据字段
- 静态数据: 适合展示静态或已知数据
- 性能优势: 无需异步请求,性能更好
Column 配置项:
- title: 列标题
- key: 列的唯一标识
- dataIndex: 数据字段名,对应 dataSource 中的字段
- ellipsis: 是否显示省略号
- copyable: 是否可复制
- valueType: 值类型,决定如何渲染
- valueEnum: 枚举值配置
- render: 自定义渲染函数
ValueType 类型:
- select: 选择框,配合 valueEnum 使用
- date: 日期格式
- money: 金额格式
- percent: 百分比格式
- option: 操作按钮
ValueEnum 枚举配置:
- text: 显示的文本
- status: 状态类型,影响显示样式
- 支持状态: Default, Error, Success, Processing
Render 自定义渲染:
- 函数返回: 返回 React 节点数组
- 操作按钮: 常用于渲染操作链接或按钮
- 样式控制: 完全控制渲染内容的样式
列配置方式:
- columns: 通过 columns 数组定义全部列
与 Request 的区别:
- 数据来源: dataSource 直接提供数据,request 异步获取
- 使用场景: dataSource 适合静态数据,request 适合动态数据
- 性能差异: dataSource 性能更好,无需网络请求
- 错误处理: dataSource 无需处理请求错误
使用场景:
- 静态数据: 展示已知的静态数据
- 配置展示: 展示系统配置信息
- 表单预览: 展示表单提交的数据
- 详情页面: 展示对象详细信息
最佳实践:
- 数据准备: 确保 dataSource 包含所有需要的字段
- 列配置: 使用 columns 配置批量定义列
- 类型匹配: 选择合适的 valueType 展示数据
- 性能优化: 对于静态数据优先使用 dataSource
Editable definition list
API is the same as ProTable
API
ProDescriptions
For more features, see Descriptions of antd
editable edit configuration
columns
Each item is ProDescriptionsColumn (same schema family as ProTable columns; ProDescriptionsItemProps is an alias). Common fields:
span={2}spans two description cells.
ActionRef
We need to manually trigger the update of the description list when performing an operation or tab switching. It is difficult to solve this problem with pure props, so we provide a ref to support some default operations.
ActionRef also supports some other behaviors, which will reduce your coding cost in some cases, but ref will break away from the life cycle of react, so these actions are not controlled.