From 0665f53f0d913d65c4bdd85b99c462b98ea1c6d8 Mon Sep 17 00:00:00 2001 From: qier222 Date: Tue, 5 Jan 2021 22:18:19 +0800 Subject: [PATCH] fix: update Next Up page --- src/views/next.vue | 83 ++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/src/views/next.vue b/src/views/next.vue index 045c22d..e9fd087 100644 --- a/src/views/next.vue +++ b/src/views/next.vue @@ -3,14 +3,23 @@

{{ $t("next.nowPlaying") }}

+

插队播放

+

{{ $t("next.nextUp") }}

- @@ -39,20 +48,20 @@ export default { playerShuffle() { return this.player.shuffle; }, - sortedTracks() { - function compare(property) { - return function (obj1, obj2) { - var value1 = obj1[property]; - var value2 = obj2[property]; - return value1 - value2; - }; - } - return this.tracks - .filter( - (t) => this.player.list.find((t2) => t2.id === t.id) !== undefined - ) - .filter((t) => t.sort > this.player.currentTrack.sort) - .sort(compare("sort")); + filteredTracks() { + let trackIDs = this.player.list.slice( + this.player.current + 1, + this.player.current + 100 + ); + return this.tracks.filter((t) => trackIDs.includes(t.id)); + }, + playNextList() { + return this.player.playNextList; + }, + playNextTracks() { + return this.playNextList.map((tid) => { + return this.tracks.find((t) => t.id === tid); + }); }, }, watch: { @@ -60,36 +69,35 @@ export default { this.loadTracks(); }, playerShuffle() { - this.tracks = this.tracks.map((t) => { - t.sort = this.player.list.find((t2) => t.id === t2.id).sort; - return t; - }); + this.loadTracks(); + }, + playNextList() { + this.loadTracks(); }, }, methods: { ...mapActions(["playTrackOnListByID"]), loadTracks() { - console.time("loadTracks"); + // 获取播放列表当前歌曲后100首歌 + let trackIDs = this.player.list.slice( + this.player.current + 1, + this.player.current + 100 + ); + + // 将playNextList的歌曲加进trackIDs + trackIDs.push(...this.playNextList); + + // 获取已经加载了的歌曲 let loadedTrackIDs = this.tracks.map((t) => t.id); - let basicTracks = this.player.list - .filter( - (t) => - t.sort > this.player.currentTrack.sort && - t.sort <= this.player.currentTrack.sort + 100 - ) - .filter((t) => loadedTrackIDs.includes(t.id) === false); - let trackIDs = basicTracks.map((t) => t.id); if (trackIDs.length > 0) { getTrackDetail(trackIDs.join(",")).then((data) => { - let newTracks = data.songs.map((t) => { - t.sort = this.player.list.find((t2) => t2.id == t.id).sort; - return t; - }); + let newTracks = data.songs.filter( + (t) => !loadedTrackIDs.includes(t.id) + ); this.tracks.push(...newTracks); }); } - console.timeEnd("loadTracks"); }, }, activated() { @@ -99,9 +107,6 @@ export default {