From a1d2de88baba795d7784d84ad9f9f6c6ad16b102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Tue, 11 Mar 2025 09:53:41 +0800 Subject: [PATCH] =?UTF-8?q?docs(basic):=20=E8=A1=A5=E5=85=85=20README=20?= =?UTF-8?q?=E4=B8=AD=20JS=20=E4=BA=A4=E4=BA=92=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81-=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=AE=9A=E4=B9=89=20JS?= =?UTF-8?q?=20SDK=20=E5=90=8D=E7=A7=B0=E5=92=8C=E6=96=B9=E6=B3=95=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81-=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=20JSSdkClsManager=20=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E4=BE=9B=20HTML=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=20-=20=E6=9B=B4=E6=96=B0=E4=BA=86?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E5=AE=9A=E4=B9=89=E5=92=8C=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8F=91=E9=80=81=E7=9A=84=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=20-=20=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E5=90=91=20web=20=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E5=92=8C?= =?UTF-8?q?=20html=20=E8=B0=83=E7=94=A8=E5=8E=9F=E7=94=9F=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5f177fb..b1f4ebe 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,18 @@ XWebHelper.openWeb({ > > [详见官方文档](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V1/web-in-app-frontend-page-function-invoking-0000001630265293-V1) +```tsx +// 定义`js`指定名称 +export const JSSdkName = 'HarmonyOSWebView' +// 允许调用的方法列表 +export const JSSdkMethodList = ['showToast'] +export class JSSdkClsManager { + // 供`HTML`调用的方法 + showToast(msg: string): void { + ToolsHelper.log('showToast', msg) + } +} +``` ```tsx // 定义控制器 xc: XWebJsController = {} as XWebJsController @@ -169,14 +181,17 @@ xc: XWebJsController = {} as XWebJsController XWebHelper.openWeb({ url: 'https://www.baidu.com', jsParams: { - obj: new testClass(), + obj: new JSSdkClsManager(), name: JSSdkName, methodList: JSSdkMethodList, controller: this.xc, } }) -//原生像web发送消息 -this.xc.sendMessage('htmlTest()') +// 交互消息的收发,见官方文档 +// 原生向web发送消息 +this.xc.sendMessage('发送给html的内容') +// html调用原生方法 +window.HarmonyOSWebView.showToast('hello word!') ``` ### 1.7.[PickerDateTimeHelper](./src/main/ets/utils/PickerDateTimeHelper.ets)