Просмотр исходного кода

fix(frontend): login redirectTo + goMoreActivities/Products URLs with type filters

User 2 месяцев назад
Родитель
Сommit
004c8d7a00

+ 4 - 3
cfc-frontend/pages/action/index.vue

@@ -63,11 +63,12 @@
     <DimensionProducts
       dimensionCode="action"
       :products="dimensionProducts"
+      :isLoggedIn="isLoggedIn"
       @productClick="goProductDetail"
       @moreProducts="goMoreProducts" />
 
     <!-- 推荐阅读 -->
-    <view class="section" v-if="sectionVisible('recommended_reading') && actionArticles.length > 0">
+    <view class="section" v-if="actionArticles.length > 0">
       <view class="section-header">
         <text class="section-title">推荐阅读</text>
       </view>
@@ -270,7 +271,7 @@ export default {
     var self = this
     setTimeout(function() {
       self.showTabTransition = false
-    }, 1500)
+    }, 1800)
 
     var token = uni.getStorageSync('token')
     this.isLoggedIn = !!token
@@ -455,7 +456,7 @@ export default {
       uni.navigateTo({ url: '/pages/discover-detail/activity-detail/activity-detail?id=' + act.id })
     },
     goMoreActivities: function() {
-      uni.navigateTo({ url: '/pages/discover/index' })
+      uni.navigateTo({ url: '/pages/discover/index?type=activity' })
     },
     goProductDetail: function(prod) {
       uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + prod.id })

+ 2 - 2
cfc-frontend/pages/body/index.vue

@@ -315,7 +315,7 @@ export default {
     var self = this
     setTimeout(function() {
       self.showTabTransition = false
-    }, 1500)
+    }, 1800)
 
     var token = uni.getStorageSync('token')
     this.isLoggedIn = !!token
@@ -517,7 +517,7 @@ export default {
       uni.navigateTo({ url: '/pages/discover-detail/activity-detail/activity-detail?id=' + act.id })
     },
     goMoreActivities: function() {
-      uni.navigateTo({ url: '/pages/discover/index?type=activity&dimension=body' })
+      uni.navigateTo({ url: '/pages/discover/index?type=activity' })
     },
     goProductDetail: function(prod) {
       uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + prod.id })

+ 56 - 75
cfc-frontend/pages/login/login.vue

