diff --git a/ruoyi-ui/src/views/playlist/normal/index.vue b/ruoyi-ui/src/views/playlist/normal/index.vue index a0fa520..39c35b2 100644 --- a/ruoyi-ui/src/views/playlist/normal/index.vue +++ b/ruoyi-ui/src/views/playlist/normal/index.vue @@ -21,7 +21,7 @@ - + @@ -70,7 +70,7 @@ v-if="scope.row.musicAddr" type="primary" :underline="false" - @click="downloadMusic(scope.row.musicAddr, scope.row.name)" + @click="downloadMusic(scope.row.musicAddr, scope.row.name, scope.row.musicId)" > 下载 @@ -151,7 +151,7 @@ - + @@ -196,7 +196,7 @@ 下载当前音乐文件 @@ -221,6 +221,7 @@ import { listNormalSong, getNormalSong, delNormalSong, addNormalSong, updateNormalSong } from "@/api/playlist/normal"; import { listTags } from "@/api/playlist/tag"; import { getImageUrl } from "@/utils/image"; +import request from '@/utils/request'; export default { name: "Normal", @@ -309,7 +310,7 @@ export default { musicId: null, name: null, author: null, - vip: 0, + vip: 2, shelf: 1, imgAddr: null, musicAddr: null, @@ -405,28 +406,79 @@ export default { }).catch(() => {}); }, // 下载音乐文件 - downloadMusic(musicAddr, musicName) { + downloadMusic(musicAddr, musicName, musicId) { if (!musicAddr) { this.$modal.msgError("音乐文件地址为空,无法下载"); return; } - // 构建完整的下载URL + // 构建下载URL,直接使用相对路径,让request自动处理baseUrl let downloadUrl = musicAddr; - if (!musicAddr.startsWith('http://') && !musicAddr.startsWith('https://')) { - downloadUrl = process.env.VUE_APP_BASE_API + musicAddr; + + // 拼接musicId参数 + if (!downloadUrl.includes('?')) { + downloadUrl += '?musicId=' + musicId; + } else { + downloadUrl += '&musicId=' + musicId; } - // 创建下载链接 - const link = document.createElement('a'); - link.href = downloadUrl; - link.download = musicName || 'music'; - link.target = '_blank'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); + // 构建完整的URL + if (!musicAddr.startsWith('http://') && !musicAddr.startsWith('https://')) { + downloadUrl = process.env.VUE_APP_BASE_API + downloadUrl; + } - this.$modal.msgSuccess(`正在下载音乐: ${musicName || '未知文件'}`); + // 使用fetch API下载文件,确保正确处理二进制数据 + this.$message.info("正在下载音乐文件..."); + + fetch(downloadUrl, { + method: 'GET', + headers: { + 'Authorization': 'Bearer ' + this.$store.getters.token + } + }) + .then(response => { + if (!response.ok) { + throw new Error('下载失败'); + } + return response.blob(); + }) + .then(blob => { + + // 从URL中提取文件扩展名 + let fileExtension = ''; + if (musicAddr) { + const urlParts = musicAddr.split('.'); + if (urlParts.length > 1) { + fileExtension = '.' + urlParts[urlParts.length - 1].split('?')[0]; // 移除查询参数 + } + } + + // 如果没有扩展名,默认使用.mp3 + if (!fileExtension || fileExtension === '.') { + fileExtension = '.mp3'; + } + + // 构建下载文件名 + const downloadFileName = (musicName || 'music') + fileExtension; + + // 创建下载链接 + const url = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.download = downloadFileName; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // 释放URL对象 + window.URL.revokeObjectURL(url); + + this.$modal.msgSuccess(`音乐文件下载完成: ${downloadFileName}`); + }) + .catch(error => { + console.error('下载失败:', error); + this.$modal.msgError("下载失败,请重试"); + }); } } }; diff --git a/ruoyi-ui/src/views/playlist/remix/index.vue b/ruoyi-ui/src/views/playlist/remix/index.vue index d1ca500..be357e7 100644 --- a/ruoyi-ui/src/views/playlist/remix/index.vue +++ b/ruoyi-ui/src/views/playlist/remix/index.vue @@ -127,7 +127,7 @@ - + @@ -324,7 +324,7 @@ export default { { label: '上架', value: 1 } ], permissionOptions: [ - { label: '免费', value: 0 }, + { label: '免费', value: 2 }, { label: 'VIP', value: 1 } ], selectedMusicInfo: null, // 用于存储选中的音乐信息 @@ -453,25 +453,22 @@ export default { this.open = false; this.reset(); }, + // 表单重置 reset() { this.form = { id: null, musicId: null, name: null, author: null, - vip: 0, + vip: 2, shelf: 1, imgAddr: null, musicType: "mixing", label: null, - musicScenes: null, - musicScene: { - sceneIds: "" - } + musicScenes: null }; this.selectedTags = []; - this.selectedScenes = []; - this.selectedMusicInfo = null; // 清空选中的音乐信息 + this.selectedMusicInfo = null; this.resetForm("form"); }, handleQuery() { diff --git a/ruoyi-ui/src/views/playlist/scene/index.vue b/ruoyi-ui/src/views/playlist/scene/index.vue index 2a7181d..b08a1dc 100644 --- a/ruoyi-ui/src/views/playlist/scene/index.vue +++ b/ruoyi-ui/src/views/playlist/scene/index.vue @@ -37,7 +37,14 @@ @@ -103,6 +110,7 @@