未验证 提交 31888f8b 编写于 作者: O openharmony_ci 提交者: Gitee

!9538 翻译完成:9275 3.1修复文档toast没有说明清楚duration的具体范围

Merge pull request !9538 from wusongqing/TR9275
# Prompt # Prompt
The **Prompt** module provides APIs for creating and showing toasts, dialog boxes, and action menus.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
``` ```js
import prompt from '@ohos.prompt' import prompt from '@ohos.prompt'
``` ```
## Required Permissions
None.
## prompt.showToast ## prompt.showToast
showToast(options: ShowToastOptions): void showToast(options: ShowToastOptions): void
Shows the toast. Shows a toast.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------------- | ---- | ------- | | ------- | ------------------------------------- | ---- | ------- |
| options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.| | options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.|
**Example** **Example**
```
export default { ```js
showToast() { prompt.showToast({
prompt.showToast({
message: 'Message Info', message: 'Message Info',
duration: 2000, duration: 2000,
}); });
} ```
}
```
## ShowToastOptions ## ShowToastOptions
Describes the options for showing the toast. Describes the options for showing the toast.
...@@ -44,10 +42,10 @@ Describes the options for showing the toast. ...@@ -44,10 +42,10 @@ Describes the options for showing the toast.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| message | string | Yes | Text to display. | | message | string| Yes | Text to display. |
| duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The recommended value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used.| | duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used.|
| bottom | <length> | No | Distance between the toast border and the bottom of the screen. | | bottom | string\| number | No | Distance between the toast border and the bottom of the screen. |
## prompt.showDialog ## prompt.showDialog
...@@ -58,6 +56,7 @@ Shows a dialog box. This API uses a promise to return the result synchronously. ...@@ -58,6 +56,7 @@ Shows a dialog box. This API uses a promise to return the result synchronously.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | --------------------------------------- | ---- | ------ | | ------- | --------------------------------------- | ---- | ------ |
| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.| | options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.|
...@@ -70,10 +69,8 @@ Shows a dialog box. This API uses a promise to return the result synchronously. ...@@ -70,10 +69,8 @@ Shows a dialog box. This API uses a promise to return the result synchronously.
**Example** **Example**
``` ```js
export default { prompt.showDialog({
showDialog() {
prompt.showDialog({
title: 'Title Info', title: 'Title Info',
message: 'Message Info', message: 'Message Info',
buttons: [ buttons: [
...@@ -86,44 +83,34 @@ Shows a dialog box. This API uses a promise to return the result synchronously. ...@@ -86,44 +83,34 @@ Shows a dialog box. This API uses a promise to return the result synchronously.
color: '#000000', color: '#000000',
} }
], ],
}) })
.then(data => { .then(data => {
console.info('showDialog success, click button: ' + data.index); console.info('showDialog success, click button: ' + data.index);
}) })
.catch(err => { .catch(err => {
console.info('showDialog error: ' + err); console.info('showDialog error: ' + err);
}) })
} ```
}
```
## prompt.showDialog ## prompt.showDialog
showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void
Shows a dialog box. This API uses a callback to return the result asynchronously. Shows a dialog box. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------ | | -------- | ---------------------------------------- | ---- | ------------ |
| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.| | options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.|
| callback | AsyncCallback<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Yes | Callback used to return the dialog box response result. | | callback | AsyncCallback<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Yes | Callback used to return the dialog box response result. |
**Example** **Example**
```
export default { ```js
callback(err, data) { prompt.showDialog({
if(err) {
console.info('showDialog err: ' + err);
return;
}
console.info('showDialog success callback, click button: ' + data.index);
},
showDialog() {
prompt.showDialog({
title: 'showDialog Title Info', title: 'showDialog Title Info',
message: 'Message Info', message: 'Message Info',
buttons: [ buttons: [
...@@ -136,10 +123,14 @@ Shows a dialog box. This API uses a callback to return the result asynchronously ...@@ -136,10 +123,14 @@ Shows a dialog box. This API uses a callback to return the result asynchronously
color: '#000000', color: '#000000',
} }
] ]
}, this.callback); }, (err, data) => {
} if (err) {
console.info('showDialog err: ' + err);
return;
} }
``` console.info('showDialog success callback, click button: ' + data.index);
});
```
## ShowDialogOptions ## ShowDialogOptions
...@@ -148,10 +139,10 @@ Describes the options for showing the dialog box. ...@@ -148,10 +139,10 @@ Describes the options for showing the dialog box.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ---------------------------------------- | | ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string | No | Title of the text to display. | | title | string| No | Title of the dialog box. |
| message | string | No | Text body. | | message | string| No | Text body. |
| buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. One to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.| | buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.|
## ShowDialogSuccessResponse ## ShowDialogSuccessResponse
...@@ -161,7 +152,7 @@ Describes the dialog box response result. ...@@ -161,7 +152,7 @@ Describes the dialog box response result.
| Name | Type | Description | | Name | Type | Description |
| ----- | ------ | ------------------- | | ----- | ------ | ------------------- |
| index | number | Index of the selected button in the array.| | index | number | Index of the selected button in the **buttons** array.|
## prompt.showActionMenu ## prompt.showActionMenu
...@@ -173,6 +164,7 @@ Shows an action menu. This API uses a callback to return the result asynchronous ...@@ -173,6 +164,7 @@ Shows an action menu. This API uses a callback to return the result asynchronous
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------- | | -------- | ---------------------------------------- | ---- | --------- |
| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. | | options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. |
...@@ -180,17 +172,9 @@ Shows an action menu. This API uses a callback to return the result asynchronous ...@@ -180,17 +172,9 @@ Shows an action menu. This API uses a callback to return the result asynchronous
**Example** **Example**
```
export default { ```js
callback(err, data) { prompt.showActionMenu({
if(err) {
console.info('showActionMenu err: ' + err);
return;
}
console.info('showActionMenu success callback, click button: ' + data.index);
},
showActionMenu() {
prompt.showActionMenu({
title: 'Title Info', title: 'Title Info',
buttons: [ buttons: [
{ {
...@@ -202,34 +186,39 @@ Shows an action menu. This API uses a callback to return the result asynchronous ...@@ -202,34 +186,39 @@ Shows an action menu. This API uses a callback to return the result asynchronous
color: '#000000', color: '#000000',
}, },
] ]
}, this.callback) }, (err, data) => {
} if (err) {
console.info('showActionMenu err: ' + err);
return;
} }
``` console.info('showActionMenu success callback, click button: ' + data.index);
})
```
## prompt.showActionMenu ## prompt.showActionMenu
showActionMenu(options: ActionMenuOptions): Promise\<ActionMenuSuccessResponse> showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
Shows an action menu. This API uses a promise to return the result synchronously. Shows an action menu. This API uses a promise to return the result synchronously.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | --------------------------------------- | ---- | ------- | | ------- | --------------------------------------- | ---- | ------- |
| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options.| | options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------- | ------- | | ---------------------------------------- | ------- |
| Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result.| | Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result.|
**Example** **Example**
```
export default { ```js
showActionMenu() { prompt.showActionMenu({
prompt.showActionMenu({
title: 'showActionMenu Title Info', title: 'showActionMenu Title Info',
buttons: [ buttons: [
{ {
...@@ -241,16 +230,14 @@ Shows an action menu. This API uses a promise to return the result synchronously ...@@ -241,16 +230,14 @@ Shows an action menu. This API uses a promise to return the result synchronously
color: '#000000', color: '#000000',
}, },
] ]
}) })
.then(data => { .then(data => {
console.info('showActionMenu success, click button: ' + data.index); console.info('showActionMenu success, click button: ' + data.index);
}) })
.catch(err => { .catch(err => {
console.info('showActionMenu error: ' + err); console.info('showActionMenu error: ' + err);
}) })
} ```
}
```
## ActionMenuOptions ## ActionMenuOptions
Describes the options for showing the action menu. Describes the options for showing the action menu.
...@@ -258,9 +245,9 @@ Describes the options for showing the action menu. ...@@ -258,9 +245,9 @@ Describes the options for showing the action menu.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ---------------------------------------- | | ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string | No | Title of the text to display. | | title | string| No | Title of the text to display. |
| buttons | Array | Yes | Array of menu items. The array structure is **{text:'button',&nbsp;color:&nbsp;'\#666666'}**. One to six items are supported. If there are more than six items, extra items will not be displayed.| | buttons | Array&lt;[Button](#button)&gt; | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.|
## ActionMenuSuccessResponse ## ActionMenuSuccessResponse
...@@ -270,4 +257,15 @@ Describes the action menu response result. ...@@ -270,4 +257,15 @@ Describes the action menu response result.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ------------------------ | | ----- | ------ | ---- | ------------------------ |
| index | number | No | Index of the selected button in the array, starting from **0**.| | index | number | No | Index of the selected button in the **buttons** array, starting from **0**.|
## Button
Describes the menu item button in the action menu.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| ----- | ---------------------------------------- | ---- | ------- |
| text | string| Yes | Button text.|
| color | string| Yes | Text color of the button.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册