diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..34f66ab Binary files /dev/null and b/.DS_Store differ diff --git a/assets/.DS_Store b/assets/.DS_Store new file mode 100644 index 0000000..0f06a84 Binary files /dev/null and b/assets/.DS_Store differ diff --git a/pages/community/index.js b/pages/community/index.js index 63aa8d4..f11744a 100644 --- a/pages/community/index.js +++ b/pages/community/index.js @@ -81,6 +81,15 @@ Page({ const publisher = item.publisher || {}; const avatarObj = publisher.avatar || {}; + // 从 likeList 提取所有点赞者名字,当前用户显示"我" + const app = getApp(); + const myId = (app.globalData.userInfo || {}).id; + const likeNames = (item.likeList || []).map(like => { + const liker = like.liker || {}; + if (myId && liker.id === myId) return '我'; + return liker.nickName || liker.name || '花友'; + }); + return { id: item.id, user: publisher.nickName || publisher.name || '花友', @@ -89,7 +98,7 @@ Page({ images: (item.imgList || []).map(img => img.url), location: item.location || '', time: item.createdAtStr || '刚刚', - likes: item.hasLiked === 1 ? ['我'] : [], + likes: likeNames, comments: (item.commentList || []).map(c => ({ id: c.id, user: c.commentator ? (c.commentator.nickName || c.commentator.name) : '花友', @@ -180,10 +189,13 @@ Page({ const updatedPosts = this.data.posts.map(p => { if (p.id === postId) { const liked = !p.likedByMe; + const updatedLikes = liked + ? (p.likes.includes('我') ? p.likes : [...p.likes, '我']) + : p.likes.filter(n => n !== '我'); return { ...p, likedByMe: liked, - likes: liked ? ['我'] : [] + likes: updatedLikes }; } return p;