Skip to content

Prompts 提示词 ​

AI 对话组件。公开入口:Prompts、Prompt。

在线演示 ​

本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。

Prompts 提示词 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

Prompts 提示词

gallery 演示 Prompts 的具名 Render 函数,源码 page_chat.go#L320。

加载中…

Prompt 输入框

gallery 演示 Prompt 的具名 Render 函数,源码 page_more_confirm.go#L16。

加载中…

API ​

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

入口函数 ​

ui.Prompts ​

go
func Prompts(c *Context, items []PromptItem) *PromptsW

Prompts adds prompt cards for items.

if k, ok := ui.Prompts(c, prompts).Title("试试这样问").Wrap().Clicked(); ok { ask(k) }

返回 *PromptsW,可链式调用的方法见 PromptsW 方法。

ui.Prompt ​

go
func Prompt(c *Context, o ConfirmOptions) *ConfirmRef

Prompt opens a dialog with a text input; read the value in OnOk with d.Value().

返回 *ConfirmRef,可链式调用的方法见 ConfirmRef 方法。

PromptsW 方法 ​

ui.PromptsW:PromptsW is a group of clickable prompt suggestion cards (the empty state of a chat, follow-up questions under an answer). Not to be confused with Prompt, the input dialog.

方法说明签名
CardWidthCardWidth sets the minimum card width when wrapping (default 200).CardWidth(px float32) *PromptsW
ClickedClicked returns the key of the card activated this frame.Clicked() (string, bool)
LayoutLayout applies layout options to the group.Layout(opts ...layout.Option) *PromptsW
TitleTitle shows a heading above the cards (also the accessible name).Title(s string) *PromptsW
VerticalVertical stacks the cards in a column.Vertical() *PromptsW
WrapWrap lets the cards wrap onto more rows instead of shrinking.Wrap() *PromptsW

ConfirmRef 方法 ​

ui.ConfirmRef:ConfirmRef is a handle to an open dialog.

方法说明签名
ActionAction reports how the dialog was closed by the user ("" while open or after Close).Action() ConfirmAction
CloseClose closes the dialog without calling any callback.Close()
IsOpenIsOpen reports whether the dialog is still shown.IsOpen() bool
LoadingLoading shows (or clears) the spinner on the OK button.Loading(on bool)
ValueValue returns the Prompt input.Value() string

PromptItem 参数类型 ​

ui.PromptItem:PromptItem is one suggestion card of Prompts.

字段说明类型
Keystring
Labelstring
Descriptionstring
Icon*icon.Icon
Disabledbool

ConfirmOptions 参数类型 ​

ui.ConfirmOptions:ConfirmOptions configure Confirm, MessageBox and Prompt.

字段说明类型
Titlestring
Contentstring
StatusStatus picks the leading icon: "info", "success", "warning", "error" or "none".string
OkTextdefault "确定" ("知道了" for Ant MessageBox)string
CancelTextdefault "取消"string
Dangerred OK button (destructive actions)bool
Widthfloat32
MaskClosableMaskClosable closes the dialog (as a cancel) on a mask click.bool
OnOkOnOk runs on the UI thread when OK is activated.func(d *ConfirmRef)
OnCancelOnCancel runs on Cancel, the close button, Escape or a mask click.func()
DistinguishCancelAndCloseDistinguishCancelAndClose tells the close button, Escape and a mask click apart from Cancel: they run OnClose (not OnCancel) and ConfirmRef.Action reports ConfirmActionClose.bool
OnCloseOnClose runs when the dialog is closed without Cancel or OK (close button, Escape, mask) and DistinguishCancelAndClose is set.func()
CenterCenter centers the icon, title, content and buttons.bool
DraggableDraggable lets the user move the dialog by dragging its title.bool
IconIcon replaces the status icon; it is drawn in the status color (the primary color for Status "none").*icon.Icon
AutoFocusButtonAutoFocusButton picks the button focused when the dialog opens: "" or "ok" (default), "cancel", or "none" (antd autoFocusButton, null for none).string
NoKeyboardNoKeyboard keeps Escape from closing the dialog (antd keyboard false, Element close-on-press-escape false).bool
InputValuePrompt only.string
InputPlaceholderstring
ValidateValidate returns an error message ("" = valid); OK is refused while it fails.func(v string) string

相关链接 ​

本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。

以 MIT 许可发布