nieyuge 2 years ago
parent
commit
0e5bb81e18
1 changed files with 12 additions and 5 deletions
  1. 12 5
      src/uilts/messageCenter/index.js

+ 12 - 5
src/uilts/messageCenter/index.js

@@ -1,4 +1,4 @@
-import { guid } from '@/uilts/help'
+import { guid, isInApp } from '@/uilts/help'
 //  iframe 通信中心
 class IframeMessageCenter {
     constructor() {
@@ -13,10 +13,17 @@ class IframeMessageCenter {
         if (callback) {
             info.messageId = `${info.actionType}-${guid()}` // 唯一的ID,用于标记回调函数
         }
-        window.parent.postMessage({
-            info,
-            data: JSON.parse(JSON.stringify(data))
-        }, '*');
+        if (isInApp) {
+            window.ReactNativeWebView.postMessage(JSON.stringify({
+                info,
+                data
+            }))
+        } else {
+            window.parent.postMessage({
+                info,
+                data: JSON.parse(JSON.stringify(data))
+            }, '*');
+        }
         if (callback) {
             // 带回调callback 的message, 要求携带messageId,callback,failback等
             this.listen(info.messageId, callback)