From 4fcc6d2aff96b37f5989e849d8597bfec1475c5c Mon Sep 17 00:00:00 2001 From: qier222 <68148142+qier222@users.noreply.github.com> Date: Wed, 21 Oct 2020 00:32:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=92=AD=E6=94=BEVIP?= =?UTF-8?q?=E6=AD=8C=E6=9B=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/actions.js | 48 +++++++++++++++++++++++++------------------- src/utils/common.js | 19 ++++++++++++------ 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/store/actions.js b/src/store/actions.js index 753fb5f..047886f 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,9 +1,10 @@ import { updateMediaSessionMetaData } from "@/utils/mediaSession"; -import { getTrackDetail, scrobble } from "@/api/track"; +import { getTrackDetail, scrobble, getMP3 } from "@/api/track"; +import { isLoggedIn } from "@/utils/auth"; export default { switchTrack({ state, dispatch, commit }, basicTrack) { - getTrackDetail(basicTrack.id).then((data) => { + getTrackDetail(basicTrack.id).then(data => { let track = data.songs[0]; track.sort = basicTrack.sort; @@ -11,9 +12,7 @@ export default { scrobble({ id: state.player.currentTrack.id, sourceid: state.player.listInfo.id, - time: time === 0 ? 180 : time, - }).then((data) => { - console.log("scrobble", data); + time: time === 0 ? 180 : time }); commit("updateCurrentTrack", track); @@ -25,36 +24,43 @@ export default { return; } - commit( - "replaceMP3", - `https://music.163.com/song/media/outer/url?id=${track.id}` - ); - state.howler.once("end", () => { - dispatch("nextTrack"); - }); + function commitMP3(mp3) { + commit("replaceMP3", mp3); + state.howler.once("end", () => { + dispatch("nextTrack"); + }); + } + + if (isLoggedIn) { + getMP3(track.id).then(data => { + commitMP3(data.data[0].url); + }); + } else { + commitMP3(`https://music.163.com/song/media/outer/url?id=${track.id}`); + } }); }, playFirstTrackOnList({ state, dispatch }) { dispatch( "switchTrack", - state.player.list.find((t) => t.sort === 0) + state.player.list.find(t => t.sort === 0) ); }, playTrackOnListByID({ state, commit, dispatch }, trackID) { - let track = state.player.list.find((t) => t.id === trackID); + let track = state.player.list.find(t => t.id === trackID); dispatch("switchTrack", track); if (state.player.shuffle) { // 当随机模式开启时,双击列表的一首歌进行播放,此时要把这首歌的sort调到第一(0),这样用户就能随机播放完整的歌单 - let otherTrack = state.player.list.find((t) => t.sort === 0); + let otherTrack = state.player.list.find(t => t.sort === 0); commit("switchSortBetweenTwoTracks", { trackID1: track.id, - trackID2: otherTrack.id, + trackID2: otherTrack.id }); } }, nextTrack({ state, dispatch }, realNext = false) { let nextTrack = state.player.list.find( - (track) => track.sort === state.player.currentTrack.sort + 1 + track => track.sort === state.player.currentTrack.sort + 1 ); if (state.player.repeat === "one" && realNext === false) { @@ -63,7 +69,7 @@ export default { if (nextTrack === undefined) { if (state.player.repeat !== "off") { - nextTrack = state.player.list.find((t) => t.sort === 0); + nextTrack = state.player.list.find(t => t.sort === 0); } else { return; } @@ -73,13 +79,13 @@ export default { }, previousTrack({ state, dispatch }) { let previousTrack = state.player.list.find( - (track) => track.sort === state.player.currentTrack.sort - 1 + track => track.sort === state.player.currentTrack.sort - 1 ); if (previousTrack == undefined) { if (state.player.repeat !== "off") { previousTrack = state.player.list.reduce((x, y) => (x > y ? x : y)); } else { - previousTrack = state.player.list.find((t) => t.sort === 0); + previousTrack = state.player.list.find(t => t.sort === 0); } } dispatch("switchTrack", previousTrack); @@ -88,5 +94,5 @@ export default { state.howler.once("end", () => { dispatch("nextTrack"); }); - }, + } }; diff --git a/src/utils/common.js b/src/utils/common.js index 7b92ac6..96a2bcb 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -1,11 +1,18 @@ +import { isLoggedIn } from "./auth"; +import store from "@/store"; + export function isTrackPlayable(track) { let result = { playable: true, - reason: "", + reason: "" }; if (track.fee === 1 || track.privilege?.fee === 1) { - result.playable = false; - result.reason = "VIP Only"; + if (isLoggedIn && store.state.settings.user.vipType === 11) { + result.playable = true; + } else { + result.playable = false; + result.reason = "VIP Only"; + } } else if (track.fee === 4 || track.privilege?.fee === 4) { result.playable = false; result.reason = "Paid Album"; @@ -20,7 +27,7 @@ export function isTrackPlayable(track) { } export function mapTrackPlayableStatus(tracks) { - return tracks.map((t) => { + return tracks.map(t => { let result = isTrackPlayable(t); t.playable = result.playable; t.reason = result.reason; @@ -40,13 +47,13 @@ export function randomNum(minNum, maxNum) { } export function shuffleAList(list) { - let sortsList = list.map((t) => t.sort); + let sortsList = list.map(t => t.sort); for (let i = 1; i < sortsList.length; i++) { const random = Math.floor(Math.random() * (i + 1)); [sortsList[i], sortsList[random]] = [sortsList[random], sortsList[i]]; } let newSorts = {}; - list.map((track) => { + list.map(track => { newSorts[track.id] = sortsList.pop(); }); return newSorts;