feat(playlist): 增加歌单播放次数功能

- 在前端 PlaylistDetail.vue 中添加播放全部歌曲时增加播放次数的逻辑- 在后端 PlaylistServiceImpl 中实现 playPlaylist 方法,增加歌单播放次数
- 优化了播放全部歌曲的功能,包括处理播放次数增加失败的情况
This commit is contained in:
ikmkj
2025-07-28 22:33:09 +08:00
parent 01bbf8204c
commit f15a50a2c0
2 changed files with 21 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import { useRoute, useRouter } from 'vue-router'
import { usePlayerStore } from '../stores/player'
import { useUserStore } from '../stores/user'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getPlaylistById, toggleCollectPlaylist, deletePlaylist as apiDeletePlaylist, isPlaylistCollected, updatePlaylist } from '../api/playlist'
import { getPlaylistById, toggleCollectPlaylist, deletePlaylist as apiDeletePlaylist, isPlaylistCollected, updatePlaylist, playPlaylist } from '../api/playlist'
import { getMusicStatus } from '../api/music'
import { getCommentList, addComment, deleteComment as apiDeleteComment } from '../api/comment'
import { connect, subscribe, unsubscribe, disconnect } from '../utils/websocket' // 导入 WebSocket 工具
@@ -127,12 +127,25 @@ const fetchComments = async () => {
}
// 播放全部
const playAll = () => {
const playAll = async () => {
if (!playlist.value || playlist.value.songs.length === 0) {
ElMessage.warning('没有可播放的音乐')
return
}
try {
// 调用 API 增加播放次数
await playPlaylist(playlistId.value)
// 更新前端显示的播放次数
if (playlist.value) {
playlist.value.playCount++
}
} catch (error) {
console.error('增加播放次数失败:', error)
// 即使增加播放次数失败,也继续播放
}
// 清空当前播放列表
playerStore.clearPlaylist()
@@ -142,7 +155,7 @@ const playAll = () => {
})
// 播放第一首
playerStore.setCurrentMusic(playlist.value.songs[0])
playerStore.setCurrentMusic(playlist.value.songs)
ElMessage.success('开始播放全部歌曲')
}