From 0707ac5aa2de2fb9e624a760b26ccd59410a1670 Mon Sep 17 00:00:00 2001 From: kukixi Date: Wed, 23 Mar 2022 16:46:29 +0800 Subject: [PATCH] update sample case Signed-off-by: kukixi --- .../js-apis-basic-features-ohos-prompt.md | 174 ++++++++++-------- .../js-apis-basic-features-ohos-router.md | 10 +- 2 files changed, 100 insertions(+), 84 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-prompt.md b/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-prompt.md index c24ae4d65f..b843237d0c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-prompt.md +++ b/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-prompt.md @@ -53,6 +53,7 @@ showToast(options: ShowToastOptions): void showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse> 创建并显示对话框,对话框响应后同步返回结果。 + **系统能力:** SystemCapability.ArkUI.ArkUI.Full **参数:** @@ -69,28 +70,34 @@ showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse> **示例:** ``` - export default { - showDialog() { - prompt.showDialog({ - title: 'Title Info', - message: 'Message Info', - buttons: [ - { - text: 'button', - color: '#666666', - }, - ], - success: function(data) { - console.log('dialog success callback,click button : ' + data.index); - }, - cancel: function() { - console.log('dialog cancel callback'); - }, - }); + export default { + showDialog() { + prompt.showDialog({ + title: 'Title Info', + message: 'Message Info', + buttons: [ + { + text: 'button1', + color: '#000000', + }, + { + text: 'button2', + color: '#000000', + } + ], + }) + .then(data => { + console.info('showDialog success, click button: ' + data.index); + }) + .catch(err => { + console.info('showDialog error: ' + err); + }) } } ``` +## prompt.showDialog + showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void 创建并显示对话框,对话框响应结果异步返回。 @@ -106,24 +113,29 @@ showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSucc **示例:** ``` - export default { - showDialog() { - prompt.showDialog({ - title: 'Title Info', - message: 'Message Info', - buttons: [ - { - text: 'button', - color: '#666666', - }, - ], - success: function(data) { - console.log('dialog success callback,click button : ' + data.index); - }, - cancel: function() { - console.log('dialog cancel callback'); - }, - }); + export default { + callback(err, data) { + if(err) { + console.info('showDialog err: ' + err); + return; + } + console.info('showDialog success callback, click button: ' + data.index); + }, + showDialog() { + prompt.showDialog({ + title: 'showDialog Title Info', + message: 'Message Info', + buttons: [ + { + text: 'button1', + color: '#000000', + }, + { + text: 'button2', + color: '#000000', + } + ] + }, this.callback); } } ``` @@ -153,7 +165,7 @@ showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSucc ## prompt.showActionMenu - showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void +showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void 创建并显示操作菜单,菜单响应结果异步返回。 @@ -168,31 +180,33 @@ showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSucc **示例:** ``` - export default { - showActionMenu() { - prompt.showActionMenu({ - title: 'Title Info', - buttons: [ - { - text: 'item1', - color: '#666666', - }, - { - text: 'item2', - color: '#000000', - }, - ], - success: function(data) { - console.log('dialog success callback,click button : ' + data.tapIndex); - }, - fail: function(data) { - console.log('dialog fail callback' + data.errMsg); - }, - }); + export default { + callback(err, data) { + if(err) { + console.info('showActionMenu err: ' + err); + return; + } + console.info('showActionMenu success callback, click button: ' + data.index); + }, + showActionMenu() { + prompt.showActionMenu({ + title: 'Title Info', + buttons: [ + { + text: 'item1', + color: '#666666', + }, + { + text: 'item2', + color: '#000000', + }, + ] + }, this.callback) } } ``` +## prompt.showActionMenu showActionMenu(options: ActionMenuOptions): Promise @@ -212,27 +226,27 @@ showActionMenu(options: ActionMenuOptions): Promise **示例:** ``` - export default { - showActionMenu() { - prompt.showActionMenu({ - title: 'Title Info', - buttons: [ - { - text: 'item1', - color: '#666666', - }, - { - text: 'item2', - color: '#000000', - }, - ], - success: function(data) { - console.log('dialog success callback,click button : ' + data.tapIndex); - }, - fail: function(data) { - console.log('dialog fail callback' + data.errMsg); - }, - }); + export default { + showActionMenu() { + prompt.showActionMenu({ + title: 'showActionMenu Title Info', + buttons: [ + { + text: 'item1', + color: '#666666', + }, + { + text: 'item2', + color: '#000000', + }, + ] + }) + .then(data => { + console.info('showActionMenu success, click button: ' + data.index); + }) + .catch(err => { + console.info('showActionMenu error: ' + err); + }) } } ``` @@ -245,7 +259,7 @@ showActionMenu(options: ActionMenuOptions): Promise | 名称 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | title | string | 否 | 标题文本。 | -| buttons | Array | 是 | 对话框中按钮的数组,结构为:{text:'button', color: '\#666666'},支持1-6个按钮。大于6个按钮时弹窗不显示。 | +| buttons | Array | 是 | 菜单中菜单项按钮的数组,结构为:{text:'button', color: '\#666666'},支持1-6个按钮。大于6个按钮时弹窗不显示。 | ## ActionMenuSuccessResponse diff --git a/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-router.md b/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-router.md index 5e3c8839d6..a23600c396 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-router.md +++ b/zh-cn/application-dev/reference/apis/js-apis-basic-features-ohos-router.md @@ -1,10 +1,10 @@ # 页面路由 > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> +> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> - 页面路由需要在页面渲染完成之后才能调用,在onInit和onReady生命周期中页面还处于渲染阶段,禁止调用页面路由方法。 -> ![icon-notice.gif](public_sys-resources/icon-notice.gif) **须知:** -> 页面路由需要在页面渲染完成之后才能调用,在onInit和onReady生命周期中页面还处于渲染阶段,禁止调用页面路由方法。 ## 导入模块 ``` @@ -272,11 +272,13 @@ enableAlertBeforeBackPage(options: EnableAlertOptions): void ``` ## EnableAlertOptions +页面返回询问对话框选项。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Lite。 +| 名称 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | message | string | 是 | 询问对话框内容。 | -| 名称 | 类型 | 必填 | 说明 | ## router.disableAlertBeforeBackPage -- GitLab