init
This commit is contained in:
102
miniprogram/pages/test-comment-stats/index.js
Normal file
102
miniprogram/pages/test-comment-stats/index.js
Normal file
@@ -0,0 +1,102 @@
|
||||
// 测试评论统计数量显示
|
||||
import { fetchCommentsCount } from '../../services/comments/fetchCommentsCount';
|
||||
import { fetchUserComments } from '../../services/comments/createComment';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
spuId: '31',
|
||||
countObj: {
|
||||
commentCount: '0',
|
||||
goodCount: '0',
|
||||
middleCount: '0',
|
||||
badCount: '0',
|
||||
hasImageCount: '0',
|
||||
uidCount: '0',
|
||||
},
|
||||
loading: false,
|
||||
error: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
console.log('测试评论统计页面加载');
|
||||
this.testGetCount();
|
||||
},
|
||||
|
||||
// 测试获取评论统计
|
||||
async testGetCount() {
|
||||
console.log('开始测试获取评论统计');
|
||||
|
||||
this.setData({
|
||||
loading: true,
|
||||
error: null
|
||||
});
|
||||
|
||||
try {
|
||||
const spuId = this.data.spuId;
|
||||
console.log('[测试] 获取商品评论统计,spuId:', spuId);
|
||||
|
||||
// 获取评论统计
|
||||
const result = await fetchCommentsCount(spuId);
|
||||
console.log('[测试] fetchCommentsCount 返回数据:', result);
|
||||
|
||||
// 尝试获取用户自己的评论数
|
||||
try {
|
||||
const token = wx.getStorageSync('token');
|
||||
console.log('[测试] 当前token:', token ? '存在' : '不存在');
|
||||
|
||||
if (token) {
|
||||
const userCommentsData = await fetchUserComments({
|
||||
page: 1,
|
||||
pageSize: 1
|
||||
});
|
||||
console.log('[测试] 用户评论数据:', userCommentsData);
|
||||
|
||||
if (userCommentsData && userCommentsData.total !== undefined) {
|
||||
result.uidCount = String(userCommentsData.total);
|
||||
console.log('[测试] 获取到用户评论数:', userCommentsData.total);
|
||||
}
|
||||
}
|
||||
} catch (userError) {
|
||||
console.log('[测试] 获取用户评论数失败,使用默认值0:', userError.message);
|
||||
// 保持默认值0,不影响主要功能
|
||||
}
|
||||
|
||||
console.log('[测试] 最终统计数据:', result);
|
||||
|
||||
this.setData({
|
||||
countObj: result,
|
||||
loading: false
|
||||
});
|
||||
|
||||
wx.showToast({
|
||||
title: '获取统计成功',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('[测试] 获取评论统计失败:', error);
|
||||
|
||||
this.setData({
|
||||
error: error.message,
|
||||
loading: false
|
||||
});
|
||||
|
||||
wx.showToast({
|
||||
title: error.message || '获取统计失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 切换商品ID进行测试
|
||||
changeSpuId(e) {
|
||||
const spuId = e.detail.value;
|
||||
this.setData({ spuId });
|
||||
console.log('[测试] 切换商品ID为:', spuId);
|
||||
},
|
||||
|
||||
// 重新获取统计
|
||||
refreshStats() {
|
||||
this.testGetCount();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user