|
|
|
@ -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 => |
|
|
|
|