master
qier222 4 years ago
parent 603e39f362
commit 2c8ba10e20
No known key found for this signature in database
GPG Key ID: 9C85007ED905F14D

@ -46,7 +46,7 @@
<div class="like-button"> <div class="like-button">
<button-icon <button-icon
:title="$t('player.like')" :title="$t('player.like')"
@click.native="likeASong(player.currentTrack.id)" @click.native="likeATrack(player.currentTrack.id)"
> >
<svg-icon <svg-icon
v-show="!player.isCurrentTrackLiked" v-show="!player.isCurrentTrackLiked"
@ -203,7 +203,7 @@ export default {
}, },
methods: { methods: {
...mapMutations(['toggleLyrics']), ...mapMutations(['toggleLyrics']),
...mapActions(['showToast', 'likeASong']), ...mapActions(['showToast', 'likeATrack']),
goToNextTracksPage() { goToNextTracksPage() {
if (this.player.isPersonalFM) return; if (this.player.isPersonalFM) return;
this.$route.name === 'next' this.$route.name === 'next'

@ -12,10 +12,10 @@
<div class="item" @click="play">{{ $t('contextMenu.play') }}</div> <div class="item" @click="play">{{ $t('contextMenu.play') }}</div>
<div class="item" @click="playNext">{{ $t('contextMenu.playNext') }}</div> <div class="item" @click="playNext">{{ $t('contextMenu.playNext') }}</div>
<hr /> <hr />
<div class="item" @click="like" v-show="!isRightClickedTrackLiked"> <div v-show="!isRightClickedTrackLiked" class="item" @click="like">
{{ $t('contextMenu.saveToMyLikedSongs') }} {{ $t('contextMenu.saveToMyLikedSongs') }}
</div> </div>
<div class="item" @click="like" v-show="isRightClickedTrackLiked"> <div v-show="isRightClickedTrackLiked" class="item" @click="like">
{{ $t('contextMenu.removeFromMyLikedSongs') }} {{ $t('contextMenu.removeFromMyLikedSongs') }}
</div> </div>
<div <div
@ -29,9 +29,9 @@
<div :style="listStyles"> <div :style="listStyles">
<TrackListItem <TrackListItem
v-for="(track, index) in tracks" v-for="(track, index) in tracks"
:track="track"
:key="itemKey === 'id' ? track.id : `${track.id}${index}`" :key="itemKey === 'id' ? track.id : `${track.id}${index}`"
:highlightPlayingTrack="highlightPlayingTrack" :track="track"
:highlight-playing-track="highlightPlayingTrack"
@dblclick.native="playThisList(track.id)" @dblclick.native="playThisList(track.id)"
@click.right.native="openMenu($event, track)" @click.right.native="openMenu($event, track)"
/> />
@ -41,7 +41,6 @@
<script> <script>
import { mapActions, mapMutations, mapState } from 'vuex'; import { mapActions, mapMutations, mapState } from 'vuex';
import { likeATrack } from '@/api/track';
import { addOrRemoveTrackFromPlaylist } from '@/api/playlist'; import { addOrRemoveTrackFromPlaylist } from '@/api/playlist';
import { isAccountLoggedIn } from '@/utils/auth'; import { isAccountLoggedIn } from '@/utils/auth';
@ -102,6 +101,12 @@ export default {
listStyles: {}, listStyles: {},
}; };
}, },
computed: {
...mapState(['liked']),
isRightClickedTrackLiked() {
return this.liked.songs.includes(this.rightClickedTrack?.id);
},
},
created() { created() {
if (this.type === 'tracklist') { if (this.type === 'tracklist') {
this.listStyles = { this.listStyles = {
@ -111,15 +116,9 @@ export default {
}; };
} }
}, },
computed: {
...mapState(['liked']),
isRightClickedTrackLiked() {
return this.liked.songs.includes(this.rightClickedTrack?.id);
},
},
methods: { methods: {
...mapMutations(['updateLikedSongs', 'updateModal']), ...mapMutations(['updateModal']),
...mapActions(['nextTrack', 'showToast']), ...mapActions(['nextTrack', 'showToast', 'likeATrack']),
openMenu(e, track) { openMenu(e, track) {
this.rightClickedTrack = track; this.rightClickedTrack = track;
this.$refs.menu.openMenu(e); this.$refs.menu.openMenu(e);
@ -184,27 +183,7 @@ export default {
this.$store.state.player.addTrackToPlayNext(this.rightClickedTrack.id); this.$store.state.player.addTrackToPlayNext(this.rightClickedTrack.id);
}, },
like() { like() {
this.likeASong(this.rightClickedTrack.id); this.likeATrack(this.rightClickedTrack.id);
},
likeASong(id) {
if (!isAccountLoggedIn()) {
this.showToast('此操作需要登录网易云账号');
return;
}
let like = true;
let likedSongs = this.liked.songs;
if (likedSongs.includes(id)) like = false;
likeATrack({ id, like }).then(data => {
if (data.code !== 200) return;
if (like === false) {
this.showToast(this.$t('toast.removedFromMyLikedSongs'));
this.updateLikedSongs(likedSongs.filter(d => d !== id));
} else {
this.showToast(this.$t('toast.savedToMyLikedSongs'));
likedSongs.push(id);
this.updateLikedSongs(likedSongs);
}
});
}, },
addTrackToPlaylist() { addTrackToPlaylist() {
if (!isAccountLoggedIn()) { if (!isAccountLoggedIn()) {

@ -77,12 +77,12 @@
</template> </template>
<script> <script>
import ArtistsInLine from "@/components/ArtistsInLine.vue"; import ArtistsInLine from '@/components/ArtistsInLine.vue';
import ExplicitSymbol from "@/components/ExplicitSymbol.vue"; import ExplicitSymbol from '@/components/ExplicitSymbol.vue';
import { mapState } from "vuex"; import { mapState } from 'vuex';
export default { export default {
name: "TrackListItem", name: 'TrackListItem',
components: { ArtistsInLine, ExplicitSymbol }, components: { ArtistsInLine, ExplicitSymbol },
props: { props: {
track: Object, track: Object,
@ -95,13 +95,13 @@ export default {
return { hover: false, trackStyle: {} }; return { hover: false, trackStyle: {} };
}, },
computed: { computed: {
...mapState(["settings"]), ...mapState(['settings']),
imgUrl() { imgUrl() {
let image = let image =
this.track?.al?.picUrl ?? this.track?.al?.picUrl ??
this.track?.album?.picUrl ?? this.track?.album?.picUrl ??
"https://p2.music.126.net/UeTuwE7pvjBpypWLudqukA==/3132508627578625.jpg"; 'https://p2.music.126.net/UeTuwE7pvjBpypWLudqukA==/3132508627578625.jpg';
return image + "?param=224y224"; return image + '?param=224y224';
}, },
artists() { artists() {
if (this.track.ar !== undefined) return this.track.ar; if (this.track.ar !== undefined) return this.track.ar;
@ -115,13 +115,13 @@ export default {
return this.$parent.type; return this.$parent.type;
}, },
isAlbum() { isAlbum() {
return this.type === "album"; return this.type === 'album';
}, },
isTracklist() { isTracklist() {
return this.type === "tracklist"; return this.type === 'tracklist';
}, },
isPlaylist() { isPlaylist() {
return this.type === "playlist"; return this.type === 'playlist';
}, },
isLiked() { isLiked() {
return this.$parent.liked.songs.includes(this.track.id); return this.$parent.liked.songs.includes(this.track.id);
@ -132,10 +132,10 @@ export default {
trackClass() { trackClass() {
let trackClass = [this.type]; let trackClass = [this.type];
if (!this.track.playable && this.showUnavailableSongInGreyStyle) if (!this.track.playable && this.showUnavailableSongInGreyStyle)
trackClass.push("disable"); trackClass.push('disable');
if (this.isPlaying && this.highlightPlayingTrack) if (this.isPlaying && this.highlightPlayingTrack)
trackClass.push("playing"); trackClass.push('playing');
if (this.focus) trackClass.push("focus"); if (this.focus) trackClass.push('focus');
return trackClass; return trackClass;
}, },
isMenuOpened() { isMenuOpened() {
@ -155,13 +155,13 @@ export default {
}, },
methods: { methods: {
goToAlbum() { goToAlbum() {
this.$router.push({ path: "/album/" + this.track.al.id }); this.$router.push({ path: '/album/' + this.track.al.id });
}, },
playTrack() { playTrack() {
this.$parent.playThisList(this.track.id); this.$parent.playThisList(this.track.id);
}, },
likeThisSong() { likeThisSong() {
this.$parent.likeASong(this.track.id); this.$parent.likeATrack(this.track.id);
}, },
}, },
}; };

@ -1,76 +1,76 @@
import store from "@/store"; import store from '@/store';
const player = store.state.player; const player = store.state.player;
export function ipcRenderer(vueInstance) { export function ipcRenderer(vueInstance) {
const self = vueInstance; const self = vueInstance;
// 添加专有的类名 // 添加专有的类名
document.body.setAttribute("data-electron", "yes"); document.body.setAttribute('data-electron', 'yes');
document.body.setAttribute( document.body.setAttribute(
"data-electron-os", 'data-electron-os',
window.require("os").platform() window.require('os').platform()
); );
// ipc message channel // ipc message channel
const electron = window.require("electron"); const electron = window.require('electron');
const ipcRenderer = electron.ipcRenderer; const ipcRenderer = electron.ipcRenderer;
// listens to the main process 'changeRouteTo' event and changes the route from // listens to the main process 'changeRouteTo' event and changes the route from
// inside this Vue instance, according to what path the main process requires. // inside this Vue instance, according to what path the main process requires.
// responds to Menu click() events at the main process and changes the route accordingly. // responds to Menu click() events at the main process and changes the route accordingly.
ipcRenderer.on("changeRouteTo", (event, path) => { ipcRenderer.on('changeRouteTo', (event, path) => {
self.$router.push(path); self.$router.push(path);
}); });
ipcRenderer.on("search", () => { ipcRenderer.on('search', () => {
// 触发数据响应 // 触发数据响应
self.$refs.navbar.$refs.searchInput.focus(); self.$refs.navbar.$refs.searchInput.focus();
self.$refs.navbar.inputFocus = true; self.$refs.navbar.inputFocus = true;
}); });
ipcRenderer.on("play", () => { ipcRenderer.on('play', () => {
player.playOrPause(); player.playOrPause();
}); });
ipcRenderer.on("next", () => { ipcRenderer.on('next', () => {
player.playNextTrack(); player.playNextTrack();
}); });
ipcRenderer.on("previous", () => { ipcRenderer.on('previous', () => {
player.playPrevTrack(); player.playPrevTrack();
}); });
ipcRenderer.on("increaseVolume", () => { ipcRenderer.on('increaseVolume', () => {
if (player.volume + 0.1 >= 1) { if (player.volume + 0.1 >= 1) {
return (player.volume = 1); return (player.volume = 1);
} }
player.volume += 0.1; player.volume += 0.1;
}); });
ipcRenderer.on("decreaseVolume", () => { ipcRenderer.on('decreaseVolume', () => {
if (player.volume - 0.1 <= 0) { if (player.volume - 0.1 <= 0) {
return (player.volume = 0); return (player.volume = 0);
} }
player.volume -= 0.1; player.volume -= 0.1;
}); });
ipcRenderer.on("like", () => { ipcRenderer.on('like', () => {
store.dispatch("likeASong", player.currentTrack.id); store.dispatch('likeATrack', player.currentTrack.id);
}); });
ipcRenderer.on("repeat", () => { ipcRenderer.on('repeat', () => {
player.switchRepeatMode(); player.switchRepeatMode();
}); });
ipcRenderer.on("shuffle", () => { ipcRenderer.on('shuffle', () => {
player.switchShuffle(); player.switchShuffle();
}); });
ipcRenderer.on("routerGo", (event, where) => { ipcRenderer.on('routerGo', (event, where) => {
self.$refs.navbar.go(where); self.$refs.navbar.go(where);
}); });
ipcRenderer.on("nextUp", () => { ipcRenderer.on('nextUp', () => {
self.$refs.player.goToNextTracksPage(); self.$refs.player.goToNextTracksPage();
}); });
} }

@ -1,10 +1,10 @@
import axios from "axios"; import axios from 'axios';
import Cookies from "js-cookie"; import Cookies from 'js-cookie';
let baseURL = ""; let baseURL = '';
// Web 和 Electron 跑在不同端口避免同时启动时冲突 // Web 和 Electron 跑在不同端口避免同时启动时冲突
if (process.env.IS_ELECTRON) { if (process.env.IS_ELECTRON) {
if (process.env.NODE_ENV === "production") { if (process.env.NODE_ENV === 'production') {
baseURL = process.env.VUE_APP_ELECTRON_API_URL; baseURL = process.env.VUE_APP_ELECTRON_API_URL;
} else { } else {
baseURL = process.env.VUE_APP_ELECTRON_API_URL_DEV; baseURL = process.env.VUE_APP_ELECTRON_API_URL_DEV;
@ -21,18 +21,18 @@ const service = axios.create({
service.interceptors.request.use(function (config) { service.interceptors.request.use(function (config) {
if (!config.params) config.params = {}; if (!config.params) config.params = {};
if (baseURL[0] !== "/") { if (baseURL[0] !== '/' && !process.env.IS_ELECTRON) {
config.params.cookie = `MUSIC_U=${Cookies.get("MUSIC_U")};`; config.params.cookie = `MUSIC_U=${Cookies.get('MUSIC_U')};`;
} }
return config; return config;
}); });
service.interceptors.response.use( service.interceptors.response.use(
(response) => { response => {
const res = response.data; const res = response.data;
return res; return res;
}, },
(error) => { error => {
return Promise.reject(error); return Promise.reject(error);
} }
); );

@ -31,7 +31,7 @@
</div> </div>
<div class="songs"> <div class="songs">
<TrackList <TrackList
:id="liked.playlist ? liked.playlist[0].id : 0" :id="liked.playlists.length > 0 ? liked.playlists[0].id : 0"
:tracks="liked.songsWithDetails" :tracks="liked.songsWithDetails"
:column-number="3" :column-number="3"
type="tracklist" type="tracklist"

@ -55,7 +55,7 @@
<div class="buttons"> <div class="buttons">
<button-icon <button-icon
:title="$t('player.like')" :title="$t('player.like')"
@click.native="likeASong(player.currentTrack.id)" @click.native="likeATrack(player.currentTrack.id)"
> >
<svg-icon <svg-icon
:icon-class=" :icon-class="
@ -285,7 +285,7 @@ export default {
}, },
methods: { methods: {
...mapMutations(['toggleLyrics']), ...mapMutations(['toggleLyrics']),
...mapActions(['likeASong']), ...mapActions(['likeATrack']),
getLyric() { getLyric() {
if (!this.currentTrack.id) return; if (!this.currentTrack.id) return;
return getLyric(this.currentTrack.id).then(data => { return getLyric(this.currentTrack.id).then(data => {

Loading…
Cancel
Save