Przeglądaj źródła

feat(mine): 优化登录体验和未登录状态处理

- 为昵称添加点击跳转登录功能
- 移除强制登录弹窗,改为用户主动触发
- 注释掉 onShow 中的自动跳转逻辑
- 将"未登录"文案统一改为"立即登录"
- 移除多余的登录提示弹窗代码
- 添加 goLogin 方法处理登录跳转

feat(recommend): 添加未登录状态下的登录引导

- 在推荐列表为空时显示登录引导按钮
- 添加 goLogin 方法跳转到登录页面
- 优化空状态样式和交互效果
李思佳 1 miesiąc temu
rodzic
commit
974e21417d

+ 33 - 77
LiangZhiYUMao/pages/mine/index.vue

@@ -6,7 +6,7 @@
         <image class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
         <view class="user-details">
           <view class="nickname-row">
-            <text class="nickname">{{ userInfo.nickname }}</text>
+            <text class="nickname" @click="goLogin">{{ userInfo.nickname }}</text>
             <!-- VIP标志 -->
           <view class="vip-badge" v-if="userInfo.isVip">
             <text class="vip-badge-text">VIP</text>
@@ -302,30 +302,13 @@ export default {
     }
   },
   onLoad() {
-   
+
 
     // 立即检查登录状态
     const token = uni.getStorageSync('token')
     const userInfo = uni.getStorageSync('userInfo')
 
-    if (!token || !userInfo) {
-      // 未登录,立即强制跳转到登录页
-     
-      uni.showModal({
-        title: '需要登录',
-        content: '请先登录后查看个人信息',
-        showCancel: false,  // 不允许取消
-        confirmText: '去登录',
-        success: () => {
-          uni.navigateTo({
-            url: '/pages/page3/page3'
-          })
-        }
-      })
-      return
-    }
-
-    // 已登录,同步登录状态
+    // 直接同步登录状态,不强制弹窗
     this.syncLoginStatus()
 
     // 监听VIP购买成功事件
@@ -336,25 +319,25 @@ export default {
     // 页面卸载时移除事件监听
     uni.$off('vipPurchased', this.handleVipPurchased)
   },
-
-  onShow() {
-   
-    // 检查登录状态
-    const token = uni.getStorageSync('token')
-    const userInfo = uni.getStorageSync('userInfo')
-
-    if (!token || !userInfo) {
-      // 未登录,直接跳转(不显示弹窗,因为onLoad已经显示过了)
-     
-      uni.navigateTo({
-        url: '/pages/page3/page3'
-      })
-      return
-    }
-
-    // 已登录,同步登录状态
-    this.syncLoginStatus()
-  },
+  //
+  // onShow() {
+  //
+  //   // 检查登录状态
+  //   const token = uni.getStorageSync('token')
+  //   const userInfo = uni.getStorageSync('userInfo')
+  //
+  //   if (!token || !userInfo) {
+  //     // 未登录,直接跳转(不显示弹窗,因为onLoad已经显示过了)
+  //
+  //     uni.navigateTo({
+  //       url: '/pages/page3/page3'
+  //     })
+  //     return
+  //   }
+  //
+  //   // 已登录,同步登录状态
+  //   this.syncLoginStatus()
+  // },
   methods: {
     // 同步登录状态并更新页面数据
     syncLoginStatus() {
@@ -419,7 +402,7 @@ export default {
         // 设置未登录状态的用户信息
         this.userInfo = {
           userId: null,
-          nickname: '登录',
+          nickname: '立即登录',
           avatar: 'https://via.placeholder.com/100?text=未登录',
           phone: '',
           email: '',
@@ -442,21 +425,6 @@ export default {
 
         // 强制页面更新
         this.$forceUpdate()
-
-        // 提示需要登录
-        setTimeout(() => {
-          uni.showModal({
-            title: '需要登录',
-            content: '请先登录后查看完整功能',
-            showCancel: false,
-            confirmText: '去登录',
-            success: () => {
-              uni.navigateTo({
-                url: '/pages/page3/page3'
-              })
-            }
-          })
-        }, 500)
       }
     },
 
@@ -626,7 +594,7 @@ export default {
     setDefaultUserInfo() {
       this.userInfo = {
         userId: null,
-        nickname: '未登录用户',
+        nickname: '立即登录',
         avatar: 'https://via.placeholder.com/100?text=未登录',
         phone: '',
         email: '',
@@ -652,27 +620,6 @@ export default {
         hobby: null,
         authenticityScore: 0
       }
-
-      // 显示登录提示(仅在没有登录时显示)
-      const token = uni.getStorageSync('token')
-      if (!token) {
-        setTimeout(() => {
-          uni.showModal({
-            title: '提示',
-            content: '请先登录以查看完整功能',
-            showCancel: true,
-            cancelText: '稍后',
-            confirmText: '去登录',
-            success: (res) => {
-              if (res.confirm) {
-                uni.navigateTo({
-                  url: '/pages/page3/page3?redirect=' + encodeURIComponent('/pages/mine/index')
-                })
-              }
-            }
-          })
-        }, 1000) // 延迟1秒显示,避免页面刚加载就弹窗
-      }
     },
 
     // 加载签到信息
@@ -1345,6 +1292,15 @@ export default {
           })
         }
       })
+    },
+    
+    // 跳转到登录页面
+    goLogin() {
+      if (this.userInfo.nickname === '立即登录') {
+        uni.navigateTo({
+          url: '/pages/page3/page3?redirect=' + encodeURIComponent('/pages/mine/index')
+        })
+      }
     }
   }
 }

+ 26 - 4
LiangZhiYUMao/pages/recommend/index.vue

@@ -219,7 +219,9 @@
 						</button>
 					</view>
 				</view>
-				<view v-if="!list.length" class="empty">暂无推荐</view>
+				<view v-if="!list.length" class="empty-container">
+                <view class="empty" @click="goLogin">前往登录,解锁功能</view>
+              </view>
 			</view>
 		</scroll-view>
 		<!-- 底部导航栏 -->
@@ -985,6 +987,12 @@ export default {
 		// 照片加载错误处理
 		onPhotoError(e) {
 			console.error('照片加载失败:', e)
+		},
+		// 跳转到登录页面
+		goLogin() {
+			uni.navigateTo({
+				url: '/pages/page3/page3?redirect=' + encodeURIComponent('/pages/recommend/index')
+			})
 		}
 	}
 }
@@ -1115,11 +1123,25 @@ export default {
 		color: #999;
 	}
 	
+	.empty-container{ 
+		width: 100%; 
+		height: 500rpx; 
+		display: flex; 
+		justify-content: center; 
+		align-items: center;
+	}
+	
 	.empty{ 
-		padding: 60rpx 20rpx; 
+		padding: 20rpx 40rpx; 
 		text-align: center; 
-		color: #999; 
-		font-size: 26rpx;
+		color: #E91E63; 
+		font-size: 28rpx;
+		font-weight: 600;
+		transition: all 0.2s ease;
+		
+		&:active {
+			opacity: 0.8;
+		}
 	}
 	
 	/* 用户卡片 - 扁平化 */