106 lines
2.9 KiB
JavaScript
106 lines
2.9 KiB
JavaScript
|
|
// 评论服务测试页面
|
||
|
|
const { fetchComments } = require('../../services/comments/fetchComments');
|
||
|
|
const { fetchCommentsCount } = require('../../services/comments/fetchCommentsCount');
|
||
|
|
|
||
|
|
Page({
|
||
|
|
data: {
|
||
|
|
testResults: [],
|
||
|
|
isLoading: false
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad() {
|
||
|
|
console.log('评论测试页面加载');
|
||
|
|
},
|
||
|
|
|
||
|
|
// 测试评论统计
|
||
|
|
async testCommentsCount() {
|
||
|
|
this.setData({ isLoading: true });
|
||
|
|
const results = [...this.data.testResults];
|
||
|
|
|
||
|
|
try {
|
||
|
|
console.log('开始测试 fetchCommentsCount...');
|
||
|
|
const result = await fetchCommentsCount(1);
|
||
|
|
console.log('fetchCommentsCount 结果:', result);
|
||
|
|
|
||
|
|
// 模拟商品详情页面的数据处理逻辑
|
||
|
|
const goodRate = result.total_count > 0 ? Math.round((result.good_count / result.total_count) * 100) : 0;
|
||
|
|
const commentsStatistics = {
|
||
|
|
commentCount: result.total_count || 0,
|
||
|
|
goodCount: result.good_count || 0,
|
||
|
|
middleCount: result.medium_count || 0,
|
||
|
|
badCount: result.bad_count || 0,
|
||
|
|
goodRate: goodRate,
|
||
|
|
hasImageCount: result.image_count || 0,
|
||
|
|
};
|
||
|
|
|
||
|
|
console.log('处理后的统计数据:', commentsStatistics);
|
||
|
|
console.log('显示条件 (commentCount > 0):', commentsStatistics.commentCount > 0);
|
||
|
|
|
||
|
|
results.push({
|
||
|
|
test: 'fetchCommentsCount',
|
||
|
|
status: 'success',
|
||
|
|
data: {
|
||
|
|
raw: result,
|
||
|
|
processed: commentsStatistics,
|
||
|
|
shouldShow: commentsStatistics.commentCount > 0
|
||
|
|
},
|
||
|
|
time: new Date().toLocaleTimeString()
|
||
|
|
});
|
||
|
|
} catch (error) {
|
||
|
|
console.error('fetchCommentsCount 错误:', error);
|
||
|
|
results.push({
|
||
|
|
test: 'fetchCommentsCount',
|
||
|
|
status: 'error',
|
||
|
|
error: error.message,
|
||
|
|
time: new Date().toLocaleTimeString()
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
this.setData({ testResults: results, isLoading: false });
|
||
|
|
},
|
||
|
|
|
||
|
|
// 测试评论列表
|
||
|
|
async testCommentsList() {
|
||
|
|
this.setData({ isLoading: true });
|
||
|
|
const results = [...this.data.testResults];
|
||
|
|
|
||
|
|
try {
|
||
|
|
console.log('开始测试 fetchComments...');
|
||
|
|
const result = await fetchComments({
|
||
|
|
productId: 1,
|
||
|
|
page: 1,
|
||
|
|
page_size: 3
|
||
|
|
});
|
||
|
|
console.log('fetchComments 结果:', result);
|
||
|
|
|
||
|
|
results.push({
|
||
|
|
test: 'fetchComments',
|
||
|
|
status: 'success',
|
||
|
|
data: result,
|
||
|
|
time: new Date().toLocaleTimeString()
|
||
|
|
});
|
||
|
|
} catch (error) {
|
||
|
|
console.error('fetchComments 错误:', error);
|
||
|
|
results.push({
|
||
|
|
test: 'fetchComments',
|
||
|
|
status: 'error',
|
||
|
|
error: error.message,
|
||
|
|
time: new Date().toLocaleTimeString()
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
this.setData({ testResults: results, isLoading: false });
|
||
|
|
},
|
||
|
|
|
||
|
|
// 清空测试结果
|
||
|
|
clearResults() {
|
||
|
|
this.setData({ testResults: [] });
|
||
|
|
},
|
||
|
|
|
||
|
|
// 运行所有测试
|
||
|
|
async runAllTests() {
|
||
|
|
this.clearResults();
|
||
|
|
await this.testCommentsCount();
|
||
|
|
await this.testCommentsList();
|
||
|
|
}
|
||
|
|
});
|