1# @system.prompt (弹窗) 2<!--Kit: ArkUI--> 3<!--Subsystem: ArkUI--> 4<!--Owner: @houguobiao--> 5<!--Designer: @houguobiao--> 6<!--Tester: @lxl007--> 7<!--Adviser: @HelloCrease--> 8 9创建并显示文本提示框、对话框和操作菜单。 10 11> **说明:** 12> 13> - 从API Version 8 开始,该接口不再维护,推荐使用新接口[@ohos.promptAction (弹窗)](js-apis-promptAction.md)。 14> 15> 16> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 17 18 19## 导入模块 20 21 22```ts 23import prompt from '@system.prompt'; 24``` 25 26## prompt.showToast 27 28showToast(options: ShowToastOptions): void 29 30显示文本弹窗。 31 32**系统能力:** SystemCapability.ArkUI.ArkUI.Full 33 34**参数:** 35 36| 参数名 | 类型 | 必填 | 说明 | 37| ------- | ------------------------------------- | ---- | --------------- | 38| options | [ShowToastOptions](#showtoastoptions) | 是 | 定义ShowToast的选项。 | 39 40**示例:** 41 42```ts 43import prompt from '@system.prompt'; 44class A{ 45 showToast() { 46 prompt.showToast({ 47 message: 'Message Info', 48 duration: 2000 49 }); 50 } 51} 52export default new A() 53``` 54 55 56## prompt.showDialog 57 58showDialog(options: ShowDialogOptions): void 59 60显示对话框。 61 62**系统能力:** SystemCapability.ArkUI.ArkUI.Full 63 64**参数:** 65 66| 参数名 | 类型 | 必填 | 说明 | 67| ------- | --------------------------------------- | ---- | ----------- | 68| options | [ShowDialogOptions](#showdialogoptions) | 是 | 定义显示对话框的选项。 | 69 70 71**示例:** 72 73```ts 74import prompt from '@system.prompt'; 75class B{ 76 showDialog() { 77 prompt.showDialog({ 78 title: 'Title Info', 79 message: 'Message Info', 80 buttons: [ 81 { 82 text: 'button', 83 color: '#666666' 84 }, 85 ], 86 success: (data)=> { 87 console.log('dialog success callback,click button : ' + data.index); 88 }, 89 cancel: ()=> { 90 console.log('dialog cancel callback'); 91 }, 92 }); 93 } 94} 95export default new B() 96``` 97 98## prompt.showActionMenu<sup>6+</sup> 99 100showActionMenu(options: ShowActionMenuOptions): void 101 102显示操作菜单。 103 104**系统能力:** SystemCapability.ArkUI.ArkUI.Full 105 106**参数:** 107 108| 参数名 | 类型 | 必填 | 说明 | 109| ------- | ---------------------------------------- | ---- | -------------------- | 110| options | [ShowActionMenuOptions](#showactionmenuoptions6) | 是 | 定义ShowActionMenu的选项。 | 111 112 113**示例:** 114 115```ts 116import prompt from '@system.prompt'; 117class C{ 118 showActionMenu() { 119 prompt.showActionMenu({ 120 title: 'Title Info', 121 buttons: [ 122 { 123 text: 'item1', 124 color: '#666666' 125 }, 126 { 127 text: 'item2', 128 color: '#000000' 129 }, 130 ], 131 success: (tapIndex)=> { 132 console.log('dialog success callback,click button : ' + tapIndex); 133 }, 134 fail: (errMsg)=> { 135 console.log('dialog fail callback' + errMsg); 136 }, 137 }); 138 } 139} 140export default new C() 141``` 142## ShowToastOptions 143 144定义ShowToast的选项。 145 146**系统能力:** 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full 147 148| 名称 | 类型 | 必填 | 说明 | 149| ------------------- | -------------- | ---- | ---------------------------------------- | 150| message | string | 是 | 显示的文本信息。 | 151| duration | number | 否 | 默认值1500ms,建议区间:1500ms-10000ms。若小于1500ms则取默认值,最大取值为10000ms。 | 152| bottom<sup>5+</sup> | string\|number | 否 | 设置弹窗边框距离屏幕底部的位置。 | 153 154## Button 155 156定义按钮的提示信息。 157 158**系统能力:** 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full 159 160| 名称 | 类型 | 必填 | 说明 | 161| ----- | ------ | ---- | ------- | 162| text | string | 是 | 定义按钮信息。 | 163| color | string | 是 | 定义按钮颜色。 | 164 165## ShowDialogSuccessResponse 166 167定义ShowDialog的响应。 168 169**系统能力:** 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full 170 171| 名称 | 类型 | 必填 | 说明 | 172| ----- | ------ | ---- | ---------- | 173| index | number | 是 | 定义数据的索引信息。 | 174 175## ShowDialogOptions 176 177定义显示对话框的选项。 178 179**系统能力:** 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full 180 181| 名称 | 类型 | 必填 | 说明 | 182| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 183| title | string | 否 | 标题文本。 | 184| message | string | 否 | 文本内容。 | 185| buttons | [[Button](#button), [Button](#button)?, [Button](#button)?] | 否 | 对话框中按钮的数组,结构为:{text:'button', color: '\#666666'},支持1-6个按钮。大于6个按钮时弹窗不显示。 | 186| success | (data: [ShowDialogSuccessResponse](#showdialogsuccessresponse)) => void | 否 | 接口调用成功的回调函数。 | 187| cancel | (data: string, code: string) => void | 否 | 接口调用失败的回调函数。 | 188| complete | (data: string) => void | 否 | 接口调用结束的回调函数。 | 189 190## ShowActionMenuOptions<sup>6+</sup> 191 192定义ShowActionMenu的选项。 193 194**系统能力:** 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full 195 196| 名称 | 类型 | 必填 | 说明 | 197| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 198| title | string | 否 | 标题文本。 | 199| buttons | [[Button](#button), [Button](#button)?, [Button](#button)?, [Button](#button)?, [Button](#button)?, [Button](#button)?] | 是 | 对话框中按钮的数组,结构为:{text:'button', color: '\#666666'},支持1-6个按钮。 | 200| success | (tapIndex: number, errMsg: string) => void | 否 | 弹出对话框时调用。 | 201| fail | (errMsg: string) => void | 否 | 接口调用失败的回调函数。 | 202| complete | (data: string) => void | 否 | 关闭对话框时调用。 | 203