diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 5bb5637..19a1406 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -2753,6 +2753,16 @@ Page({ }); }, + // Seeded random number generator for consistent results + seededRandom(seed) { + // Improved seeded random using a linear congruential generator + const a = 1103515245; + const c = 12345; + const m = Math.pow(2, 31); + const nextSeed = (a * seed + c) % m; + return nextSeed / m; + }, + // 20 default comments getDefaultComments() { return [ @@ -2779,16 +2789,6 @@ Page({ ]; }, - // Seeded random number generator for consistent results - seededRandom(seed) { - // Improved seeded random using a linear congruential generator - const a = 1103515245; - const c = 12345; - const m = Math.pow(2, 31); - const nextSeed = (a * seed + c) % m; - return nextSeed / m; - }, - // Get consistent random comments based on product ID getConsistentRandomComments(productId, count = 2) { const defaultComments = this.getDefaultComments(); @@ -2827,7 +2827,27 @@ Page({ // 加载商品评论 loadComments: function(productId) { console.log('开始加载商品评论,商品ID:', productId); - console.log('当前用户手机号:', this.data.currentUserPhone); + + // 重新获取当前用户手机号,确保使用最新的值 + let currentUserPhone = ''; + const userId = wx.getStorageSync('userId'); + const users = wx.getStorageSync('users') || {}; + const userInfo = wx.getStorageSync('userInfo') || {}; + + if (userId && users[userId] && users[userId].phoneNumber) { + currentUserPhone = users[userId].phoneNumber; + } else if (userInfo.phoneNumber) { + currentUserPhone = userInfo.phoneNumber; + } else { + currentUserPhone = wx.getStorageSync('phoneNumber'); + } + + // 更新data中的currentUserPhone + this.setData({ + currentUserPhone: currentUserPhone + }); + + console.log('当前用户手机号:', currentUserPhone); API.getComments(productId) .then(res => { @@ -2871,9 +2891,7 @@ Page({ }); commentsData = uniqueComments; - // Always add default comments at the beginning - const defaultComments = this.getConsistentRandomComments(productId, 2); - commentsData = [...defaultComments, ...commentsData]; + // 检查返回的评论是否都属于当前用户 const allCommentsBelongToCurrentUser = commentsData.every(comment => diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml index 3e14f2a..7310d0f 100644 --- a/pages/goods-detail/goods-detail.wxml +++ b/pages/goods-detail/goods-detail.wxml @@ -233,25 +233,21 @@ - - + - 商品评价 ({{comments.length}}条) - 评论按钮 - + - 评论列表 @@ -261,8 +257,7 @@ {{item.nickname || '匿名用户'}} {{item.time || '刚刚'}} - 删除按钮,仅当前用户的评论显示且非默认评论 - + 删除 @@ -278,9 +273,8 @@ ---> - - + + diff --git a/pages/goods-detail/goods-detail.wxss b/pages/goods-detail/goods-detail.wxss index d7c7b71..1a3de16 100644 --- a/pages/goods-detail/goods-detail.wxss +++ b/pages/goods-detail/goods-detail.wxss @@ -1425,15 +1425,16 @@ video.slider-media .wx-video-volume-icon { .comment-content { margin-bottom: 12px; + width: 100%; + overflow: auto; + -webkit-overflow-scrolling: touch; } .content-text { font-size: 14px; line-height: 1.6; color: #595959; - word-break: break-all; - word-wrap: break-word; - white-space: normal; + white-space: nowrap; } .comment-footer { @@ -1447,6 +1448,17 @@ video.slider-media .wx-video-volume-icon { gap: 24px; } +.delete-btn { + font-size: 12px; + color: #ff4d4f; + cursor: pointer; + transition: color 0.2s ease; +} + +.delete-btn:active { + color: #ff7875; +} + .action-item { display: flex; align-items: center; @@ -1651,6 +1663,166 @@ video.slider-media .wx-video-volume-icon { transform: scale(0.98); } +/* 评论区样式增强 */ +.comments-section { + background-color: #ffffff; + margin: 0 0 90px; + padding: 16px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); + border-top: 1px solid #f0f0f0; +} + +.comments-header { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + margin-bottom: 20px; + padding-bottom: 12px; + border-bottom: 1px solid #f0f0f0; +} + +.comments-title { + display: flex; + align-items: baseline; + gap: 8px; +} + +.comments-label { + font-size: 18px; + font-weight: 700; + color: #262626; +} + +.comments-count { + font-size: 14px; + color: #8c8c8c; + font-weight: 500; +} + +.comment-action { + display: flex; + align-items: center; +} + +.comment-button { + background-color: #1890ff; + color: #ffffff; + border: none; + border-radius: 8rpx; + padding: 16rpx 48rpx; + font-size: 28rpx; + font-weight: 600; + box-shadow: 0 2rpx 8rpx rgba(24, 144, 255, 0.3); + transition: all 0.3s ease; + white-space: nowrap; +} + +.comment-button:active { + background-color: #40a9ff; + transform: scale(0.98); + box-shadow: 0 3rpx 8rpx rgba(24, 144, 255, 0.4); +} + +.comments-list { + margin-bottom: 20px; +} + +.comment-item { + margin-bottom: 24px; + padding-bottom: 24px; + border-bottom: 1px solid #f0f0f0; +} + +.comment-item:last-child { + border-bottom: none; + margin-bottom: 0; + padding-bottom: 0; +} + +.comment-user { + display: flex; + align-items: center; + gap: 12px; + margin-bottom: 12px; +} + +.user-avatar { + width: 40px; + height: 40px; + border-radius: 50%; + object-fit: cover; + background-color: #f0f0f0; + border: 1px solid #e0e0e0; +} + +.user-info { + display: flex; + flex-direction: column; + gap: 4px; + flex: 1; +} + +.user-nickname { + font-size: 14px; + font-weight: 600; + color: #262626; +} + +.comment-time { + font-size: 12px; + color: #8c8c8c; +} + +.comment-actions { + margin-left: auto; +} + +.delete-btn { + color: #ff4d4f; + font-size: 28rpx; + padding: 8rpx 16rpx; + border-radius: 8rpx; + transition: all 0.3s ease; +} + +.delete-btn:active { + background-color: rgba(255, 77, 79, 0.1); + transform: scale(0.98); +} + +.comment-content { + margin-bottom: 12px; + width: 100%; + overflow: auto; + -webkit-overflow-scrolling: touch; +} + +.content-text { + font-size: 14px; + line-height: 1.6; + color: #595959; + white-space: nowrap; +} + +.comments-empty { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 40px 0; + color: #8c8c8c; + background-color: #fafafa; + border-radius: 8px; + margin: 20px 0; +} + +.empty-text { + font-size: 14px; + text-align: center; + color: #8c8c8c; +} + /* 评论弹窗样式 */ /* 讲价弹窗样式 */ .bargain-modal-overlay {