Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
zhangbo1_wd
2024-04-15 16:02:46 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ad6393a19c0a1d111f70e1afe2c2694e367e39ac
ad6393a1
1 parent
0d448fa9
在线web jsbridge相关注册
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
32 deletions
sight_harmony/commons/wdWebComponent/src/main/ets/pages/H5CallNativeType.ets
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebComponent.ets
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebLocalComponent.ets
sight_harmony/commons/wdWebComponent/src/main/ets/pages/H5CallNativeType.ets
View file @
ad6393a
...
...
@@ -10,7 +10,7 @@ export class H5CallNativeType {
static jsCall_callAppService = 'jsCall_callAppService'
// TODO 业务自行新增类型、自行在JsBridgeBiz#performJSCallNative里添加接收分支处理。
static
init()
{
static {
H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_currentPageOperate)
H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_getAppPublicInfo)
H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_getArticleDetailBussinessData)
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebComponent.ets
View file @
ad6393a
...
...
@@ -6,6 +6,7 @@ import { BridgeHandler, BridgeUtil, BridgeWebViewControl, Callback } from 'wdJsB
import { performJSCallNative } from './JsBridgeBiz';
import { setDefaultNativeWebSettings } from './WebComponentUtil';
import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
import { H5CallNativeType } from './H5CallNativeType';
const TAG = 'WdWebComponent';
...
...
@@ -80,16 +81,11 @@ export struct WdWebComponent {
this.onPageEnd(event?.url)
})
.onPageBegin((event) => {
// setDefaultNativeWebSettings(this.webviewControl, this.webUrl).then(()=>{
// this.handleInfo && this.handleInfo.length > 1 ? this.handleInfo.forEach(value => {
// this.webviewControl.registerHandler(value[0], value[1])
// }) : this.defaultRegisterHandler()
// setTimeout(()=>{
// BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl)
// },500)
// })
// this.onPageBegin(event?.url)
// this.webviewControl?.setCustomUserAgent('Mozilla/5.0 (Linux; Android 12; HarmonyOS; OXF-AN00; HMSCore 6.13.0.302) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.88 HuaweiBrowser/14.0.6.300 Mobile Safari/537.36')
this.onPageBegin(event?.url);
this.registerHandlers();
setTimeout(() => {
BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl)
}, 200)
})
.onLoadIntercept((event) => {
let url: string = event.data.getRequestUrl().toString()
...
...
@@ -115,5 +111,16 @@ export struct WdWebComponent {
this.webviewControl.refresh()
}
}
private registerHandlers(): void {
// 注册h5调用js相关
for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) {
let handleName = H5CallNativeType.JsCallTypeList[i];
let handle = (data: Message, f: Callback) => {
this.defaultPerformJSCallNative(data, f)
} ;
this.webviewControl.registerHandler(handleName, { handle: handle });
}
}
}
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebLocalComponent.ets
View file @
ad6393a
...
...
@@ -39,17 +39,6 @@ export struct WdWebLocalComponent {
// .onlineImageAccess(true)
// .fileAccess(true)
.onPageBegin((event) => {
// setDefaultNativeWebSettings(this.webviewControl, this.webResource).then(()=>{
// this.handleInfo && this.handleInfo.length > 1 ? this.handleInfo.forEach(value => {
// this.webviewControl.registerHandler(value[0], value[1])
// }) : this.defaultRegisterHandler()
// setTimeout(()=>{
// BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl)
// },500)
// })
// this.onPageBegin(event?.url)
// BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl);
this.onPageBegin(event?.url);
this.registerHandlers();
setTimeout(() => {
...
...
@@ -79,8 +68,6 @@ export struct WdWebLocalComponent {
}
private registerHandlers(): void {
// TODO 待优化
H5CallNativeType.init();
// 注册h5调用js相关
for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) {
let handleName = H5CallNativeType.JsCallTypeList[i];
...
...
@@ -89,13 +76,6 @@ export struct WdWebLocalComponent {
} ;
this.webviewControl.registerHandler(handleName, { handle: handle });
}
// // TODO test
// this.webviewControl.registerHandler('changeNativeMessage', {
// handle: (data: Message, f: Callback) => {
// this.defaultPerformJSCallNative(data, f)
// }
// });
}
/**
...
...
@@ -111,7 +91,7 @@ export struct WdWebLocalComponent {
Logger.debug(TAG, 'onPageEnd');
}
onLoadIntercept: (url?: string) => boolean = () => {
Logger.debug(TAG, 'on
PageBegin
return false');
Logger.debug(TAG, 'on
LoadIntercept
return false');
return false
}
}
...
...
Please
register
or
login
to post a comment