From d1a080eb8fb9a5475a7194fb5936d253e3090d63 Mon Sep 17 00:00:00 2001 From: qier222 Date: Thu, 17 Dec 2020 18:18:19 +0800 Subject: [PATCH] feat: create/delete playlist, add/remove track from playlist --- src/App.vue | 14 ++ src/api/playlist.js | 22 ++- src/components/ModalAddTrackToPlaylist.vue | 181 +++++++++++++++++++++ src/components/ModalNewPlaylist.vue | 144 ++++++++++++++++ src/components/TrackList.vue | 49 +++++- src/store/mutations.js | 3 + src/store/state.js | 10 ++ src/views/library.vue | 113 +++---------- src/views/playlist.vue | 27 ++- 9 files changed, 466 insertions(+), 97 deletions(-) create mode 100644 src/components/ModalAddTrackToPlaylist.vue create mode 100644 src/components/ModalNewPlaylist.vue diff --git a/src/App.vue b/src/App.vue index 39ecdc2..609437c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -19,10 +19,14 @@ /> + + + + diff --git a/src/components/ModalNewPlaylist.vue b/src/components/ModalNewPlaylist.vue new file mode 100644 index 0000000..2dbccaa --- /dev/null +++ b/src/components/ModalNewPlaylist.vue @@ -0,0 +1,144 @@ + + + + + diff --git a/src/components/TrackList.vue b/src/components/TrackList.vue index 49302df..1fcc25d 100644 --- a/src/components/TrackList.vue +++ b/src/components/TrackList.vue @@ -17,6 +17,13 @@
{{ $t("contextMenu.removeFromMyLikedSongs") }}
+
添加到歌单
+
从歌单中删除
{ + return []; // 'removeTrackFromPlaylist' + }, + }, }, data() { return { @@ -93,7 +107,7 @@ export default { }, }, methods: { - ...mapMutations(["updateLikedSongs"]), + ...mapMutations(["updateLikedSongs", "updateModal"]), ...mapActions(["nextTrack", "playTrackOnListByID", "showToast"]), openMenu(e, track) { if (!track.playable) { @@ -160,6 +174,39 @@ export default { } }); }, + addTrackToPlaylist() { + if (!isAccountLoggedIn()) { + this.showToast("此操作需要登录网易云账号"); + return; + } + this.updateModal({ + modalName: "addTrackToPlaylistModal", + key: "show", + value: true, + }); + this.updateModal({ + modalName: "addTrackToPlaylistModal", + key: "selectedTrackID", + value: this.rightClickedTrack.id, + }); + }, + removeTrackFromPlaylist() { + if (!isAccountLoggedIn()) { + this.showToast("此操作需要登录网易云账号"); + return; + } + let trackID = this.rightClickedTrack.id; + addOrRemoveTrackFromPlaylist({ + op: "del", + pid: this.id, + tracks: trackID, + }).then((data) => { + this.showToast( + data.body.code === 200 ? "已从歌单中删除" : data.body.message + ); + this.$parent.removeTrack(trackID); + }); + }, }, }; diff --git a/src/store/mutations.js b/src/store/mutations.js index 0c56d6a..a35e1c7 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -123,4 +123,7 @@ export default { updateToast(state, toast) { state.toast = toast; }, + updateModal(state, { modalName, key, value }) { + state.modals[modalName][key] = value; + }, }; diff --git a/src/store/state.js b/src/store/state.js index 00d1202..5dfd635 100644 --- a/src/store/state.js +++ b/src/store/state.js @@ -12,6 +12,16 @@ export default { text: "", timer: null, }, + modals: { + addTrackToPlaylistModal: { + show: false, + selectedTrackID: 0, + }, + newPlaylistModal: { + show: false, + afterCreateAddTrackID: 0, + }, + }, player: JSON.parse(localStorage.getItem("player")), settings: JSON.parse(localStorage.getItem("settings")), data: JSON.parse(localStorage.getItem("data")), diff --git a/src/views/library.vue b/src/views/library.vue index 3379de4..2afcf28 100644 --- a/src/views/library.vue +++ b/src/views/library.vue @@ -76,7 +76,7 @@ class="add-playlist" icon="plus" v-show="currentTab === 'playlists'" - @click="showAddPlaylistModal = true" + @click="openAddPlaylistModal" >新建歌单 @@ -109,39 +109,11 @@ - - - - -