Skip to content

ProDescriptions 高级描述列表 ​

按字段定义展示详情数据,并支持远程加载和单项行内编辑。

何时使用 ​

  • 规则、订单、用户等详情页的结构化字段展示。
  • 需要按 ValueType 格式化金额、日期、状态或进度时使用。
  • 静态少量字段可用 Descriptions 描述列表。

在线体验 ​

ProDescriptions 高级描述列表 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

基本用法 ​

go
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()
}

常见用法 ​

远程数据 ​

go
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()
}

行内编辑 ​

go
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()
}

布局和尺寸 ​

go
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 入门。

ProDescriptions 高级描述列表

gallery 演示 ProDescriptions 的注册调用(含 Render 函数),源码 page_pro3_desc.go#L34。

加载中…

Pro v6 · 详情页

gallery 演示 ProPatternDetail 的具名 Render 函数,源码 page_pro4_patterns.go#L95。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.ProDescriptions ​

go
func ProDescriptions(c *Context, items []ProDescItem) *ProDescriptionsW

ProDescriptions 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()
方法说明签名
BorderedBordered draws the table-like bordered style.Bordered() *ProDescriptionsW
ColumnColumn sets the number of columns (default: Descriptions' DEFAULT_COLUMN_MAP, 1 on xs, 2 on sm, 3 from md up).Column(n int) *ProDescriptionsW
ColumnAtColumnAt sets the number of columns from breakpoint bp upwards.ColumnAt(bp Breakpoint, n int) *ProDescriptionsW
ColumnsColumns sets the number of columns for several breakpoints.Columns(m map[Breakpoint]int) *ProDescriptionsW
DataSourceDataSource binds the values (inline edits are written into it).DataSource(v *ProValues) *ProDescriptionsW
EditableEditable 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
EditingEditing reports whether the item key is being edited.Editing(key string) bool
ErrErr returns the last request error.Err() error
ExtraExtra builds actions right of the heading.Extra(fn func()) *ProDescriptionsW
IDID returns the widget ID (valid after Show).ID() ID
LoadingLoading reports a pending request.Loading() bool
ReloadReload runs the request again (valid after Show).Reload()
RequestRequest 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
SavedSaved returns the key of the item committed this frame ("" if none).Saved() string
ShowShow builds the list.Show() *ProDescriptionsW
SizeSize sets the density (Large default, Middle, Small).Size(s ControlSize) *ProDescriptionsW
TitleTitle sets the heading.Title(s string) *ProDescriptionsW
ValuesValues returns the current values.Values() ProValues
VerticalVertical 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.

字段说明类型
Keystring
Labelstring
ValueTypestring
ValueEnum[]ProEnum
Spancolumns taken (default 1)int
ReadOnlyReadOnly keeps the item out of inline editing.bool
RenderRender replaces the value display (all holds every value).func(c *Context, v any, all ProValues)
FieldField configures the inline editor (Required, Rules, Min / Max, Placeholder, Options ...).*ProField

相关链接 ​

以 MIT 许可发布