From 98745b859baf8ac591db705eb004206042147ac1 Mon Sep 17 00:00:00 2001
From: xingyy <373639591@qq.com>
Date: Tue, 20 Aug 2024 17:00:06 +0800
Subject: [PATCH] 1123

---
 pages/index/index.vue                      | 46 +++++++----------
 unpackage/dist/dev/app-plus/app-service.js | 58 +++++++++-------------
 utils/communication.js                     | 14 ++----
 3 files changed, 46 insertions(+), 72 deletions(-)

diff --git a/pages/index/index.vue b/pages/index/index.vue
index ba87e9d..0b23328 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -8,44 +8,34 @@ import {onExit } from "@dcloudio/uni-app";
  import { Communication } from '../../utils/communication.js';
 const commun=new Communication()
  const  permissionListener = uni.createRequestPermissionListener();
-permissionListener.onRequest((e)=>{
-  console.log('APP执行onRequest',e)
-  commun.sendToH5('permission-application',e);
-})
-permissionListener.onConfirm((e) => {
-});
-permissionListener.onComplete((e) => {
-	  console.log('APP执行onComplete',e)
-  const arr=['android.permission.ACCESS_COARSE_LOCATION','android.permission.ACCESS_FINE_LOCATION','android.permission.ACCESS_LOCATION_EXTRA_COMMANDS','android.permission.ACCESS_MOCK_LOCATION']
-  commun.sendToH5('permission-complete',e);
-
-})
 onExit(()=>{
    permissionListener.stop()
 })
  function initializeWebView() {
    const currentWebview = getCurrentPages().pop().$getAppWebview()
-   console.log('当前view',currentWebview)
    commun.setWebView(currentWebview.children()[0])
  }
-
  commun.registerHandler('load-complete',()=>{
+   initializeWebView()
+   const {statusBarHeight} = uni.getSystemInfoSync()
+   commun.webViewObj.setStyle({
+     top: statusBarHeight,
+     bottom: 0,
+   })
+   permissionListener.onRequest((e)=>{
+     commun.sendToH5('permission-application',e);
+   })
+   permissionListener.onConfirm((e) => {
+   });
+   permissionListener.onComplete((e) => {
+     console.log('APP执行onComplete',e)
+     const arr=['android.permission.ACCESS_COARSE_LOCATION','android.permission.ACCESS_FINE_LOCATION','android.permission.ACCESS_LOCATION_EXTRA_COMMANDS','android.permission.ACCESS_MOCK_LOCATION']
+     commun.sendToH5('permission-complete',e);
+   })
  })
  const webLoad = (e) => {
-   try {
-     const message = e.detail.data?.[0] || '';
-      if (message.action==='load-complete'){
-        initializeWebView()
-        const {statusBarHeight} = uni.getSystemInfoSync()
-        commun.webViewObj.setStyle({
-          top: statusBarHeight,
-          bottom: 0,
-        })
-      }else {
-        commun.handleMessage(message);
-      }
-   } catch (error) {
-   }
+   const message = e.detail.data?.[0] || '';
+   commun.handleMessage(message);
  };
 </script>
 
diff --git a/unpackage/dist/dev/app-plus/app-service.js b/unpackage/dist/dev/app-plus/app-service.js
index 6a78f18..eacdde6 100644
--- a/unpackage/dist/dev/app-plus/app-service.js
+++ b/unpackage/dist/dev/app-plus/app-service.js
@@ -87,15 +87,11 @@ if (uni.restoreGlobal) {
       this.messageHandlers[action] = handler;
     }
     handleMessage(message) {
-      try {
-        const { action, data } = JSON.parse(message);
-        if (this.messageHandlers[action]) {
-          this.messageHandlers[action](data);
-        } else {
-          formatAppLog("warn", "at utils/communication.js:31", "Unknown action:", action);
-        }
-      } catch (error2) {
-        formatAppLog("error", "at utils/communication.js:34", "Failed to handle message:", error2);
+      const { action, data = {} } = message;
+      if (this.messageHandlers[action]) {
+        this.messageHandlers[action](data);
+      } else {
+        formatAppLog("warn", "at utils/communication.js:30", "Unknown action:", action);
       }
     }
   }
