Approval 权限确认
AI 对话组件。公开入口:Approval。
在线演示
本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。
Approval 权限确认 · 在线体验真实 Go 组件
在独立页面打开 ↗示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.Approval
go
func Approval(c *Context, title string) *ApprovalWApproval adds a permission card; title "" uses Locale.Chat.ApprovalTitle.
a := ui.Approval(c, "").Description("运行 shell 命令").Command("rm -rf build", "sh")
if d, ok := a.Decided(); ok { resolve(d) }
返回 *ApprovalW,可链式调用的方法见 ApprovalW 方法。
ApprovalW 方法
ui.ApprovalW:ApprovalW is a card asking the user to allow or deny an action (a tool call, a command, a file write) before the assistant goes on.
| 方法 | 说明 | 签名 |
|---|---|---|
Body | Body adds custom content above the buttons. | Body(fn func()) *ApprovalW |
Choices | Choices sets the buttons in order (default Deny, Always, Once; the last one is the primary button). | Choices(ch ...ApprovalChoice) *ApprovalW |
Command | Command shows the command or parameters as a code block in lang. | Command(code, lang string) *ApprovalW |
Decided | Decided returns the choice clicked this frame. | Decided() (ApprovalChoice, bool) |
Decision | Decision shows a decided card: the buttons give way to the outcome. | Decision(d ApprovalChoice) *ApprovalW |
Description | Description explains what will happen. | Description(s string) *ApprovalW |
Feedback | Feedback adds an optional note input bound to *note, sent with the decision. | Feedback(note *string) *ApprovalW |
Field | Field adds a labelled detail row (tool, resource, scope …). | Field(label, value string) *ApprovalW |
Layout | Layout applies layout options to the card. | Layout(opts ...layout.Option) *ApprovalW |
Risk | Risk sets the level: "warning" (default) or "error" (dangerous). | Risk(level string) *ApprovalW |
相关链接
本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。