From 115a859dd3809d69342aef1bd78f4d7a5d959f86 Mon Sep 17 00:00:00 2001 From: hajimi Date: Sun, 2 Aug 2026 19:59:58 +0800 Subject: [PATCH] feat: show author follower count on post cards --- .../lists/community/CommunityPostLists.php | 15 +++++++++++++ .../components/post-card.vue | 22 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/server/app/api/lists/community/CommunityPostLists.php b/server/app/api/lists/community/CommunityPostLists.php index b2e7883..01da3ca 100644 --- a/server/app/api/lists/community/CommunityPostLists.php +++ b/server/app/api/lists/community/CommunityPostLists.php @@ -107,11 +107,26 @@ class CommunityPostLists extends BaseApiDataLists // 批量查询用户 → id 为 key $userMap = []; + $fansCountMap = []; if ($userIds) { $users = User::field('id,sn,nickname,avatar,sex')->whereIn('id', $userIds)->select()->toArray(); foreach ($users as $u) { $userMap[$u['id']] = $u; } + + $fansCounts = CommunityFollow::whereIn('follow_user_id', $userIds) + ->field('follow_user_id, COUNT(*) AS fans_count') + ->group('follow_user_id') + ->select() + ->toArray(); + foreach ($fansCounts as $fansCount) { + $fansCountMap[(int) $fansCount['follow_user_id']] = (int) $fansCount['fans_count']; + } + + foreach ($userMap as $userId => &$user) { + $user['fans_count'] = $fansCountMap[(int) $userId] ?? 0; + } + unset($user); } $categoryIds = array_values(array_filter(array_unique(array_column($list, 'category_id')))); diff --git a/uniapp/src/packages_community/components/post-card.vue b/uniapp/src/packages_community/components/post-card.vue index 6e4408e..5e153ec 100644 --- a/uniapp/src/packages_community/components/post-card.vue +++ b/uniapp/src/packages_community/components/post-card.vue @@ -11,6 +11,7 @@ {{ post.user?.nickname || '匿名用户' }} + 置顶 {{ formatTime(post.create_time) }} @@ -248,10 +249,13 @@ const formatCount = (value: any) => { align-items: center; } - &__identity { gap: 10rpx; } + &__identity { + min-width: 0; + gap: 9rpx; + } &__nickname { - max-width: 250rpx; + max-width: 220rpx; overflow: hidden; color: #202a3b; font-size: 29rpx; @@ -260,6 +264,20 @@ const formatCount = (value: any) => { white-space: nowrap; } + &__follow-count { + min-width: 0; + padding: 5rpx 14rpx; + border-radius: 999rpx; + color: #fff; + font-size: 20rpx; + font-weight: 600; + line-height: 1.1; + white-space: nowrap; + background: linear-gradient(135deg, #2480ff 0%, #0d63ed 100%); + box-shadow: 0 4rpx 10rpx rgba(20, 104, 245, 0.2); + flex-shrink: 0; + } + &__pin, &__free, &__price {