chenquansheng

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

@@ -54,7 +54,6 @@ export class BridgeWebViewControl extends webview.WebviewController { @@ -54,7 +54,6 @@ export class BridgeWebViewControl extends webview.WebviewController {
54 * 刷新消息 54 * 刷新消息
55 */ 55 */
56 flushMessageQueue() { 56 flushMessageQueue() {
57 - hilog.error(0xFF00, TAG, 'flushMessageQueue');  
58 this.loadUrlCustom(BridgeUtil.JS_FETCH_QUEUE_FROM_JAVA, (data: string) => { 57 this.loadUrlCustom(BridgeUtil.JS_FETCH_QUEUE_FROM_JAVA, (data: string) => {
59 let list: Array<Message> = JSON.parse(data) 58 let list: Array<Message> = JSON.parse(data)
60 if (list == null || list.length == 0) { 59 if (list == null || list.length == 0) {
@@ -105,6 +104,53 @@ export class BridgeWebViewControl extends webview.WebviewController { @@ -105,6 +104,53 @@ export class BridgeWebViewControl extends webview.WebviewController {
105 104
106 } 105 }
107 106
  107 + receiveDataFromH5(url: string) {
  108 +
  109 + if (!url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) {
  110 + return
  111 + }
  112 + let functionName: string = url.replace('yy://__QUEUE_MESSAGE__/', '');
  113 + let value:Message = JSON.parse(functionName)
  114 + let responseId: string = value.responseId
  115 + // 是否是response CallBackFunction,收到消息,
  116 + if (StringUtils.isNotEmpty(responseId)) {
  117 + let call: Callback = this.responseCallbacks.get(responseId)
  118 + let responseData: string = value.responseData;
  119 + if (StringUtils.isEmpty(responseData) || call === undefined) {
  120 + return
  121 + }
  122 + call(responseData)
  123 + this.responseCallbacks.remove(responseId)
  124 + } else {
  125 + let responseFunction: Callback;
  126 + let callbackId: string = value.callbackId
  127 + let handlerName: string = value.handlerName
  128 + if (StringUtils.isNotEmpty(callbackId)) {
  129 + responseFunction = (data: string) => {
  130 + let msg: CallBackMessage = new CallBackMessage()
  131 + msg.responseId = callbackId
  132 + msg.responseData = data
  133 + msg.handlerName = handlerName
  134 + this.queueMessage(msg)
  135 + }
  136 + } else {
  137 + responseFunction = (data: string) => {
  138 + //TODO 更换log输出方式
  139 + // Logger.info(TAG, `default response:: ${data}`);
  140 + }
  141 + }
  142 + let handle: BridgeHandler
  143 + if (StringUtils.isNotEmpty(value.handlerName)) {
  144 + handle = this.messageHandlers.get(value.handlerName)
  145 + } else {
  146 + handle = new DefaultBridgeHandler()
  147 + }
  148 + if (handle != undefined && value.data != undefined) {
  149 + handle.handle(value, responseFunction)
  150 + }
  151 + }
  152 + }
  153 +
108 private queueMessage(msg: CallBackMessage) { 154 private queueMessage(msg: CallBackMessage) {
109 // //TODO 155 // //TODO
110 this.dispatchMessage(msg); 156 this.dispatchMessage(msg);
@@ -134,6 +134,7 @@ export struct WdWebComponent { @@ -134,6 +134,7 @@ export struct WdWebComponent {
134 if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) { 134 if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) {
135 Logger.debug(TAG, 'flushMessageQueue'); 135 Logger.debug(TAG, 'flushMessageQueue');
136 this.webviewControl.flushMessageQueue() 136 this.webviewControl.flushMessageQueue()
  137 + // this.webviewControl.receiveDataFromH5(url)
137 return true 138 return true
138 } 139 }
139 if (url.includes(BridgeUtil.BRIDGE_LOADED_MSG)) { 140 if (url.includes(BridgeUtil.BRIDGE_LOADED_MSG)) {
@@ -99,8 +99,9 @@ export struct WdWebLocalComponent { @@ -99,8 +99,9 @@ export struct WdWebLocalComponent {
99 return true 99 return true
100 } 100 }
101 if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) { 101 if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) {
102 - Logger.debug(TAG, 'flushMessageQueue');  
103 - this.webviewControl.flushMessageQueue() 102 + Logger.debug(TAG, 'flushMessageQueue:'+url);
  103 + // this.webviewControl.flushMessageQueue()
  104 + this.webviewControl.receiveDataFromH5(url)
104 return true 105 return true
105 } 106 }
106 return this.onLoadIntercept(event.data.getRequestUrl().toString()); 107 return this.onLoadIntercept(event.data.getRequestUrl().toString());
@@ -147,6 +148,8 @@ export struct WdWebLocalComponent { @@ -147,6 +148,8 @@ export struct WdWebLocalComponent {
147 148
148 //webview 高度设置 149 //webview 高度设置
149 private setCurrentPageOperate8: (data: Message) => void = (data) => { 150 private setCurrentPageOperate8: (data: Message) => void = (data) => {
  151 +
  152 + Logger.debug('setCurrentPageOperate8: ' + data?.data?.webViewHeight)
150 if (data.handlerName === H5CallNativeType.jsCall_currentPageOperate && data?.data?.operateType === '8') { 153 if (data.handlerName === H5CallNativeType.jsCall_currentPageOperate && data?.data?.operateType === '8') {
151 if (typeof this.webHeight === 'number') { 154 if (typeof this.webHeight === 'number') {
152 if (Number(data?.data?.webViewHeight) > this.webHeight) { 155 if (Number(data?.data?.webViewHeight) > this.webHeight) {
@@ -4,29 +4,6 @@ var dpr = window.devicePixelRatio || 1 @@ -4,29 +4,6 @@ var dpr = window.devicePixelRatio || 1
4 var clientHeight = 0 4 var clientHeight = 0
5 var appFontSize = 'normalsize' 5 var appFontSize = 'normalsize'
6 6
7 -/* 判断设备类型 */  
8 -function judgTerminal() {  
9 - /* 返回当前的用户代理(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' */  
10 - const u = navigator.userAgent  
11 - const isXiaomi = u.indexOf('XiaoMi') > -1 // 小米手机  
12 - const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 // 其它安卓  
13 - const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios  
14 - const isHarmony = u.indexOf('ArkWeb') > -1  
15 - if (isAndroid) {  
16 - return 1  
17 - } else if (isIOS) {  
18 - if (isXiaomi) {  
19 - return 1  
20 - } else {  
21 - return 2  
22 - }  
23 - }else if (isHarmony){  
24 - return 2  
25 - }  
26 -  
27 - return 1  
28 -}  
29 -  
30 // adjust body font size 7 // adjust body font size
31 function setBodyFontSize() { 8 function setBodyFontSize() {
32 if (document && document.body) { 9 if (document && document.body) {
@@ -178,6 +178,7 @@ function judgTerminal() { @@ -178,6 +178,7 @@ function judgTerminal() {
178 const isXiaomi = u.indexOf('XiaoMi') > -1 // 小米手机 178 const isXiaomi = u.indexOf('XiaoMi') > -1 // 小米手机
179 const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 // 其它安卓 179 const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 // 其它安卓
180 const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios 180 const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios
  181 + const isHarmony = u.indexOf('ArkWeb') > -1 // 鸿蒙
181 if (isAndroid) { 182 if (isAndroid) {
182 return 1 183 return 1
183 } else if (isIOS) { 184 } else if (isIOS) {
@@ -186,6 +187,8 @@ function judgTerminal() { @@ -186,6 +187,8 @@ function judgTerminal() {
186 } else { 187 } else {
187 return 2 188 return 2
188 } 189 }
  190 + }else if (isHarmony){
  191 + return 2
189 } 192 }
190 193
191 return 1 194 return 1
@@ -70,8 +70,9 @@ @@ -70,8 +70,9 @@
70 message.callbackId = callbackId; 70 message.callbackId = callbackId;
71 } 71 }
72 72
  73 + console.log("WebViewJavascriptBridge55: ", JSON.stringify(message));
73 sendMessageQueue.push(message); 74 sendMessageQueue.push(message);
74 - messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE; 75 + messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE + encodeURIComponent(JSON.stringify(message));
75 } 76 }
76 77
77 // 提供给native调用,该函数作用:获取sendMessageQueue返回给native,由于android不能直接获取返回的内容,所以使用url shouldOverrideUrlLoading 的方式返回内容 78 // 提供给native调用,该函数作用:获取sendMessageQueue返回给native,由于android不能直接获取返回的内容,所以使用url shouldOverrideUrlLoading 的方式返回内容