Renxy 1 жил өмнө
parent
commit
fe637a0bac
3 өөрчлөгдсөн 17 нэмэгдсэн , 29 устгасан
  1. 1 9
      src/app.ts
  2. 0 10
      src/global.js
  3. 16 10
      src/utils/utils.js

+ 1 - 9
src/app.ts

@@ -1,7 +1,7 @@
 // 运行时配置
 
 // import { RequestConfig, history } from '@umijs/max';
-import { getToken, GetTokenFromUrl, UnityAction } from '@/utils/utils';
+import { getToken, GetTokenFromUrl } from '@/utils/utils';
 import { RequestConfig } from '@umijs/max';
 import { message } from 'antd';
 import dayjs from 'dayjs';
@@ -104,12 +104,4 @@ const tokenExpiredHandle = (code: number) => {
 };
 if (window.vuplex) {
   alert('---------app----------');
-  window.vuplex.addEventListener('message', (e) => {
-    console.log(
-      '============================getMessageForUnity============================',
-    );
-    const data = JSON.parse(e.data);
-    console.log(data);
-    UnityAction.emit(data.type, data.message);
-  });
 }

+ 0 - 10
src/global.js

@@ -9,13 +9,3 @@ if (token) {
 if (window.vuplex) {
   alert('---------global---------');
 }
-if (window.vuplex) {
-  window.vuplex.addEventListener('message', (e) => {
-    console.log(
-      '============================getMessageForUnity============================',
-    );
-    const data = JSON.parse(e.data);
-    console.log(data);
-    UnityAction.emit(data.type, data.message);
-  });
-}

+ 16 - 10
src/utils/utils.js

@@ -105,6 +105,10 @@ export function getUser(params) {
 export const UnityAction = {
   event: {},
   on(type, callback) {
+    if (window.vuplex) {
+      alert('----------on----------');
+      addUnityListener();
+    }
     if (!UnityAction.event[type]) {
       UnityAction.event[type] = [];
     }
@@ -147,16 +151,18 @@ export const UnityAction = {
   },
 };
 
-// if (window.vuplex) {
-//   window.vuplex.addEventListener('message', (e) => {
-//     console.log(
-//       '============================getMessageForUnity============================',
-//     );
-//     const data = JSON.parse(e.data);
-//     console.log(data);
-//     UnityAction.emit(data.type, data.message);
-//   });
-// }
+export function addUnityListener() {
+  if (window.vuplex) {
+    window.vuplex.addEventListener('message', (e) => {
+      console.log(
+        '============================getMessageForUnity============================',
+      );
+      const data = JSON.parse(e.data);
+      console.log(data);
+      UnityAction.emit(data.type, data.message);
+    });
+  }
+}
 
 export function getGlobalData(key) {
   let data;