Explorar el Código

修复活动详情页图片和时间显示问题

YH_0525 hace 1 mes
padre
commit
1ddae3292c

+ 89 - 3
LiangZhiYUMao/pages/activities/detail.vue

@@ -11,7 +11,8 @@
 
 		<!-- 活动封面 -->
 		<view class="activity-cover">
-			<image :src="activity.coverImage" class="cover-image" mode="aspectFill"></image>
+			<image :src="activity.coverImage" class="cover-image" mode="aspectFill" 
+				@error="handleImageError" @load="handleImageLoad"></image>
 			<view class="cover-mask">
 				<view class="activity-tag" v-if="activity.isHot">🔥 热门活动</view>
 			</view>
@@ -25,7 +26,7 @@
 				<view class="info-item">
 					<text class="info-icon">⏰</text>
 					<text class="info-label">活动时间:</text>
-					<text class="info-value">{{ formatTime(activity.startTime) }}</text>
+					<text class="info-value">{{ formatActivityTime(activity.startTime, activity.endTime) }}</text>
 				</view>
 				<view class="info-item">
 					<text class="info-icon">📍</text>
@@ -106,7 +107,20 @@
 				try {
 					const data = await api.activity.getDetail(this.activityId)
 					if (data) {
-						this.activity = data
+						// 处理字段映射,确保前端使用的字段名统一
+						this.activity = {
+							...data,
+							coverImage: this.validateImageUrl(data.coverImage || data.cover_image || data.imageUrl || data.image_url),
+							startTime: data.startTime || data.start_time || data.startDate || data.start_date || '',
+							endTime: data.endTime || data.end_time || data.endDate || data.end_date || '',
+							location: data.location || data.address || data.venue || '待定',
+							maxParticipants: data.maxParticipants || data.max_participants || null,
+							actualParticipants: data.actualParticipants || data.actual_participants || 0,
+							price: data.price || data.fee || 0,
+							description: data.description || data.desc || '暂无介绍',
+							notes: data.notes || data.notice || '请准时参加活动'
+						}
+						console.log('活动详情加载成功:', this.activity)
 					}
 				} catch (error) {
 					console.error('加载活动详情失败:', error)
@@ -117,9 +131,70 @@
 				}
 			},
 
+			// 验证并修正图片URL
+			validateImageUrl(url) {
+				if (!url || url === 'null' || url === 'undefined') {
+					return DEFAULT_IMAGES.activity || '/static/default-activity.jpg'
+				}
+
+				let cleanedUrl = String(url).trim()
+				const httpIndex = cleanedUrl.indexOf('http')
+				if (httpIndex > 0) {
+					cleanedUrl = cleanedUrl.slice(httpIndex)
+				}
+
+				if (!cleanedUrl) {
+					return DEFAULT_IMAGES.activity || '/static/default-activity.jpg'
+				}
+				
+				// 如果是相对路径,添加协议和域名
+				if (cleanedUrl.startsWith('/')) {
+					return `http://115.190.125.125:9000${cleanedUrl}`
+				}
+				
+				// 如果已经是完整URL,直接返回
+				if (cleanedUrl.startsWith('http://') || cleanedUrl.startsWith('https://')) {
+					return cleanedUrl
+				}
+				
+				// 其他情况返回默认图片
+				return DEFAULT_IMAGES.activity || '/static/default-activity.jpg'
+			},
+
 			// 格式化时间
 			formatTime,
 
+			// 格式化活动时间(显示开始和结束时间)
+			formatActivityTime(startTime, endTime) {
+				if (!startTime) return '时间待定'
+				
+				try {
+					const start = new Date(startTime)
+					const startMonth = start.getMonth() + 1
+					const startDay = start.getDate()
+					const startHour = start.getHours().toString().padStart(2, '0')
+					const startMinute = start.getMinutes().toString().padStart(2, '0')
+					
+					let timeStr = `${startMonth}月${startDay}日 ${startHour}:${startMinute}`
+					
+					// 如果有结束时间,添加结束时间
+					if (endTime) {
+						const end = new Date(endTime)
+						const endMonth = end.getMonth() + 1
+						const endDay = end.getDate()
+						const endHour = end.getHours().toString().padStart(2, '0')
+						const endMinute = end.getMinutes().toString().padStart(2, '0')
+						
+						timeStr += ` - ${endMonth}月${endDay}日 ${endHour}:${endMinute}`
+					}
+					
+					return timeStr
+				} catch (error) {
+					console.error('时间格式化失败:', error)
+					return '时间待定'
+				}
+			},
+
 			// 处理报名
 			handleRegister() {
 				// 获取当前用户ID
@@ -182,6 +257,17 @@
 			// 返回
 			goBack() {
 				uni.navigateBack()
+			},
+
+			// 图片加载错误处理
+			handleImageError(e) {
+				console.warn('活动封面图片加载失败:', e)
+				this.activity.coverImage = DEFAULT_IMAGES.activity || '/static/default-activity.jpg'
+			},
+
+			// 图片加载成功
+			handleImageLoad(e) {
+				console.log('活动封面图片加载成功')
 			}
 		}
 	}

+ 1 - 1
LiangZhiYUMao/pages/index/index.vue

@@ -424,7 +424,7 @@
 					}
 				} catch (error) {
 					console.error('获取推荐用户失败:', error)
-					// 失败时使用默认数据,不影响页面显示
+					// 使用默认数据
 				}
 			},
 

+ 57 - 42
LiangZhiYUMao/pages/page3/page3.vue

@@ -1,7 +1,7 @@
 <template>
 	<view class="content">
 		<!-- 背景图片 -->
