feat(singer): 添加歌手评论数和收藏数功能
- 在 SingerDetail.vue 中添加评论数和收藏数的格式化计算属性 - 更新后端 SingerServiceImpl 类,添加评论数和收藏数的查询逻辑 - 在前端页面中使用格式化的评论数和收藏数
This commit is contained in:
@@ -12,6 +12,7 @@ import com.test.musichouduan.entity.Music;
|
||||
import com.test.musichouduan.exception.BusinessException;
|
||||
import com.test.musichouduan.repository.MusicRepository;
|
||||
import com.test.musichouduan.repository.SingerRepository;
|
||||
import com.test.musichouduan.repository.CommentRepository;
|
||||
import com.test.musichouduan.repository.SingerTypeRepository;
|
||||
import com.test.musichouduan.repository.UserRepository;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
@@ -78,6 +79,9 @@ public class SingerServiceImpl implements SingerService {
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
|
||||
@Autowired
|
||||
private CommentRepository commentRepository;
|
||||
|
||||
@Override
|
||||
public SingerDTO getSingerById(Long id) {
|
||||
Singer singer = singerRepository.findById(id)
|
||||
@@ -452,12 +456,14 @@ public class SingerServiceImpl implements SingerService {
|
||||
Long musicCount = musicRepository.countBySingersContaining(singer);
|
||||
singerDTO.setMusicCount(musicCount);
|
||||
|
||||
// // 设置粉丝数量
|
||||
// Long fansCount = userSingerRepository.count();
|
||||
// singerDTO.setFansCount(fansCount);
|
||||
// 设置粉丝数量
|
||||
Long fansCount = userSingerRepository.countBySingerId(singer.getId());
|
||||
singerDTO.setFansCount(fansCount);
|
||||
singerDTO.setCollectCount(fansCount.intValue());
|
||||
|
||||
// 设置评论数
|
||||
long commentCount = commentRepository.countByTargetIdAndTargetType(singer.getId(), 3); // 3 for singer
|
||||
singerDTO.setCommentCount((int) commentCount);
|
||||
|
||||
// 检查当前登录用户是否已收藏该歌手
|
||||
if (StpUtil.isLogin()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user