@@ -111,42 +107,34 @@ if (uni.restoreGlobal) {
     setup(__props) {
       const commun = new Communication();
       const permissionListener = uni.createRequestPermissionListener();
-      permissionListener.onRequest((e2) => {
-        formatAppLog("log", "at pages/index/index.vue:12", "APP执行onRequest", e2);
-        commun.sendToH5("permission-application", e2);
-      });
-      permissionListener.onConfirm((e2) => {
-      });
-      permissionListener.onComplete((e2) => {
-        formatAppLog("log", "at pages/index/index.vue:18", "APP执行onComplete", e2);
-        commun.sendToH5("permission-complete", e2);
-      });
       onExit(() => {
         permissionListener.stop();
       });
       function initializeWebView() {
         const currentWebview = getCurrentPages().pop().$getAppWebview();
-        formatAppLog("log", "at pages/index/index.vue:28", "当前view", currentWebview);
         commun.setWebView(currentWebview.children()[0]);
       }
       commun.registerHandler("load-complete", () => {
+        initializeWebView();
+        const { statusBarHeight } = uni.getSystemInfoSync();
+        commun.webViewObj.setStyle({
+          top: statusBarHeight,
+          bottom: 0
+        });
+        permissionListener.onRequest((e2) => {
+          commun.sendToH5("permission-application", e2);
+        });
+        permissionListener.onConfirm((e2) => {
+        });
+        permissionListener.onComplete((e2) => {
+          formatAppLog("log", "at pages/index/index.vue:31", "APP执行onComplete", e2);
+          commun.sendToH5("permission-complete", e2);
+        });
       });
       const webLoad = (e2) => {
         var _a;
-        try {
-          const message = ((_a = e2.detail.data) == null ? void 0 : _a[0]) || "";
-          if (message.action === "load-complete") {
-            initializeWebView();
-            const { statusBarHeight } = uni.getSystemInfoSync();
-            commun.webViewObj.setStyle({
-              top: statusBarHeight,
-              bottom: 0
-            });
-          } else {
-            commun.handleMessage(message);
-          }
-        } catch (error2) {
-        }
+        const message = ((_a = e2.detail.data) == null ? void 0 : _a[0]) || "";
+        commun.handleMessage(message);
       };
       return (_ctx, _cache) => {
         return vue.openBlock(), vue.createElementBlock("web-view", {
@@ -3206,7 +3194,7 @@ if (uni.restoreGlobal) {
   function I(e2) {
     return e2 && "string" == typeof e2 ? JSON.parse(e2) : e2;
   }
-  const S = true, b = "app", A = I(define_process_env_UNI_SECURE_NETWORK_CONFIG_default), C = b, P = I('{\n    "address": [\n        "127.0.0.1",\n        "192.168.56.1",\n        "192.168.88.56"\n    ],\n    "debugPort": 9001,\n    "initialLaunchType": "local",\n    "servePort": 7001,\n    "skipFiles": [\n        "<node_internals>/**",\n        "C:/Users/37363/Downloads/HBuilderX.4.08.2024040127/HBuilderX/plugins/unicloud/**/*.js"\n    ]\n}\n'), T = I('[{"provider":"alipay","spaceName":"oaapp","spaceId":"env-00jxgxphla18","spaceAppId":"2021004145628977","accessKey":"ZALus7EgJXdovISb","secretKey":"7qzvVrPN0mAxfcLr"}]') || [];
+  const S = true, b = "app", A = I(define_process_env_UNI_SECURE_NETWORK_CONFIG_default), C = b, P = I('{\n    "address": [\n        "127.0.0.1",\n        "192.168.56.1",\n        "192.168.88.56"\n    ],\n    "debugPort": 9000,\n    "initialLaunchType": "local",\n    "servePort": 7000,\n    "skipFiles": [\n        "<node_internals>/**",\n        "C:/Users/37363/Downloads/HBuilderX.4.08.2024040127/HBuilderX/plugins/unicloud/**/*.js"\n    ]\n}\n'), T = I('[{"provider":"alipay","spaceName":"oaapp","spaceId":"env-00jxgxphla18","spaceAppId":"2021004145628977","accessKey":"ZALus7EgJXdovISb","secretKey":"7qzvVrPN0mAxfcLr"}]') || [];
   let O = "";
   try {
     O = "__UNI__4796942";
diff --git a/utils/communication.js b/utils/communication.js
index d070748..9b79bed 100644
--- a/utils/communication.js
+++ b/utils/communication.js
@@ -23,15 +23,11 @@ export class Communication {
         this.messageHandlers[action] = handler;
     }
     handleMessage(message) {
-        try {
-            const { action, data } = JSON.parse(message);
-            if (this.messageHandlers[action]) {
-                this.messageHandlers[action](data);
-            } else {
-                console.warn('Unknown action:', action);
-            }
-        } catch (error) {
-            console.error('Failed to handle message:', error);
+        const { action, data = {} } = message
+        if (this.messageHandlers[action]) {
+            this.messageHandlers[action](data);
+        } else {
+            console.warn('Unknown action:', action);
         }
     }
 }