feat: 修改post点赞显示
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -81,6 +81,15 @@ Page({
|
|||||||
const publisher = item.publisher || {};
|
const publisher = item.publisher || {};
|
||||||
const avatarObj = publisher.avatar || {};
|
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 {
|
return {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
user: publisher.nickName || publisher.name || '花友',
|
user: publisher.nickName || publisher.name || '花友',
|
||||||
@@ -89,7 +98,7 @@ Page({
|
|||||||
images: (item.imgList || []).map(img => img.url),
|
images: (item.imgList || []).map(img => img.url),
|
||||||
location: item.location || '',
|
location: item.location || '',
|
||||||
time: item.createdAtStr || '刚刚',
|
time: item.createdAtStr || '刚刚',
|
||||||
likes: item.hasLiked === 1 ? ['我'] : [],
|
likes: likeNames,
|
||||||
comments: (item.commentList || []).map(c => ({
|
comments: (item.commentList || []).map(c => ({
|
||||||
id: c.id,
|
id: c.id,
|
||||||
user: c.commentator ? (c.commentator.nickName || c.commentator.name) : '花友',
|
user: c.commentator ? (c.commentator.nickName || c.commentator.name) : '花友',
|
||||||
@@ -180,10 +189,13 @@ Page({
|
|||||||
const updatedPosts = this.data.posts.map(p => {
|
const updatedPosts = this.data.posts.map(p => {
|
||||||
if (p.id === postId) {
|
if (p.id === postId) {
|
||||||
const liked = !p.likedByMe;
|
const liked = !p.likedByMe;
|
||||||
|
const updatedLikes = liked
|
||||||
|
? (p.likes.includes('我') ? p.likes : [...p.likes, '我'])
|
||||||
|
: p.likes.filter(n => n !== '我');
|
||||||
return {
|
return {
|
||||||
...p,
|
...p,
|
||||||
likedByMe: liked,
|
likedByMe: liked,
|
||||||
likes: liked ? ['我'] : []
|
likes: updatedLikes
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
Reference in New Issue
Block a user