|
@@ -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)
|