From 06a17c236d4cb9b8da75fce43af938cb7ea510bf Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期一, 15 十二月 2025 09:50:12 +0800
Subject: [PATCH] feat: 优化企业微信判断,优化gps分断处理

---
 app/App.vue |  157 +++++++++++++++++++++++++---------------------------
 1 files changed, 75 insertions(+), 82 deletions(-)

diff --git a/app/App.vue b/app/App.vue
index 15eb1ac..f45cc42 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -4,6 +4,7 @@
   import { getToken } from '@/utils/auth'
   import { getUnreadCount } from '@/api/message'
   import storage from '@/utils/storage'
+  import { redirectToLoginByEnvironment } from '@/utils/wechat'
 
   export default {
     data() {
@@ -13,6 +14,7 @@
       }
     },
     onLaunch: function(options) {
+      console.log('App onLaunch, options:', options);
       this.lastToken = getToken()
       this.initApp(options)
       
@@ -36,7 +38,11 @@
         this.stopMessagePolling()
         this.lastToken = null
         // 娓呴櫎娑堟伅寰芥爣
-        uni.removeTabBarBadge({ index: 3 })
+        try {
+          uni.removeTabBarBadge({ index: 3 })
+        } catch (e) {
+          console.error('娓呴櫎娑堟伅寰芥爣澶辫触:', e)
+        }
       })
     },
     onShow: function() {
@@ -73,10 +79,14 @@
     methods: {
       // 鍒濆鍖栧簲鐢�
       initApp(options) {
-        // 鍒濆鍖栧簲鐢ㄩ厤缃�
-        this.initConfig()
-        // 妫�鏌ョ敤鎴风櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
-        this.checkLoginAndRedirect(options)
+        try {
+          // 鍒濆鍖栧簲鐢ㄩ厤缃�
+          this.initConfig()
+          // 妫�鏌ョ敤鎴风櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
+          this.checkLoginAndRedirect(options)
+        } catch (e) {
+          console.error('鍒濆鍖栧簲鐢ㄥけ璐�:', e)
+        }
         
         // 娉ㄦ剰锛氫笉鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鑷姩鍚姩杞
         // 鍙湁鍦ㄧ敤鎴蜂富鍔ㄧ櫥褰曟垚鍔熷悗鎵嶅惎鍔紙閫氳繃 user-login 浜嬩欢瑙﹀彂锛�
@@ -86,73 +96,40 @@
       },
       // 妫�鏌ョ櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
       checkLoginAndRedirect(options) {
-        if (!getToken()) {
-          // 妫�鏌ヨ繍琛岀幆澧冨苟璺宠浆鍒板搴旂殑鐧诲綍椤甸潰
-          // #ifdef MP-WEIXIN
-          // 鍦ㄥ井淇″皬绋嬪簭鐜涓�
+        try {
+          if (!getToken()) {
+            console.log('鐢ㄦ埛鏈櫥褰曪紝鍑嗗璺宠浆鍒扮櫥褰曢〉闈�')
+            // 浣跨敤宸ュ叿绫绘牴鎹幆澧冭嚜鍔ㄨ烦杞埌鍚堥�傜殑鐧诲綍椤甸潰
+            redirectToLoginByEnvironment(options, this.$tab);
+          } else {
+            console.log('鐢ㄦ埛宸茬櫥褰曪紝鏃犻渶璺宠浆')
+          }
+        } catch (e) {
+          console.error('妫�鏌ョ櫥褰曠姸鎬佸苟璺宠浆澶辫触:', e)
+          // fallback鍒版櫘閫氱櫥褰曢〉闈�
           try {
-            // 鑾峰彇绯荤粺淇℃伅
-            const systemInfo = uni.getSystemInfoSync()
-            console.log('绯荤粺淇℃伅:', systemInfo)
-            
-            // 妫�鏌nvironment瀛楁鏄惁涓簑xwork
-            if (systemInfo.environment === 'wxwork') {
-              console.log('妫�娴嬪埌浼佷笟寰俊鐜锛岃烦杞埌浼佷笟寰俊鍏嶇櫥椤甸潰')
-              // 鏋勯�犲甫鍙傛暟鐨刄RL
-              let url = '/pages/qylogin'
-              if (options && options.query) {
-                const queryParams = Object.keys(options.query).map(key => `${key}=${encodeURIComponent(options.query[key])}`).join('&')
-                if (queryParams) {
-                  url += '?' + queryParams
-                }
-              }
-              this.$tab.reLaunch(url)
-              return
-            } else {
-              console.log('妫�娴嬪埌鏅�氬井淇$幆澧冿紝璺宠浆鍒板井淇$櫥褰曢〉闈�')
-              // 鏋勯�犲甫鍙傛暟鐨刄RL
-              let url = '/pages/login'
-              if (options && options.query) {
-                const queryParams = Object.keys(options.query).map(key => `${key}=${encodeURIComponent(options.query[key])}`).join('&')
-                if (queryParams) {
-                  url += '?' + queryParams
-                }
-              }
-              this.$tab.reLaunch(url)
-              return
-            }
-          } catch (e) {
-            console.error('鑾峰彇绯荤粺淇℃伅澶辫触:', e)
-            // 榛樿璺宠浆鍒版櫘閫氱櫥褰曢〉闈�
-            this.$tab.reLaunch('/pages/login')
+            this.$tab.reLaunch('/pages/login');
+          } catch (fallbackError) {
+            console.error('fallback璺宠浆涔熷け璐ヤ簡:', fallbackError);
           }
-          // #endif
-          
-          // #ifndef MP-WEIXIN
-          // 闈炲井淇″皬绋嬪簭鐜锛岃烦杞埌鏅�氱櫥褰曢〉闈�
-          console.log('闈炲井淇″皬绋嬪簭鐜锛岃烦杞埌鏅�氱櫥褰曢〉闈�')
-          let url = '/pages/login'
-          if (options && options.query) {
-            const queryParams = Object.keys(options.query).map(key => `${key}=${encodeURIComponent(options.query[key])}`).join('&')
-            if (queryParams) {
-              url += '?' + queryParams
-            }
-          }
-          this.$tab.reLaunch(url)
-          // #endif
         }
       },
       
       // 鍒ゆ柇褰撳墠鏄惁鍦ㄧ櫥褰曢〉闈�
       isLoginPage() {
-        const pages = getCurrentPages()
-        if (pages.length === 0) {
+        try {
+          const pages = getCurrentPages()
+          if (pages.length === 0) {
+            return false
+          }
+          const currentPage = pages[pages.length - 1]
+          const route = currentPage.route || ''
+          // 鍒ゆ柇鏄惁涓虹櫥褰曠浉鍏抽〉闈�
+          return route.includes('login') || route.includes('register')
+        } catch (e) {
+          console.error('鍒ゆ柇鏄惁涓虹櫥褰曢〉闈㈠け璐�:', e)
           return false
         }
-        const currentPage = pages[pages.length - 1]
-        const route = currentPage.route || ''
-        // 鍒ゆ柇鏄惁涓虹櫥褰曠浉鍏抽〉闈�
-        return route.includes('login') || route.includes('register')
       },
       
       // 鏇存柊鏈娑堟伅寰芥爣
@@ -169,15 +146,23 @@
           
           if (count > 0) {
             // 璁剧疆寰芥爣
-            uni.setTabBarBadge({
-              index: 3, // 娑堟伅椤甸潰鍦╰abBar涓殑绱㈠紩浣嶇疆锛�0寮�濮嬶級
-              text: count > 99 ? '99+' : count.toString()
-            })
+            try {
+              uni.setTabBarBadge({
+                index: 3, // 娑堟伅椤甸潰鍦╰abBar涓殑绱㈠紩浣嶇疆锛�0寮�濮嬶級
+                text: count > 99 ? '99+' : count.toString()
+              })
+            } catch (e) {
+              console.error('璁剧疆娑堟伅寰芥爣澶辫触:', e)
+            }
           } else {
             // 绉婚櫎寰芥爣
-            uni.removeTabBarBadge({
-              index: 3
-            })
+            try {
+              uni.removeTabBarBadge({
+                index: 3
+              })
+            } catch (e) {
+              console.error('绉婚櫎娑堟伅寰芥爣澶辫触:', e)
+            }
           }
         }).catch(error => {
           console.error('鑾峰彇鏈娑堟伅鏁伴噺澶辫触:', error)
@@ -186,22 +171,30 @@
       
       // 鍚姩娑堟伅杞
       startMessagePolling() {
-        // 姣�30绉掕疆璇竴娆�
-        this.messagePollingTimer = setInterval(() => {
-          if (getToken()) {
-            this.updateUnreadMessageBadge()
-          } else {
-            // 濡傛灉鐢ㄦ埛宸茬櫥鍑猴紝鍋滄杞
-            this.stopMessagePolling()
-          }
-        }, 30000) // 30绉�
+        try {
+          // 姣�30绉掕疆璇竴娆�
+          this.messagePollingTimer = setInterval(() => {
+            if (getToken()) {
+              this.updateUnreadMessageBadge()
+            } else {
+              // 濡傛灉鐢ㄦ埛宸茬櫥鍑猴紝鍋滄杞
+              this.stopMessagePolling()
+            }
+          }, 30000) // 30绉�
+        } catch (e) {
+          console.error('鍚姩娑堟伅杞澶辫触:', e)
+        }
       },
       
       // 鍋滄娑堟伅杞
       stopMessagePolling() {
-        if (this.messagePollingTimer) {
-          clearInterval(this.messagePollingTimer)
-          this.messagePollingTimer = null
+        try {
+          if (this.messagePollingTimer) {
+            clearInterval(this.messagePollingTimer)
+            this.messagePollingTimer = null
+          }
+        } catch (e) {
+          console.error('鍋滄娑堟伅杞澶辫触:', e)
         }
       },
       

--
Gitblit v1.9.1