外观
system.prompt 补充 API
约 306 字大约 1 分钟
2026-07-15
官网只列出 showToast();固件还注册并实现 showDialog()。
prompt.showDialog(options)
| 参数 | 类型 | 必填 | 默认值 |
|---|---|---|---|
title | String | 否 | "" |
message | String | 是 | — |
autocancel | Boolean | 否 | true |
success | Function | 否 | 接收 { index: integer } |
cancel | Function | 否 | 无参数 |
complete | Function | 否 | 无参数 |
同步返回 void。success 返回被点击按钮的索引;cancel 表示弹窗被取消(例如允许点按外部区域时),不是某个按钮索引。
prompt.showDialog({
title: '提示',
message: '确认继续?',
autocancel: true,
success: res => console.log('button index', res.index),
cancel: () => console.log('cancelled')
})Promise 封装
function showDialog(options) {
return new Promise((resolve, reject) => {
prompt.showDialog({
...options,
success: ({ index }) => resolve({ type: 'button', index }),
cancel: () => resolve({ type: 'cancel' }),
complete: () => {}
})
})
}
const result = await showDialog({
title: '提示',
message: '确认继续?',
autocancel: false
})JIDL 没有定义 fail 回调,因此参数错误或 UI 管理器不可用时,不一定能像其他 feature 一样收到 (message, code)。调用前应确保应用仍在前台、页面未销毁,并避免同时弹出多个对话框。
JIDL 中还存在 { text, color } 的 button 结构痕迹,但当前 DialogInfo 没有稳定公开的按钮数组字段,不应依赖。
机型可用性
| Xiaomi Smart Band 10 Pro | Xiaomi Watch S4 41mm |
|---|---|
| ✅ | ✅ |