|
|
|
|
@ -50,15 +50,32 @@ Page({
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化加载数据
|
|
|
|
|
this.initializeData();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
|
// 每次页面显示时重新加载糖友圈预览数据
|
|
|
|
|
const {targetUserId} = this.data;
|
|
|
|
|
if (targetUserId) {
|
|
|
|
|
console.log('页面显示,重新加载糖友圈预览数据');
|
|
|
|
|
this.loadUserPosts(targetUserId);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 初始化数据加载
|
|
|
|
|
initializeData() {
|
|
|
|
|
const {targetUserId, currentUserId, isViewingSelf} = this.data;
|
|
|
|
|
|
|
|
|
|
// 加载用户资料
|
|
|
|
|
this.loadUserProfile(userId);
|
|
|
|
|
this.loadUserProfile(targetUserId);
|
|
|
|
|
|
|
|
|
|
// 加载用户帖子
|
|
|
|
|
this.loadUserPosts(userId);
|
|
|
|
|
this.loadUserPosts(targetUserId);
|
|
|
|
|
|
|
|
|
|
// 只有在查看他人页面时才检查关注状态
|
|
|
|
|
if (this.data.currentUserId && !this.data.isViewingSelf) {
|
|
|
|
|
this.checkFollowingStatus(userId);
|
|
|
|
|
if (currentUserId && !isViewingSelf) {
|
|
|
|
|
this.checkFollowingStatus(targetUserId);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@ -182,6 +199,8 @@ Page({
|
|
|
|
|
const currentUserId = this.data.currentUserId;
|
|
|
|
|
const isViewingSelf = this.data.isViewingSelf;
|
|
|
|
|
|
|
|
|
|
console.log('重新加载用户帖子,目标用户ID:', targetUserId);
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
url: `${API_BASE_URL}/api/circle/posts`,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
@ -190,7 +209,8 @@ Page({
|
|
|
|
|
size: 6, // 只获取前6条用于预览
|
|
|
|
|
userId: currentUserId, // 当前用户ID,用于判断点赞状态
|
|
|
|
|
authorId: targetUserId, // 目标用户ID,只获取他的帖子
|
|
|
|
|
isViewingSelf: isViewingSelf // 是否查看自己的帖子
|
|
|
|
|
isViewingSelf: isViewingSelf, // 是否查看自己的帖子
|
|
|
|
|
timestamp: Date.now() // 添加时间戳避免缓存
|
|
|
|
|
},
|
|
|
|
|
success: (res) => {
|
|
|
|
|
console.log('获取用户帖子列表:', res.data);
|
|
|
|
|
@ -209,6 +229,8 @@ Page({
|
|
|
|
|
'statistics.posts': totalPosts
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log('糖友圈预览数据已更新,帖子数量:', feedList.length);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
console.error('获取帖子失败:', res.data.message);
|
|
|
|
|
// 如果获取失败,使用空数组
|
|
|
|
|
@ -511,8 +533,10 @@ Page({
|
|
|
|
|
refreshData() {
|
|
|
|
|
const {targetUserId} = this.data;
|
|
|
|
|
if (targetUserId) {
|
|
|
|
|
console.log('手动刷新页面数据');
|
|
|
|
|
this.loadUserProfile(targetUserId);
|
|
|
|
|
if (this.data.currentUserId) {
|
|
|
|
|
this.loadUserPosts(targetUserId); // 确保重新加载帖子数据
|
|
|
|
|
if (this.data.currentUserId && !this.data.isViewingSelf) {
|
|
|
|
|
this.checkFollowingStatus(targetUserId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|