feat: 修改post点赞显示

This commit is contained in:
Blizzard
2026-03-05 09:11:08 +08:00
parent a34d7df090
commit 2031e788b0
3 changed files with 14 additions and 2 deletions
+14 -2
View File
@@ -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;