@@ -103,82 +103,62 @@ export default {
       this.loading = true
       var self = this
 
-      uni.login({
-        provider: 'weixin',
-        success: function(loginRes) {
-          wechatLogin(loginRes.code, {
-            nickname: self.nickname || '用户',
-            avatar: self.avatar || ''
-          }).then(function(res) {
-            // 保存 token 和用户信息
-            uni.setStorageSync('token', res.data.token)
-            uni.setStorageSync('userId', res.data.userId)
-            uni.setStorageSync('role', res.data.role)
-            uni.setStorageSync('familyId', res.data.familyId)
-            uni.setStorageSync('currentRole', res.data.role)
-            uni.setStorageSync('isSwitchedChild', false)
-            uni.setStorageSync('isSwitchedTeacher', false)
-            // 保存 openid,用于后续自动登录
-            if (res.data.openid) {
-              uni.setStorageSync('openid', res.data.openid)
-            }
-            uni.setStorageSync('userInfo', {
-              nickname: res.data.nickname,
-              userId: res.data.userId
-            })
-
-            // 存储成长规划师审核状态
-            if (res.data.teacherStatus) {
-              uni.setStorageSync('teacherStatus', res.data.teacherStatus)
-            }
-            if (res.data.teacherRejectReason) {
-              uni.setStorageSync('teacherRejectReason', res.data.teacherRejectReason)
-            }
-
-            // 保存 token 和用户信息(同步写入,立即持久化)
-            uni.setStorageSync('token', res.data.token)
-            uni.setStorageSync('userId', res.data.userId)
-            uni.setStorageSync('role', res.data.role)
-            uni.setStorageSync('familyId', res.data.familyId)
-            uni.setStorageSync('currentRole', res.data.role)
-            uni.setStorageSync('isSwitchedChild', false)
-            uni.setStorageSync('isSwitchedTeacher', false)
-            // 保存 openid,用于后续自动登录
-            if (res.data.openid) {
-              uni.setStorageSync('openid', res.data.openid)
-            }
-            uni.setStorageSync('userInfo', {
-              nickname: res.data.nickname,
-              userId: res.data.userId
-            })
-
-            // 存储成长规划师审核状态
-            if (res.data.teacherStatus) {
-              uni.setStorageSync('teacherStatus', res.data.teacherStatus)
-            }
-            if (res.data.teacherRejectReason) {
-              uni.setStorageSync('teacherRejectReason', res.data.teacherRejectReason)
-            }
-
-            uni.showToast({ title: '登录成功', icon: 'success' })
+      // 超时保护:10秒强制结束登录流程,避免 uni.login 挂死时按钮 loading 卡死
+      var loginTimeout = new Promise(function(_, reject) {
+        setTimeout(function() {
+          reject(new Error('微信登录超时'))
+        }, 10000)
+      })
 
-            // 立即跳转到对应页面(不等 setTimeout,直接在 Promise 链内)
-            if (res.data.needsRoleSelect) {
-              uni.redirectTo({
-                url: '/pages/user-edit/user-edit?token=' + res.data.token + '&userId=' + res.data.userId + '&needsRoleSelect=true'
-              })
-            } else {
-              self.handlePostLoginRouting()
-            }
-          }).catch(function(e) {
-            uni.showToast({ title: e.message || '登录失败', icon: 'none' })
-            self.loading = false
+      Promise.race([loginTimeout, new Promise(function(resolve, reject) {
+        uni.login({
+          provider: 'weixin',
+          success: function(loginRes) { resolve(loginRes) },
+          fail: function() { reject(new Error('微信登录失败')) }
+        })
+      })]).then(function(loginRes) {
+        wechatLogin(loginRes.code, {
+          nickname: self.nickname || '用户',
+          avatar: self.avatar || ''
+        }).then(function(res) {
+          // 保存 token 和用户信息(只写一次)
+          uni.setStorageSync('token', res.data.token)
+          uni.setStorageSync('userId', res.data.userId)
+          uni.setStorageSync('role', res.data.role)
+          uni.setStorageSync('familyId', res.data.familyId)
+          uni.setStorageSync('currentRole', res.data.role)
+          uni.setStorageSync('isSwitchedChild', false)
+          uni.setStorageSync('isSwitchedTeacher', false)
+          if (res.data.openid) {
+            uni.setStorageSync('openid', res.data.openid)
+          }
+          uni.setStorageSync('userInfo', {
+            nickname: res.data.nickname,
+            userId: res.data.userId
           })
-        },
-        fail: function() {
-          uni.showToast({ title: '微信登录失败', icon: 'none' })
+          if (res.data.teacherStatus) {
+            uni.setStorageSync('teacherStatus', res.data.teacherStatus)
+          }
+          if (res.data.teacherRejectReason) {
+            uni.setStorageSync('teacherRejectReason', res.data.teacherRejectReason)
+          }
+
+          uni.showToast({ title: '登录成功', icon: 'success' })
+
+          if (res.data.needsRoleSelect) {
+            uni.redirectTo({
+              url: '/pages/user-edit/user-edit?token=' + res.data.token + '&userId=' + res.data.userId + '&needsRoleSelect=true'
+            })
+          } else {
+            self.handlePostLoginRouting()
+          }
+        }).catch(function(e) {
+          uni.showToast({ title: e.message || '登录失败', icon: 'none' })
           self.loading = false
-        }
+        })
+      }).catch(function(e) {
+        uni.showToast({ title: e.message || '微信登录失败', icon: 'none' })
+        self.loading = false
       })
     },
     handlePostLoginRouting() {
@@ -250,9 +230,10 @@ export default {
       if (this.redirectUrl) {
         const redirect = this.redirectUrl
         this.redirectUrl = ''
-        uni.reLaunch({ url: redirect })
+        // 使用 redirectTo 支持非 tabBar 页面,避免 switchTab 无法跳转到 discover 等非 tabBar 页
+        uni.redirectTo({ url: redirect })
       } else {
-        uni.reLaunch({ url: '/pages/index/index' })
+        uni.switchTab({ url: '/pages/index/index' })
       }
     }
   }

+ 1 - 1
cfc-frontend/pages/mind/index.vue

@@ -461,7 +461,7 @@ export default {
     var self = this
     setTimeout(function() {
       self.showTabTransition = false
-    }, 1500)
+    }, 1800)
 
     var token = uni.getStorageSync('token')
     this.isLoggedIn = !!token

+ 1 - 1
cfc-frontend/pages/wisdom/index.vue

@@ -243,7 +243,7 @@ export default {
     var self = this
     setTimeout(function() {
       self.showTabTransition = false
-    }, 1500)
+    }, 1800)
 
     var token = uni.getStorageSync('token')
     this.isLoggedIn = !!token