init
This commit is contained in:
134
miniprogram/pages/test-my-comments/index.js
Normal file
134
miniprogram/pages/test-my-comments/index.js
Normal file
@@ -0,0 +1,134 @@
|
||||
// 测试我的评论列表功能
|
||||
import { fetchUserComments } from '../../services/comments/createComment';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
commentList: [],
|
||||
loading: false,
|
||||
error: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
console.log('测试页面加载');
|
||||
},
|
||||
|
||||
// 测试getMyCommentsList方法
|
||||
async testGetMyCommentsList() {
|
||||
console.log('开始测试getMyCommentsList方法');
|
||||
|
||||
this.setData({
|
||||
loading: true,
|
||||
error: null
|
||||
});
|
||||
|
||||
try {
|
||||
const data = await fetchUserComments({
|
||||
page: 1,
|
||||
pageSize: 10
|
||||
});
|
||||
|
||||
console.log('fetchUserComments返回数据:', data);
|
||||
|
||||
this.setData({
|
||||
commentList: data.list || [],
|
||||
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'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 测试changeTag方法中的getMyCommentsList调用
|
||||
testChangeTag() {
|
||||
console.log('测试changeTag方法调用getMyCommentsList');
|
||||
|
||||
// 模拟changeTag方法中的调用
|
||||
if (typeof this.getMyCommentsList === 'function') {
|
||||
console.log('getMyCommentsList方法存在,开始调用');
|
||||
this.getMyCommentsList();
|
||||
} else {
|
||||
console.error('getMyCommentsList方法不存在');
|
||||
wx.showToast({
|
||||
title: 'getMyCommentsList方法不存在',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 添加getMyCommentsList方法(从评论页面复制)
|
||||
async getMyCommentsList() {
|
||||
console.log('[测试页面] getMyCommentsList 开始');
|
||||
const { loading } = this.data;
|
||||
|
||||
// 在加载中,直接返回
|
||||
if (loading) {
|
||||
console.log('[测试页面] 跳过加载,正在加载中');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[测试页面] 设置加载状态为true');
|
||||
this.setData({
|
||||
loading: true,
|
||||
});
|
||||
|
||||
try {
|
||||
console.log('[测试页面] 开始调用fetchUserComments API...');
|
||||
const data = await fetchUserComments({
|
||||
page: 1,
|
||||
pageSize: 10
|
||||
});
|
||||
console.log('[测试页面] fetchUserComments API返回数据:', data);
|
||||
|
||||
if (data && data.list) {
|
||||
const { list, total = 0 } = data;
|
||||
|
||||
this.setData({
|
||||
commentList: list,
|
||||
loading: false,
|
||||
});
|
||||
|
||||
wx.showToast({
|
||||
title: `获取到${list.length}条评论`,
|
||||
icon: 'success'
|
||||
});
|
||||
} else {
|
||||
console.log('[测试页面] fetchUserComments API返回空结果或无list字段');
|
||||
this.setData({
|
||||
commentList: [],
|
||||
loading: false,
|
||||
});
|
||||
|
||||
wx.showToast({
|
||||
title: '暂无评论数据',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[测试页面] 获取我的评论列表失败:', error);
|
||||
wx.showToast({
|
||||
title: '获取我的评论失败',
|
||||
icon: 'none'
|
||||
});
|
||||
this.setData({
|
||||
loading: false,
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
3
miniprogram/pages/test-my-comments/index.json
Normal file
3
miniprogram/pages/test-my-comments/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
36
miniprogram/pages/test-my-comments/index.wxml
Normal file
36
miniprogram/pages/test-my-comments/index.wxml
Normal file
@@ -0,0 +1,36 @@
|
||||
<view class="container">
|
||||
<view class="header">
|
||||
<text class="title">测试我的评论列表功能</text>
|
||||
</view>
|
||||
|
||||
<view class="buttons">
|
||||
<button class="test-btn" bindtap="testGetMyCommentsList" disabled="{{loading}}">
|
||||
{{loading ? '加载中...' : '测试fetchUserComments'}}
|
||||
</button>
|
||||
|
||||
<button class="test-btn" bindtap="testChangeTag" disabled="{{loading}}">
|
||||
测试getMyCommentsList方法
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<view class="status" wx:if="{{error}}">
|
||||
<text class="error">错误: {{error}}</text>
|
||||
</view>
|
||||
|
||||
<view class="results">
|
||||
<text class="section-title">评论列表 ({{commentList.length}}条):</text>
|
||||
|
||||
<view class="comment-item" wx:for="{{commentList}}" wx:key="id">
|
||||
<view class="comment-header">
|
||||
<text class="comment-id">ID: {{item.id}}</text>
|
||||
<text class="comment-rating">评分: {{item.rating}}</text>
|
||||
</view>
|
||||
<view class="comment-content">{{item.content}}</view>
|
||||
<view class="comment-time">{{item.created_at}}</view>
|
||||
</view>
|
||||
|
||||
<view class="empty" wx:if="{{commentList.length === 0 && !loading}}">
|
||||
<text>暂无评论数据</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
99
miniprogram/pages/test-my-comments/index.wxss
Normal file
99
miniprogram/pages/test-my-comments/index.wxss
Normal file
@@ -0,0 +1,99 @@
|
||||
.container {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.test-btn {
|
||||
background-color: #007aff;
|
||||
color: white;
|
||||
border-radius: 10rpx;
|
||||
padding: 20rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.test-btn[disabled] {
|
||||
background-color: #ccc;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #ff3b30;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.results {
|
||||
border-top: 1rpx solid #eee;
|
||||
padding-top: 20rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
display: block;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.comment-item {
|
||||
border: 1rpx solid #eee;
|
||||
border-radius: 10rpx;
|
||||
padding: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.comment-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.comment-id {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.comment-rating {
|
||||
font-size: 24rpx;
|
||||
color: #ff6b35;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.comment-content {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
margin-bottom: 10rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.comment-time {
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 28rpx;
|
||||
padding: 40rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user