sud.showModal
显示模态对话框,支持确认、取消以及文本输入。
javascript
sud.showModal(object);参数
| 属性 | 类型 | 必填 | 说明 |
|---|---|---|---|
| title | string | 否 | 对话框标题 |
| content | string | 否 | 对话框内容 |
| showCancel | boolean | 否 | 是否显示取消按钮;建议显式传入 |
| cancelText | string | 否 | 取消按钮文字,最多 4 个字符 |
| cancelColor | string | 否 | 取消按钮文字颜色,使用十六进制颜色字符串,如 #000000 |
| confirmText | string | 否 | 确认按钮文字,最多 4 个字符 |
| confirmColor | string | 否 | 确认按钮文字颜色,使用十六进制颜色字符串,如 #576B95 |
| editable | boolean | 否 | 是否显示文本输入框;建议显式传入 |
| placeholderText | string | 否 | 输入框提示文字,在 editable: true 时使用 |
| success | function | 否 | 用户点击按钮后的回调,参数见下文 |
| fail | function | 否 | 调用失败的回调 |
| complete | function | 否 | 调用结束时执行,成功、失败均执行,不传入参数 |
成功回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| confirm | boolean | 用户是否点击了确认按钮 |
| cancel | boolean | 用户是否点击了取消按钮 |
| content | string | 用户输入的内容;仅在启用输入框时使用 |
失败回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| errCode | number | 错误码 |
| errMsg | string | 错误说明 |
使用说明
使用前请确认目标 App 支持该界面能力。点击取消按钮也会进入 success,请根据 confirm 或 cancel 判断用户选择。需要输入内容时设置 editable: true,并在确认后校验 content。
示例
javascript
sud.showModal({
title: '退出游戏',
content: '确定要退出当前对局吗?',
showCancel: true,
cancelText: '取消',
cancelColor: '#000000',
confirmText: '退出',
confirmColor: '#576B95',
editable: false,
success(result) {
if (result.confirm) {
console.log('用户确认退出');
} else if (result.cancel) {
console.log('用户取消退出');
}
},
fail(error) {
console.error('显示对话框失败', error.errCode, error.errMsg);
}
});