Showing
3 changed files
with
19 additions
and
32 deletions
| @@ -10,7 +10,7 @@ export class H5CallNativeType { | @@ -10,7 +10,7 @@ export class H5CallNativeType { | ||
| 10 | static jsCall_callAppService = 'jsCall_callAppService' | 10 | static jsCall_callAppService = 'jsCall_callAppService' |
| 11 | // TODO 业务自行新增类型、自行在JsBridgeBiz#performJSCallNative里添加接收分支处理。 | 11 | // TODO 业务自行新增类型、自行在JsBridgeBiz#performJSCallNative里添加接收分支处理。 |
| 12 | 12 | ||
| 13 | - static init() { | 13 | + static { |
| 14 | H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_currentPageOperate) | 14 | H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_currentPageOperate) |
| 15 | H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_getAppPublicInfo) | 15 | H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_getAppPublicInfo) |
| 16 | H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_getArticleDetailBussinessData) | 16 | H5CallNativeType.JsCallTypeList.push(H5CallNativeType.jsCall_getArticleDetailBussinessData) |
| @@ -6,6 +6,7 @@ import { BridgeHandler, BridgeUtil, BridgeWebViewControl, Callback } from 'wdJsB | @@ -6,6 +6,7 @@ import { BridgeHandler, BridgeUtil, BridgeWebViewControl, Callback } from 'wdJsB | ||
| 6 | import { performJSCallNative } from './JsBridgeBiz'; | 6 | import { performJSCallNative } from './JsBridgeBiz'; |
| 7 | import { setDefaultNativeWebSettings } from './WebComponentUtil'; | 7 | import { setDefaultNativeWebSettings } from './WebComponentUtil'; |
| 8 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; | 8 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; |
| 9 | +import { H5CallNativeType } from './H5CallNativeType'; | ||
| 9 | 10 | ||
| 10 | const TAG = 'WdWebComponent'; | 11 | const TAG = 'WdWebComponent'; |
| 11 | 12 | ||
| @@ -80,16 +81,11 @@ export struct WdWebComponent { | @@ -80,16 +81,11 @@ export struct WdWebComponent { | ||
| 80 | this.onPageEnd(event?.url) | 81 | this.onPageEnd(event?.url) |
| 81 | }) | 82 | }) |
| 82 | .onPageBegin((event) => { | 83 | .onPageBegin((event) => { |
| 83 | - // setDefaultNativeWebSettings(this.webviewControl, this.webUrl).then(()=>{ | ||
| 84 | - // this.handleInfo && this.handleInfo.length > 1 ? this.handleInfo.forEach(value => { | ||
| 85 | - // this.webviewControl.registerHandler(value[0], value[1]) | ||
| 86 | - // }) : this.defaultRegisterHandler() | ||
| 87 | - // setTimeout(()=>{ | ||
| 88 | - // BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl) | ||
| 89 | - // },500) | ||
| 90 | - // }) | ||
| 91 | - // this.onPageBegin(event?.url) | ||
| 92 | - // 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') | 84 | + this.onPageBegin(event?.url); |
| 85 | + this.registerHandlers(); | ||
| 86 | + setTimeout(() => { | ||
| 87 | + BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl) | ||
| 88 | + }, 200) | ||
| 93 | }) | 89 | }) |
| 94 | .onLoadIntercept((event) => { | 90 | .onLoadIntercept((event) => { |
| 95 | let url: string = event.data.getRequestUrl().toString() | 91 | let url: string = event.data.getRequestUrl().toString() |
| @@ -115,5 +111,16 @@ export struct WdWebComponent { | @@ -115,5 +111,16 @@ export struct WdWebComponent { | ||
| 115 | this.webviewControl.refresh() | 111 | this.webviewControl.refresh() |
| 116 | } | 112 | } |
| 117 | } | 113 | } |
| 114 | + | ||
| 115 | + private registerHandlers(): void { | ||
| 116 | + // 注册h5调用js相关 | ||
| 117 | + for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) { | ||
| 118 | + let handleName = H5CallNativeType.JsCallTypeList[i]; | ||
| 119 | + let handle = (data: Message, f: Callback) => { | ||
| 120 | + this.defaultPerformJSCallNative(data, f) | ||
| 121 | + } ; | ||
| 122 | + this.webviewControl.registerHandler(handleName, { handle: handle }); | ||
| 123 | + } | ||
| 124 | + } | ||
| 118 | } | 125 | } |
| 119 | 126 |
| @@ -39,17 +39,6 @@ export struct WdWebLocalComponent { | @@ -39,17 +39,6 @@ export struct WdWebLocalComponent { | ||
| 39 | // .onlineImageAccess(true) | 39 | // .onlineImageAccess(true) |
| 40 | // .fileAccess(true) | 40 | // .fileAccess(true) |
| 41 | .onPageBegin((event) => { | 41 | .onPageBegin((event) => { |
| 42 | - | ||
| 43 | - // setDefaultNativeWebSettings(this.webviewControl, this.webResource).then(()=>{ | ||
| 44 | - // this.handleInfo && this.handleInfo.length > 1 ? this.handleInfo.forEach(value => { | ||
| 45 | - // this.webviewControl.registerHandler(value[0], value[1]) | ||
| 46 | - // }) : this.defaultRegisterHandler() | ||
| 47 | - // setTimeout(()=>{ | ||
| 48 | - // BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl) | ||
| 49 | - // },500) | ||
| 50 | - // }) | ||
| 51 | - // this.onPageBegin(event?.url) | ||
| 52 | - // BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl); | ||
| 53 | this.onPageBegin(event?.url); | 42 | this.onPageBegin(event?.url); |
| 54 | this.registerHandlers(); | 43 | this.registerHandlers(); |
| 55 | setTimeout(() => { | 44 | setTimeout(() => { |
| @@ -79,8 +68,6 @@ export struct WdWebLocalComponent { | @@ -79,8 +68,6 @@ export struct WdWebLocalComponent { | ||
| 79 | } | 68 | } |
| 80 | 69 | ||
| 81 | private registerHandlers(): void { | 70 | private registerHandlers(): void { |
| 82 | - // TODO 待优化 | ||
| 83 | - H5CallNativeType.init(); | ||
| 84 | // 注册h5调用js相关 | 71 | // 注册h5调用js相关 |
| 85 | for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) { | 72 | for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) { |
| 86 | let handleName = H5CallNativeType.JsCallTypeList[i]; | 73 | let handleName = H5CallNativeType.JsCallTypeList[i]; |
| @@ -89,13 +76,6 @@ export struct WdWebLocalComponent { | @@ -89,13 +76,6 @@ export struct WdWebLocalComponent { | ||
| 89 | } ; | 76 | } ; |
| 90 | this.webviewControl.registerHandler(handleName, { handle: handle }); | 77 | this.webviewControl.registerHandler(handleName, { handle: handle }); |
| 91 | } | 78 | } |
| 92 | - // // TODO test | ||
| 93 | - // this.webviewControl.registerHandler('changeNativeMessage', { | ||
| 94 | - // handle: (data: Message, f: Callback) => { | ||
| 95 | - // this.defaultPerformJSCallNative(data, f) | ||
| 96 | - // } | ||
| 97 | - // }); | ||
| 98 | - | ||
| 99 | } | 79 | } |
| 100 | 80 | ||
| 101 | /** | 81 | /** |
| @@ -111,7 +91,7 @@ export struct WdWebLocalComponent { | @@ -111,7 +91,7 @@ export struct WdWebLocalComponent { | ||
| 111 | Logger.debug(TAG, 'onPageEnd'); | 91 | Logger.debug(TAG, 'onPageEnd'); |
| 112 | } | 92 | } |
| 113 | onLoadIntercept: (url?: string) => boolean = () => { | 93 | onLoadIntercept: (url?: string) => boolean = () => { |
| 114 | - Logger.debug(TAG, 'onPageBegin return false'); | 94 | + Logger.debug(TAG, 'onLoadIntercept return false'); |
| 115 | return false | 95 | return false |
| 116 | } | 96 | } |
| 117 | } | 97 | } |
-
Please register or login to post a comment