-		<image class="bg-image" src="/static/login-bg.png" mode="aspectFill"></image>
+		<image class="bg-image" src="/static/login-bg.png" mode="aspectFill"></image>
 		
 		
 		<!-- 顶部标题区域 -->
@@ -18,7 +18,7 @@
 			<button class="wechat-login-btn" @click="login_zheshow">
 				<image class="wechat-icon" src="/static/wechat-icon.png" mode="aspectFit"></image>
 				<text>微信一键登录</text>
-			</button>
+			</button>
 		
 		</view>
 		
@@ -104,7 +104,22 @@
 							
 							console.log('💾 保存用户信息:', { userId: user.userId, phone: user.phone, nickname: user.nickname })
 							
-							// 4. 保存登录信息
+							// 4. 如果用户输入了昵称或头像,更新到后端
+							if (Logon_Credentials.nickname || Logon_Credentials.active) {
+								try {
+									await api.user.updateInfo({
+										userId: user.userId,
+										nickname: user.nickname,
+										avatarUrl: user.avatar
+									})
+									console.log('✅ 用户信息已更新到后端')
+								} catch (updateError) {
+									console.warn('⚠️ 更新用户信息失败:', updateError)
+									// 不影响登录流程,继续
+								}
+							}
+							
+							// 5. 保存登录信息
 							userAuth.saveLoginInfo(token, user)
 							
 							uni.hideLoading()
@@ -248,45 +263,45 @@
 	// 		opacity: 0.9;
 	// 		transform: translateY(2rpx);
 	// 	}
-	// }
-	.wechat-login-btn {
-	  width: 100%;
-	  height: 96rpx;
-	  // 渐变背景+光泽叠加
-	  background: linear-gradient(90deg, #9d40e9 0%, #5a35f7 100%),
-	              radial-gradient(circle at 30% 30%, rgba(255,255,255,0.15), transparent 50%);
-	  background-blend-mode: overlay;
-	  color: #ffffff;
-	  border-radius: 60rpx;
-	  font-size: 32rpx;
-	  font-weight: bold;
-	  display: flex;
-	  align-items: center;
-	  justify-content: center;
-	  border: none;
-	  // 多层光影:外层投影+内高光+内阴影
-	  box-shadow: 
-	    0 6rpx 16rpx rgba(90, 53, 247, 0.4), 
-	    0 3rpx 8rpx rgba(90, 53, 247, 0.2),
-	    inset 0 2rpx 3rpx rgba(255, 255, 255, 0.25),
-	    inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.15);
-	  transition: all 0.2s ease; // 动画过渡,更自然
-	}
-	
-	.wechat-login-btn:active {
-	  transform: translateY(2rpx);
-	  box-shadow: 
-	    0 3rpx 8rpx rgba(90, 53, 247, 0.3), 
-	    0 1rpx 4rpx rgba(90, 53, 247, 0.2),
-	    inset 0 1rpx 2rpx rgba(255, 255, 255, 0.15),
-	    inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.2);
-	}
-	
-	.wechat-icon {
-	  width: 45rpx;
-	  height: 45rpx;
-	  margin-right: 15rpx;
-	  filter: drop-shadow(0 1rpx 2rpx rgba(0,0,0,0.1)); // 给图标加轻微阴影,更立体
+	// }
+	.wechat-login-btn {
+	  width: 100%;
+	  height: 96rpx;
+	  // 渐变背景+光泽叠加
+	  background: linear-gradient(90deg, #9d40e9 0%, #5a35f7 100%),
+	              radial-gradient(circle at 30% 30%, rgba(255,255,255,0.15), transparent 50%);
+	  background-blend-mode: overlay;
+	  color: #ffffff;
+	  border-radius: 60rpx;
+	  font-size: 32rpx;
+	  font-weight: bold;
+	  display: flex;
+	  align-items: center;
+	  justify-content: center;
+	  border: none;
+	  // 多层光影:外层投影+内高光+内阴影
+	  box-shadow: 
+	    0 6rpx 16rpx rgba(90, 53, 247, 0.4), 
+	    0 3rpx 8rpx rgba(90, 53, 247, 0.2),
+	    inset 0 2rpx 3rpx rgba(255, 255, 255, 0.25),
+	    inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.15);
+	  transition: all 0.2s ease; // 动画过渡,更自然
+	}
+	
+	.wechat-login-btn:active {
+	  transform: translateY(2rpx);
+	  box-shadow: 
+	    0 3rpx 8rpx rgba(90, 53, 247, 0.3), 
+	    0 1rpx 4rpx rgba(90, 53, 247, 0.2),
+	    inset 0 1rpx 2rpx rgba(255, 255, 255, 0.15),
+	    inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.2);
+	}
+	
+	.wechat-icon {
+	  width: 45rpx;
+	  height: 45rpx;
+	  margin-right: 15rpx;
+	  filter: drop-shadow(0 1rpx 2rpx rgba(0,0,0,0.1)); // 给图标加轻微阴影,更立体
 	}
 }
 

+ 8 - 2
LiangZhiYUMao/utils/api.js

@@ -81,11 +81,17 @@ export default {
     // 获取今日匹配数
     getMatchCount: () => request({ url: '/user/match-count' }),
     
-    // 更新用户信息
+    // 更新用户基本信息(昵称、头像等)
     updateInfo: (data) => request({ 
-      url: '/user/info', 
+      url: '/user/basic', 
       method: 'PUT', 
       data 
+    }),
+    
+    // 更新单个字段
+    updateField: (userId, fieldName, fieldValue) => request({
+      url: `/user/basic/field?userId=${userId}&fieldName=${fieldName}&fieldValue=${encodeURIComponent(fieldValue)}`,
+      method: 'PUT'
     })
   },