Initial commit
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();
|
||||
}
|
||||
});
|
||||
3
miniprogram/pages/test-comment-stats/index.json
Normal file
3
miniprogram/pages/test-comment-stats/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
73
miniprogram/pages/test-comment-stats/index.wxml
Normal file
73
miniprogram/pages/test-comment-stats/index.wxml
Normal file
@@ -0,0 +1,73 @@
|
||||
<view class="container">
|
||||
<view class="header">
|
||||
<text class="title">测试评论统计数量显示</text>
|
||||
</view>
|
||||
|
||||
<view class="input-section">
|
||||
<text class="label">商品ID:</text>
|
||||
<input class="input" value="{{spuId}}" bindinput="changeSpuId" placeholder="请输入商品ID" />
|
||||
<button class="refresh-btn" bindtap="refreshStats" disabled="{{loading}}">
|
||||
{{loading ? '加载中...' : '获取统计'}}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<view class="status" wx:if="{{error}}">
|
||||
<text class="error">错误: {{error}}</text>
|
||||
</view>
|
||||
|
||||
<!-- 模拟评论页面的标签显示 -->
|
||||
<view class="comments-header">
|
||||
<view class="tag {{commentType === '' ? 'active' : ''}}">
|
||||
全部({{countObj.commentCount}})
|
||||
</view>
|
||||
<view class="tag {{commentType === '5' ? 'active' : ''}}" wx:if="{{countObj.uidCount !== '0'}}">
|
||||
自己({{countObj.uidCount}})
|
||||
</view>
|
||||
<view class="tag {{commentType === '4' ? 'active' : ''}}">
|
||||
带图({{countObj.hasImageCount}})
|
||||
</view>
|
||||
<view class="tag {{commentType === '3' ? 'active' : ''}}">
|
||||
好评({{countObj.goodCount}})
|
||||
</view>
|
||||
<view class="tag {{commentType === '2' ? 'active' : ''}}">
|
||||
中评({{countObj.middleCount}})
|
||||
</view>
|
||||
<view class="tag {{commentType === '1' ? 'active' : ''}}">
|
||||
差评({{countObj.badCount}})
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="stats-detail">
|
||||
<text class="section-title">详细统计数据:</text>
|
||||
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">总评论数:</text>
|
||||
<text class="stat-value">{{countObj.commentCount}}</text>
|
||||
</view>
|
||||
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">好评数:</text>
|
||||
<text class="stat-value">{{countObj.goodCount}}</text>
|
||||
</view>
|
||||
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">中评数:</text>
|
||||
<text class="stat-value">{{countObj.middleCount}}</text>
|
||||
</view>
|
||||
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">差评数:</text>
|
||||
<text class="stat-value">{{countObj.badCount}}</text>
|
||||
</view>
|
||||
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">带图评论数:</text>
|
||||
<text class="stat-value">{{countObj.hasImageCount}}</text>
|
||||
</view>
|
||||
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">我的评论数:</text>
|
||||
<text class="stat-value">{{countObj.uidCount}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
118
miniprogram/pages/test-comment-stats/index.wxss
Normal file
118
miniprogram/pages/test-comment-stats/index.wxss
Normal file
@@ -0,0 +1,118 @@
|
||||
.container {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.input-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 40rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 10rpx;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
margin-right: 20rpx;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
padding: 10rpx 20rpx;
|
||||
border: 1rpx solid #ddd;
|
||||
border-radius: 5rpx;
|
||||
font-size: 28rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
background-color: #007aff;
|
||||
color: white;
|
||||
border-radius: 5rpx;
|
||||
padding: 10rpx 20rpx;
|
||||
font-size: 24rpx;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.refresh-btn[disabled] {
|
||||
background-color: #ccc;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #ff3b30;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.comments-header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10rpx;
|
||||
margin-bottom: 40rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 10rpx;
|
||||
}
|
||||
|
||||
.tag {
|
||||
padding: 10rpx 20rpx;
|
||||
background-color: #fff;
|
||||
border: 1rpx solid #ddd;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.tag.active {
|
||||
background-color: #007aff;
|
||||
color: white;
|
||||
border-color: #007aff;
|
||||
}
|
||||
|
||||
.stats-detail {
|
||||
border-top: 1rpx solid #eee;
|
||||
padding-top: 20rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
display: block;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15rpx 0;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
Reference in New Issue
Block a user