feat(singer): 添加歌手评论数和收藏数功能

- 在 SingerDetail.vue 中添加评论数和收藏数的格式化计算属性
- 更新后端 SingerServiceImpl 类,添加评论数和收藏数的查询逻辑
- 在前端页面中使用格式化的评论数和收藏数
This commit is contained in:
ikmkj
2025-07-29 00:06:48 +08:00
parent 28a5f451ca
commit 331245f8e6
2 changed files with 37 additions and 6 deletions

View File

@@ -125,6 +125,9 @@ const fetchComments = async () => {
const res = await getCommentList(singerId.value, 3, 1, 20) // targetType 3 表示歌手
if (res.code === 200) {
comments.value = res.data.list || res.data.records || []
if (singer.value && res.data.total !== undefined) {
singer.value.commentCount = res.data.total
}
// 处理用户头像
comments.value.forEach(comment => {
@@ -393,6 +396,28 @@ const formatTime = (seconds) => {
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
}
// 格式化评论数
const formattedCommentCount = computed(() => {
if (!singer.value || singer.value.commentCount === undefined) {
return 0;
}
if (singer.value.commentCount > 99) {
return '99+';
}
return singer.value.commentCount;
});
// 格式化收藏数
const formattedCollectCount = computed(() => {
if (!singer.value || singer.value.collectCount === undefined) {
return 0;
}
if (singer.value.collectCount > 99) {
return '99+';
}
return singer.value.collectCount;
});
// 格式化粉丝数
const formatFans = (count) => {
if (count < 10000) {
@@ -477,11 +502,11 @@ onUnmounted(() => {
<div class="stat-label">粉丝数</div>
</div>
<div class="stat-item">
<div class="stat-value">{{ singer.collectCount || 0 }}</div>
<div class="stat-value">{{ formattedCollectCount }}</div>
<div class="stat-label">收藏数</div>
</div>
<div class="stat-item">
<div class="stat-value">{{ singer.commentCount || 0 }}</div>
<div class="stat-value">{{ formattedCommentCount }}</div>
<div class="stat-label">评论数</div>
</div>
</div>
@@ -517,7 +542,7 @@ onUnmounted(() => {
<el-tab-pane :label="`评论(${singer.commentCount || 0})`">
<el-tab-pane :label="`评论(${formattedCommentCount})`">
<!-- 评论输入框 -->
<div class="comment-input">
<el-input