Files
ai_dianshang/miniprogram/pages/test-my-comments/index.js

134 lines
3.2 KiB
JavaScript
Raw Normal View History

2025-11-17 14:11:46 +08:00
// 测试我的评论列表功能
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
});
}
}
});