Files
ai_dianshang/miniprogram/pages/debug/hardcoded-comment-test.js
2025-11-17 14:11:46 +08:00

230 lines
6.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/debug/hardcoded-comment-test.js
Page({
data: {
// 商品ID测试相关
testProductId: '1',
testResults: [],
// 硬编码的评论统计数据 - 确保有评论
commentsStatistics: {
commentCount: 5,
goodCount: 4,
middleCount: 1,
badCount: 0,
goodRate: 80,
hasImageCount: 2,
},
// 硬编码的评论列表数据
commentsList: [
{
id: 1,
userName: '测试用户1',
userHeadUrl: 'https://tdesign.gtimg.com/miniprogram/template/retail/avatar/avatar1.png',
commentScore: 5,
commentContent: '商品质量很好,物流也很快!',
commentTime: '2024-01-15',
specInfo: '颜色:红色 尺寸:M',
commentResources: [],
isAnonymity: false,
sellerReply: '',
goodsDetailInfo: ''
},
{
id: 2,
userName: '测试用户2',
userHeadUrl: 'https://tdesign.gtimg.com/miniprogram/template/retail/avatar/avatar2.png',
commentScore: 4,
commentContent: '整体不错,性价比很高,推荐购买!',
commentTime: '2024-01-14',
specInfo: '颜色:蓝色 尺寸:L',
commentResources: ['https://example.com/image1.jpg'],
isAnonymity: false,
sellerReply: '感谢您的好评!',
goodsDetailInfo: ''
},
{
id: 3,
userName: '匿名用户',
userHeadUrl: 'https://tdesign.gtimg.com/miniprogram/template/retail/avatar/avatar3.png',
commentScore: 3,
commentContent: '一般般,还可以吧。',
commentTime: '2024-01-13',
specInfo: '颜色:绿色 尺寸:S',
commentResources: [],
isAnonymity: true,
sellerReply: '',
goodsDetailInfo: ''
}
],
// 测试状态
testMode: 'with-comments', // 'with-comments' 或 'no-comments'
debugInfo: {
commentCount: 5,
displayCondition: true,
timestamp: ''
}
},
onLoad: function (options) {
console.log('硬编码评论测试页面加载');
this.updateDebugInfo();
},
// 更新调试信息
updateDebugInfo() {
const { commentsStatistics } = this.data;
this.setData({
'debugInfo.commentCount': commentsStatistics.commentCount,
'debugInfo.displayCondition': commentsStatistics.commentCount > 0,
'debugInfo.timestamp': new Date().toLocaleTimeString()
});
console.log('调试信息更新:', {
commentCount: commentsStatistics.commentCount,
displayCondition: commentsStatistics.commentCount > 0,
shouldShow: commentsStatistics.commentCount > 0 ? '应该显示' : '不应该显示'
});
},
// 切换测试模式
switchTestMode() {
const newMode = this.data.testMode === 'with-comments' ? 'no-comments' : 'with-comments';
if (newMode === 'no-comments') {
// 设置为无评论状态
this.setData({
testMode: newMode,
commentsStatistics: {
commentCount: 0,
goodCount: 0,
middleCount: 0,
badCount: 0,
goodRate: 0,
hasImageCount: 0,
},
commentsList: []
});
} else {
// 设置为有评论状态
this.setData({
testMode: newMode,
commentsStatistics: {
commentCount: 5,
goodCount: 4,
middleCount: 1,
badCount: 0,
goodRate: 80,
hasImageCount: 2,
},
commentsList: [
{
id: 1,
userName: '测试用户1',
userHeadUrl: 'https://tdesign.gtimg.com/miniprogram/template/retail/avatar/avatar1.png',
commentScore: 5,
commentContent: '商品质量很好,物流也很快!',
commentTime: '2024-01-15',
specInfo: '颜色:红色 尺寸:M',
commentResources: [],
isAnonymity: false,
sellerReply: '',
goodsDetailInfo: ''
},
{
id: 2,
userName: '测试用户2',
userHeadUrl: 'https://tdesign.gtimg.com/miniprogram/template/retail/avatar/avatar2.png',
commentScore: 4,
commentContent: '整体不错,性价比很高,推荐购买!',
commentTime: '2024-01-14',
specInfo: '颜色:蓝色 尺寸:L',
commentResources: ['https://example.com/image1.jpg'],
isAnonymity: false,
sellerReply: '感谢您的好评!',
goodsDetailInfo: ''
},
{
id: 3,
userName: '匿名用户',
userHeadUrl: 'https://tdesign.gtimg.com/miniprogram/template/retail/avatar/avatar3.png',
commentScore: 3,
commentContent: '一般般,还可以吧。',
commentTime: '2024-01-13',
specInfo: '颜色:绿色 尺寸:S',
commentResources: [],
isAnonymity: true,
sellerReply: '',
goodsDetailInfo: ''
}
]
});
}
this.updateDebugInfo();
},
// 跳转到评论列表页面(占位函数)
navToCommentsListPage() {
console.log('跳转到评论列表页面');
wx.showToast({
title: '跳转到评论列表',
icon: 'none'
});
},
// 输入框值变化
onProductIdInput(e) {
this.setData({
testProductId: e.detail.value
});
},
// 测试商品ID验证
async testProductIdValidation() {
const { testProductId } = this.data;
console.log(`[调试页面] 开始测试商品ID: "${testProductId}"`);
const testResult = {
productId: testProductId,
timestamp: new Date().toLocaleTimeString(),
success: false,
error: null,
data: null
};
try {
// 导入评论服务
const { fetchCommentsCount } = require('../../services/comments/fetchCommentsCount');
console.log(`[调试页面] 调用 fetchCommentsCount参数: "${testProductId}"`);
const result = await fetchCommentsCount(testProductId);
testResult.success = true;
testResult.data = result;
console.log(`[调试页面] 测试成功:`, result);
} catch (error) {
testResult.success = false;
testResult.error = error.message;
console.error(`[调试页面] 测试失败:`, error);
}
// 更新测试结果
const testResults = [testResult, ...this.data.testResults.slice(0, 9)]; // 保留最近10条
this.setData({ testResults });
},
// 快速测试预设值
async quickTest(e) {
const testValue = e.currentTarget.dataset.value;
this.setData({ testProductId: testValue });
await this.testProductIdValidation();
},
// 清空测试结果
clearTestResults() {
this.setData({ testResults: [] });
}
});