feat(playlist): 优化歌单详情页面加载逻辑
- 将评论获取移至歌单详情获取成功后 - 添加评论数到歌单 DTO - 优化前端歌单详情展示
This commit is contained in:
@@ -75,6 +75,9 @@ public class PlaylistServiceImpl implements PlaylistService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PlayHistoryRepository playHistoryRepository;
|
private PlayHistoryRepository playHistoryRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommentRepository commentRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileService fileService;
|
private FileService fileService;
|
||||||
|
|
||||||
@@ -590,6 +593,10 @@ public class PlaylistServiceImpl implements PlaylistService {
|
|||||||
playlistDTO.setSongCount(0);
|
playlistDTO.setSongCount(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置评论数 (targetType=2 代表歌单)
|
||||||
|
long commentCount = commentRepository.countByTargetIdAndTargetType(playlist.getId(), 2);
|
||||||
|
playlistDTO.setCommentCount((int) commentCount);
|
||||||
|
|
||||||
// 检查当前登录用户是否已收藏该歌单
|
// 检查当前登录用户是否已收藏该歌单
|
||||||
if (StpUtil.isLogin()) {
|
if (StpUtil.isLogin()) {
|
||||||
Long userId = StpUtil.getLoginIdAsLong();
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ const fetchPlaylistDetail = async () => {
|
|||||||
|
|
||||||
// 更新歌单内歌曲的状态
|
// 更新歌单内歌曲的状态
|
||||||
updateMusicStatuses(playlist.value.songs)
|
updateMusicStatuses(playlist.value.songs)
|
||||||
|
|
||||||
|
// 获取评论
|
||||||
|
fetchComments()
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(res.message || '获取歌单详情失败')
|
ElMessage.error(res.message || '获取歌单详情失败')
|
||||||
}
|
}
|
||||||
@@ -474,7 +477,6 @@ let commentSubscription = null;
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchPlaylistDetail()
|
fetchPlaylistDetail()
|
||||||
fetchComments()
|
|
||||||
|
|
||||||
// 连接 WebSocket 并订阅评论
|
// 连接 WebSocket 并订阅评论
|
||||||
connect(() => {
|
connect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user