feat(playlist): 增加歌单收藏状态检查功能
- 新增 isPlaylistCollected 接口和相关实现 - 修改 toggleCollectPlaylist 函数,增加当前收藏状态参数 - 在前端 PlaylistDetail 组件中添加收藏状态检查逻辑 - 后端增加对应的控制层、服务层和实现类方法
This commit is contained in:
@@ -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 { getSingerById, toggleCollectSinger } from '../api/singer'
|
||||
import { getSingerById, isSingerCollected, collectSinger, uncollectSinger } from '../api/singer'
|
||||
import { getCommentList, addComment, deleteComment as apiDeleteComment } from '../api/comment'
|
||||
import { processImageUrl } from '../utils/imageUtils'
|
||||
import { processMusicUrl, getMusicBySinger, getMusicStatus } from '../api/music'
|
||||
@@ -67,8 +67,10 @@ const fetchSingerDetail = async () => {
|
||||
// 获取歌手的音乐列表
|
||||
await fetchSingerMusic()
|
||||
|
||||
// 获取收藏状态
|
||||
isCollected.value = singer.value.collected === true
|
||||
// 如果用户已登录,则检查是否收藏
|
||||
if (userStore.isLoggedIn) {
|
||||
checkIfCollected()
|
||||
}
|
||||
} else {
|
||||
ElMessage.error(res.message || '获取歌手详情失败')
|
||||
}
|
||||
@@ -80,6 +82,18 @@ const fetchSingerDetail = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否收藏
|
||||
const checkIfCollected = async () => {
|
||||
try {
|
||||
const res = await isSingerCollected(singerId.value)
|
||||
if (res.code === 200) {
|
||||
isCollected.value = res.data
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查收藏状态失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取歌手的音乐列表
|
||||
const fetchSingerMusic = async () => {
|
||||
try {
|
||||
@@ -181,7 +195,7 @@ const toggleCollect = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await toggleCollectSinger(singerId.value)
|
||||
const res = await toggleCollectSinger(singerId.value, isCollected.value)
|
||||
if (res.code === 200) {
|
||||
isCollected.value = !isCollected.value
|
||||
// 更新收藏数
|
||||
|
||||
Reference in New Issue
Block a user