chenquansheng

fix |> 图文详情页前端传递数据给原生方法调整

... ... @@ -54,7 +54,6 @@ export class BridgeWebViewControl extends webview.WebviewController {
* 刷新消息
*/
flushMessageQueue() {
hilog.error(0xFF00, TAG, 'flushMessageQueue');
this.loadUrlCustom(BridgeUtil.JS_FETCH_QUEUE_FROM_JAVA, (data: string) => {
let list: Array<Message> = JSON.parse(data)
if (list == null || list.length == 0) {
... ... @@ -105,6 +104,53 @@ export class BridgeWebViewControl extends webview.WebviewController {
}
receiveDataFromH5(url: string) {
if (!url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) {
return
}
let functionName: string = url.replace('yy://__QUEUE_MESSAGE__/', '');
let value:Message = JSON.parse(functionName)
let responseId: string = value.responseId
// 是否是response CallBackFunction,收到消息,
if (StringUtils.isNotEmpty(responseId)) {
let call: Callback = this.responseCallbacks.get(responseId)
let responseData: string = value.responseData;
if (StringUtils.isEmpty(responseData) || call === undefined) {
return
}
call(responseData)
this.responseCallbacks.remove(responseId)
} else {
let responseFunction: Callback;
let callbackId: string = value.callbackId
let handlerName: string = value.handlerName
if (StringUtils.isNotEmpty(callbackId)) {
responseFunction = (data: string) => {
let msg: CallBackMessage = new CallBackMessage()
msg.responseId = callbackId
msg.responseData = data
msg.handlerName = handlerName
this.queueMessage(msg)
}
} else {
responseFunction = (data: string) => {
//TODO 更换log输出方式
// Logger.info(TAG, `default response:: ${data}`);
}
}
let handle: BridgeHandler
if (StringUtils.isNotEmpty(value.handlerName)) {
handle = this.messageHandlers.get(value.handlerName)
} else {
handle = new DefaultBridgeHandler()
}
if (handle != undefined && value.data != undefined) {
handle.handle(value, responseFunction)
}
}
}
private queueMessage(msg: CallBackMessage) {
// //TODO
this.dispatchMessage(msg);
... ...
... ... @@ -134,6 +134,7 @@ export struct WdWebComponent {
if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) {
Logger.debug(TAG, 'flushMessageQueue');
this.webviewControl.flushMessageQueue()
// this.webviewControl.receiveDataFromH5(url)
return true
}
if (url.includes(BridgeUtil.BRIDGE_LOADED_MSG)) {
... ...
... ... @@ -99,8 +99,9 @@ export struct WdWebLocalComponent {
return true
}
if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) {
Logger.debug(TAG, 'flushMessageQueue');
this.webviewControl.flushMessageQueue()
Logger.debug(TAG, 'flushMessageQueue:'+url);
// this.webviewControl.flushMessageQueue()
this.webviewControl.receiveDataFromH5(url)
return true
}
return this.onLoadIntercept(event.data.getRequestUrl().toString());
... ... @@ -147,6 +148,8 @@ export struct WdWebLocalComponent {
//webview 高度设置
private setCurrentPageOperate8: (data: Message) => void = (data) => {
Logger.debug('setCurrentPageOperate8: ' + data?.data?.webViewHeight)
if (data.handlerName === H5CallNativeType.jsCall_currentPageOperate && data?.data?.operateType === '8') {
if (typeof this.webHeight === 'number') {
if (Number(data?.data?.webViewHeight) > this.webHeight) {
... ...
... ... @@ -4,29 +4,6 @@ var dpr = window.devicePixelRatio || 1
var clientHeight = 0
var appFontSize = 'normalsize'
/* 判断设备类型 */
function judgTerminal() {
/* 返回当前的用户代理(User Agent)字符串 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' */
const u = navigator.userAgent
const isXiaomi = u.indexOf('XiaoMi') > -1 // 小米手机
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 // 其它安卓
const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios
const isHarmony = u.indexOf('ArkWeb') > -1
if (isAndroid) {
return 1
} else if (isIOS) {
if (isXiaomi) {
return 1
} else {
return 2
}
}else if (isHarmony){
return 2
}
return 1
}
// adjust body font size
function setBodyFontSize() {
if (document && document.body) {
... ...
... ... @@ -178,6 +178,7 @@ function judgTerminal() {
const isXiaomi = u.indexOf('XiaoMi') > -1 // 小米手机
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 // 其它安卓
const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios
const isHarmony = u.indexOf('ArkWeb') > -1 // 鸿蒙
if (isAndroid) {
return 1
} else if (isIOS) {
... ... @@ -186,6 +187,8 @@ function judgTerminal() {
} else {
return 2
}
}else if (isHarmony){
return 2
}
return 1
... ...
... ... @@ -70,8 +70,9 @@
message.callbackId = callbackId;
}
console.log("WebViewJavascriptBridge55: ", JSON.stringify(message));
sendMessageQueue.push(message);
messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE;
messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE + encodeURIComponent(JSON.stringify(message));
}
// 提供给native调用,该函数作用:获取sendMessageQueue返回给native,由于android不能直接获取返回的内容,所以使用url shouldOverrideUrlLoading 的方式返回内容
... ...