feat: show author follower count on post cards

This commit is contained in:
hajimi
2026-08-02 19:59:58 +08:00
parent 883b3143d5
commit 115a859dd3
2 changed files with 35 additions and 2 deletions
@@ -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'))));
@@ -11,6 +11,7 @@
<view class="post-card__author">
<view class="post-card__identity">
<text class="post-card__nickname">{{ post.user?.nickname || '匿名用户' }}</text>
<text v-if="post.user?.id" class="post-card__follow-count">关注 {{ formatCount(post.user.fans_count) }}</text>
<text v-if="post.is_top" class="post-card__pin">置顶</text>
</view>
<text class="post-card__time">{{ formatTime(post.create_time) }}</text>
@@ -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 {