feat(user): 为收藏音乐页面添加更多操作功能
- 添加下拉菜单,支持多种操作 - 实现添加到播放列表、下一首播放、下载音乐、下载歌词等功能 - 优化用户交互,增加确认对话框和提示消息
This commit is contained in:
@@ -99,6 +99,56 @@ const playAll = () => {
|
||||
ElMessage.success('开始播放全部收藏音乐')
|
||||
}
|
||||
|
||||
// 处理下拉菜单命令
|
||||
const handleCommand = (command, music) => {
|
||||
switch (command) {
|
||||
case 'addToPlaylist':
|
||||
addToPlaylist(music)
|
||||
break
|
||||
case 'playNext':
|
||||
const currentIndex = playerStore.getCurrentIndex
|
||||
if (currentIndex !== -1) {
|
||||
const playlist = [...playerStore.getPlaylist]
|
||||
const existingIndex = playlist.findIndex(item => item.id === music.id)
|
||||
if (existingIndex !== -1) {
|
||||
playlist.splice(existingIndex, 1)
|
||||
}
|
||||
playlist.splice(currentIndex + 1, 0, music)
|
||||
playerStore.$patch({ playlist })
|
||||
ElMessage.success('已添加到下一首播放')
|
||||
} else {
|
||||
playerStore.addToPlaylist(music)
|
||||
ElMessage.success('已添加到播放列表')
|
||||
}
|
||||
break
|
||||
case 'downloadMusic':
|
||||
downloadFile('music', music)
|
||||
break
|
||||
case 'downloadLyric':
|
||||
downloadFile('lyric', music)
|
||||
break
|
||||
case 'cancelCollect':
|
||||
cancelCollect(music.id)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
const downloadFile = (type, music) => {
|
||||
const typeName = type === 'music' ? '音乐' : '歌词'
|
||||
ElMessageBox.confirm(`确定要下载《${music.name}》的${typeName}吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'info'
|
||||
}).then(() => {
|
||||
const url = `/api/file/download/${type}/${music.id}`
|
||||
window.open(url, '_blank')
|
||||
ElMessage.success(`${typeName}开始下载...`)
|
||||
}).catch(() => {
|
||||
ElMessage.info(`已取消下载${typeName}`)
|
||||
})
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (seconds) => {
|
||||
const mins = Math.floor(seconds / 60)
|
||||
@@ -167,20 +217,20 @@ onMounted(() => {
|
||||
|
||||
<el-table-column label="操作" width="150" align="center">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
icon="Delete"
|
||||
circle
|
||||
size="small"
|
||||
type="danger"
|
||||
@click="cancelCollect(scope.row.id)"
|
||||
></el-button>
|
||||
|
||||
<el-button
|
||||
icon="Plus"
|
||||
circle
|
||||
size="small"
|
||||
@click="addToPlaylist(scope.row)"
|
||||
></el-button>
|
||||
<el-dropdown trigger="click" @command="handleCommand($event, scope.row)">
|
||||
<el-button circle size="small">
|
||||
<el-icon><More /></el-icon>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="addToPlaylist">添加到播放列表</el-dropdown-item>
|
||||
<el-dropdown-item command="playNext">下一首播放</el-dropdown-item>
|
||||
<el-dropdown-item command="downloadMusic">下载音乐</el-dropdown-item>
|
||||
<el-dropdown-item command="downloadLyric">下载歌词</el-dropdown-item>
|
||||
<el-dropdown-item command="cancelCollect" divided>取消收藏</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
Reference in New Issue
Block a user