ProDescriptions 高级描述列表
按字段定义展示详情数据,并支持远程加载和单项行内编辑。
何时使用
- 规则、订单、用户等详情页的结构化字段展示。
- 需要按
ValueType格式化金额、日期、状态或进度时使用。 - 静态少量字段可用 Descriptions 描述列表。
在线体验
基本用法
import "github.com/tangoui/tango/ui"
var detail = ui.ProValues{"name": "TradeCode 99", "amount": 12800.5}
func page(c *ui.Context) {
items := []ui.ProDescItem{{Key: "name", Label: "名称"}, {Key: "amount", Label: "金额", ValueType: ui.ValueMoney}}
ui.ProDescriptions(c, items).Title("规则详情").Column(2).Bordered().DataSource(&detail).Show()
}常见用法
远程数据
func remote(c *ui.Context, items []ui.ProDescItem) {
ui.ProDescriptions(c, items).Request(func() (map[string]any, error) {
return map[string]any{"name": "TradeCode 99"}, nil
}).Show()
}行内编辑
func editable(c *ui.Context, items []ui.ProDescItem) {
ui.ProDescriptions(c, items).Editable(func(key string, v any, all ui.ProValues, done func(error)) {
done(nil)
}).Show()
}布局和尺寸
func vertical(c *ui.Context, items []ui.ProDescItem) {
ui.ProDescriptions(c, items).Column(3).Size(ui.Middle).Vertical().Show()
}主题与样式
ProDescriptions 复用描述列表、ProField 和 Pro 值类型的令牌;状态、标签和金额与 ProTable 显示一致。
注意事项
DataSource 绑定外部值;Request 的加载状态和错误由组件保存。编辑回调需要调用 done,失败时传入错误以保持编辑状态。字段 Key 必须稳定。
示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.ProDescriptions
func ProDescriptions(c *Context, items []ProDescItem) *ProDescriptionsWProDescriptions starts a description list over items; chain options, then Show.
返回 *ProDescriptionsW,可链式调用的方法见 ProDescriptionsW 方法。
ProDescriptionsW 方法
ui.ProDescriptionsW:ProDescriptionsW is a description list driven by item definitions (Ant Design Pro ProDescriptions): values formatted by value type, data loaded by a request function with a loading state, and inline editing of single items with save / cancel.
ui.ProDescriptions(c, items).Title("Rule").Column(2).Bordered().
Request(func() (map[string]any, error) { return api.Rule(id) }).
Editable(func(key string, v any, all ui.ProValues, done func(error)) { go save(key, v, done) }).
Show()
| 方法 | 说明 | 签名 |
|---|---|---|
Bordered | Bordered draws the table-like bordered style. | Bordered() *ProDescriptionsW |
Column | Column sets the number of columns (default: Descriptions' DEFAULT_COLUMN_MAP, 1 on xs, 2 on sm, 3 from md up). | Column(n int) *ProDescriptionsW |
ColumnAt | ColumnAt sets the number of columns from breakpoint bp upwards. | ColumnAt(bp Breakpoint, n int) *ProDescriptionsW |
Columns | Columns sets the number of columns for several breakpoints. | Columns(m map[Breakpoint]int) *ProDescriptionsW |
DataSource | DataSource binds the values (inline edits are written into it). | DataSource(v *ProValues) *ProDescriptionsW |
Editable | Editable turns on inline editing: every item without ReadOnly gets an edit icon. | Editable(onSave func(key string, v any, all ProValues, done func(error))) *ProDescriptionsW |
Editing | Editing reports whether the item key is being edited. | Editing(key string) bool |
Err | Err returns the last request error. | Err() error |
Extra | Extra builds actions right of the heading. | Extra(fn func()) *ProDescriptionsW |
ID | ID returns the widget ID (valid after Show). | ID() ID |
Loading | Loading reports a pending request. | Loading() bool |
Reload | Reload runs the request again (valid after Show). | Reload() |
Request | Request loads the values on a background goroutine; the list shows a loading mask meanwhile and an error banner when it fails. | Request(fn func() (map[string]any, error)) *ProDescriptionsW |
Saved | Saved returns the key of the item committed this frame ("" if none). | Saved() string |
Show | Show builds the list. | Show() *ProDescriptionsW |
Size | Size sets the density (Large default, Middle, Small). | Size(s ControlSize) *ProDescriptionsW |
Title | Title sets the heading. | Title(s string) *ProDescriptionsW |
Values | Values returns the current values. | Values() ProValues |
Vertical | Vertical puts labels above values. | Vertical() *ProDescriptionsW |
ProDescItem 参数类型
ui.ProDescItem:ProDescItem is one entry of ProDescriptions. ValueType and ValueEnum use the ProTable / ProForm value types (text, money, digit, percent, date, dateTime, select, status, tag, progress, textarea ...): they format the value and pick the inline editor.
| 字段 | 说明 | 类型 |
|---|---|---|
Key | string | |
Label | string | |
ValueType | string | |
ValueEnum | []ProEnum | |
Span | columns taken (default 1) | int |
ReadOnly | ReadOnly keeps the item out of inline editing. | bool |
Render | Render replaces the value display (all holds every value). | func(c *Context, v any, all ProValues) |
Field | Field configures the inline editor (Required, Rules, Min / Max, Placeholder, Options ...). | *ProField |