From 5f2ee03958a1a16dc27195c76ea7cffb422c95d1 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期五, 19 十二月 2025 22:40:34 +0800
Subject: [PATCH] feat: 任务修改接口,删除一些不要的字段同步

---
 app/App.vue |  148 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 107 insertions(+), 41 deletions(-)

diff --git a/app/App.vue b/app/App.vue
index 86cbf17..f74c66c 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() {
@@ -12,9 +13,10 @@
         lastToken: null // 鐢ㄤ簬妫�娴� token 鍙樺寲
       }
     },
-    onLaunch: function() {
+    onLaunch: function(options) {
+      console.log('App onLaunch, options:', options);
       this.lastToken = getToken()
-      this.initApp()
+      this.initApp(options)
       
       // 妫�鏌ュ苟娓呯悊瀛樺偍绌洪棿
       this.checkStorage()
@@ -26,7 +28,7 @@
         if (token) {
           this.lastToken = token
           this.updateUnreadMessageBadge()
-          this.startMessagePolling()
+          // this.startMessagePolling()
         }
       })
       
@@ -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() {
@@ -62,7 +68,7 @@
         this.updateUnreadMessageBadge()
         // 閲嶆柊鍚姩杞锛堝鏋滀箣鍓嶅凡鍋滄锛�
         if (!this.messagePollingTimer) {
-          this.startMessagePolling()
+          // this.startMessagePolling()
         }
       }
     },
@@ -72,13 +78,15 @@
     },
     methods: {
       // 鍒濆鍖栧簲鐢�
-      initApp() {
-        // 鍒濆鍖栧簲鐢ㄩ厤缃�
-        this.initConfig()
-        // 妫�鏌ョ敤鎴风櫥褰曠姸鎬�
-        //#ifdef H5
-        this.checkLogin()
-        //#endif
+      initApp(options) {
+        try {
+          // 鍒濆鍖栧簲鐢ㄩ厤缃�
+          this.initConfig()
+          // 妫�鏌ョ敤鎴风櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
+          this.checkLoginAndRedirect(options)
+        } catch (e) {
+          console.error('鍒濆鍖栧簲鐢ㄥけ璐�:', e)
+        }
         
         // 娉ㄦ剰锛氫笉鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鑷姩鍚姩杞
         // 鍙湁鍦ㄧ敤鎴蜂富鍔ㄧ櫥褰曟垚鍔熷悗鎵嶅惎鍔紙閫氳繃 user-login 浜嬩欢瑙﹀彂锛�
@@ -86,22 +94,64 @@
       initConfig() {
         this.globalData.config = config
       },
-      checkLogin() {
-        if (!getToken()) {
-          this.$tab.reLaunch('/pages/login') 
+      // 妫�鏌ョ櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
+      checkLoginAndRedirect(options) {
+        try {
+          if (!getToken()) {
+            console.log('鐢ㄦ埛鏈櫥褰曪紝鍑嗗璺宠浆鍒扮櫥褰曢〉闈�')
+            // 淇濆瓨鐩爣椤甸潰鐢ㄤ簬鐧诲綍鍚庤烦杞�
+            if (options && options.path && 
+                options.path !== 'pages/login' && 
+                options.path !== 'pages/qylogin') {
+              // 鏋勯�犲畬鏁寸殑璺緞鍜屾煡璇㈠弬鏁�
+              let fullPath = '/' + options.path;
+              if (options.query) {
+                const queryString = Object.keys(options.query).map(key => 
+                  `${key}=${encodeURIComponent(options.query[key])}`).join('&');
+                if (queryString) {
+                  fullPath += '?' + queryString;
+                }
+              }
+              
+              // 淇濆瓨鐩爣URL鍒版湰鍦板瓨鍌�
+              try {
+                uni.setStorageSync('targetUrl', fullPath);
+              } catch (e) {
+                console.error('淇濆瓨鐩爣URL澶辫触:', e);
+              }
+            }
+            
+            // 浣跨敤宸ュ叿绫绘牴鎹幆澧冭嚜鍔ㄨ烦杞埌鍚堥�傜殑鐧诲綍椤甸潰
+            redirectToLoginByEnvironment(options, this.$tab);
+          } else {
+            console.log('鐢ㄦ埛宸茬櫥褰曪紝鏃犻渶璺宠浆')
+          }
+        } catch (e) {
+          console.error('妫�鏌ョ櫥褰曠姸鎬佸苟璺宠浆澶辫触:', e)
+          // fallback鍒版櫘閫氱櫥褰曢〉闈�
+          try {
+            this.$tab.reLaunch('/pages/login');
+          } catch (fallbackError) {
+            console.error('fallback璺宠浆涔熷け璐ヤ簡:', fallbackError);
+          }
         }
       },
       
       // 鍒ゆ柇褰撳墠鏄惁鍦ㄧ櫥褰曢〉闈�
       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')
       },
       
       // 鏇存柊鏈娑堟伅寰芥爣
@@ -118,15 +168,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)
@@ -135,22 +193,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)
         }
       },
       
@@ -187,4 +253,4 @@
 
 <style lang="scss">
   @import '@/static/scss/index.scss'
-</style>
+</style>
\ No newline at end of file

--
Gitblit v1.9.1