diff --git a/music-qianduan/src/views/user/Playlist.vue b/music-qianduan/src/views/user/Playlist.vue index af3fd34..bd77bf5 100644 --- a/music-qianduan/src/views/user/Playlist.vue +++ b/music-qianduan/src/views/user/Playlist.vue @@ -34,7 +34,8 @@ const createForm = reactive({ const editForm = reactive({ id: null, name: '', - description: '' + description: '', + coverFile: null }) // 表单规则 @@ -52,14 +53,6 @@ const formRules = { const createFormRef = ref(null) const editFormRef = ref(null) -// 头像上传URL -const coverUploadUrl = ref(`${import.meta.env.VITE_API_BASE_URL || ''}/api/file/upload/image`) - -// 头像上传headers -const uploadHeaders = ref({ - [userStore.tokenName]: userStore.token -}) - // 获取自建歌单列表 const fetchUserPlaylists = async () => { loading.value = true @@ -107,6 +100,8 @@ const openEditDialog = (playlist) => { editForm.id = playlist.id editForm.name = playlist.name editForm.description = playlist.description + editForm.coverFile = null + coverPreview.value = playlist.cover editDialogVisible.value = true } @@ -144,7 +139,7 @@ const handleUpdatePlaylist = () => { const res = await updatePlaylist(editForm.id, { name: editForm.name, description: editForm.description - }) + }, editForm.coverFile) if (res.code === 200) { // 更新成功,重新获取歌单列表 @@ -185,33 +180,13 @@ const handleDeletePlaylist = (id) => { }).catch(() => {}) } -// 封面上传成功 -const handleCoverSuccess = async (response) => { - if (response.code === 200) { - // 上传成功,获取图片URL - const imageUrl = response.data +// 封面预览URL +const coverPreview = ref('') - try { - // 更新歌单封面 - const res = await updatePlaylist(currentPlaylist.value.id, { - ...editForm, - cover: imageUrl - }) - - if (res.code === 200) { - // 更新成功,重新获取歌单列表 - await fetchUserPlaylists() - ElMessage.success('封面上传成功') - } else { - ElMessage.error(res.message || '更新歌单封面失败') - } - } catch (error) { - console.error('更新歌单封面失败:', error) - ElMessage.error('更新歌单封面失败') - } - } else { - ElMessage.error(response.message || '封面上传失败') - } +// 封面选择处理(不自动上传,仅本地预览) +const handleCoverChange = (file) => { + editForm.coverFile = file.raw + coverPreview.value = URL.createObjectURL(file.raw) } // 封面上传前的处理 @@ -354,15 +329,15 @@ onMounted(() => {