mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-02-04 21:41:45 +08:00
feat: add "Save to / remove from my Liked Songs" to track list context menu
This commit is contained in:
parent
89bb04b51b
commit
81d65c2885
|
@ -3,6 +3,12 @@
|
||||||
<ContextMenu ref="menu">
|
<ContextMenu ref="menu">
|
||||||
<div class="item" @click="play">Play</div>
|
<div class="item" @click="play">Play</div>
|
||||||
<div class="item" @click="playNext">Play Next</div>
|
<div class="item" @click="playNext">Play Next</div>
|
||||||
|
<div class="item" @click="like" v-show="!isRightClickedTrackLiked">
|
||||||
|
Save to my Liked Songs
|
||||||
|
</div>
|
||||||
|
<div class="item" @click="like" v-show="isRightClickedTrackLiked">
|
||||||
|
Remove from my Liked Songs
|
||||||
|
</div>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
<TrackListItem
|
<TrackListItem
|
||||||
v-for="track in tracks"
|
v-for="track in tracks"
|
||||||
|
@ -15,12 +21,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions, mapState } from "vuex";
|
import { mapActions, mapMutations, mapState } from "vuex";
|
||||||
|
import { likeATrack } from "@/api/track";
|
||||||
import {
|
import {
|
||||||
playPlaylistByID,
|
playPlaylistByID,
|
||||||
playAlbumByID,
|
playAlbumByID,
|
||||||
playAList,
|
playAList,
|
||||||
appendTrackToPlayerList,
|
appendTrackToPlayerList
|
||||||
} from "@/utils/play";
|
} from "@/utils/play";
|
||||||
|
|
||||||
import TrackListItem from "@/components/TrackListItem.vue";
|
import TrackListItem from "@/components/TrackListItem.vue";
|
||||||
|
@ -30,7 +37,7 @@ export default {
|
||||||
name: "TrackList",
|
name: "TrackList",
|
||||||
components: {
|
components: {
|
||||||
TrackListItem,
|
TrackListItem,
|
||||||
ContextMenu,
|
ContextMenu
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
tracks: Array,
|
tracks: Array,
|
||||||
|
@ -38,17 +45,17 @@ export default {
|
||||||
id: Number,
|
id: Number,
|
||||||
itemWidth: {
|
itemWidth: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: -1,
|
default: -1
|
||||||
},
|
},
|
||||||
dbclickTrackFunc: {
|
dbclickTrackFunc: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "default",
|
default: "default"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
clickTrack: null,
|
rightClickedTrack: null,
|
||||||
listStyles: {},
|
listStyles: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -57,14 +64,18 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(["liked"]),
|
...mapState(["liked"]),
|
||||||
|
isRightClickedTrackLiked() {
|
||||||
|
return this.liked.songs.includes(this.rightClickedTrack?.id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapMutations(["updateLikedSongs"]),
|
||||||
...mapActions(["nextTrack", "playTrackOnListByID"]),
|
...mapActions(["nextTrack", "playTrackOnListByID"]),
|
||||||
openMenu(e, track) {
|
openMenu(e, track) {
|
||||||
if (!track.playable) {
|
if (!track.playable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.clickTrack = track;
|
this.rightClickedTrack = track;
|
||||||
this.$refs.menu.openMenu(e);
|
this.$refs.menu.openMenu(e);
|
||||||
},
|
},
|
||||||
playThisList(trackID) {
|
playThisList(trackID) {
|
||||||
|
@ -84,7 +95,7 @@ export default {
|
||||||
} else if (this.type === "album") {
|
} else if (this.type === "album") {
|
||||||
playAlbumByID(this.id, trackID);
|
playAlbumByID(this.id, trackID);
|
||||||
} else if (this.type === "tracklist") {
|
} else if (this.type === "tracklist") {
|
||||||
let trackIDs = this.tracks.map((t) => t.id);
|
let trackIDs = this.tracks.map(t => t.id);
|
||||||
playAList(trackIDs, this.tracks[0].ar[0].id, "artist", trackID);
|
playAList(trackIDs, this.tracks[0].ar[0].id, "artist", trackID);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -94,7 +105,24 @@ export default {
|
||||||
playNext() {
|
playNext() {
|
||||||
appendTrackToPlayerList(this.clickTrack.id);
|
appendTrackToPlayerList(this.clickTrack.id);
|
||||||
},
|
},
|
||||||
},
|
like() {
|
||||||
|
this.likeASong(this.rightClickedTrack.id);
|
||||||
|
},
|
||||||
|
likeASong(id) {
|
||||||
|
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.updateLikedSongs(likedSongs.filter(d => d !== id));
|
||||||
|
} else {
|
||||||
|
likedSongs.push(id);
|
||||||
|
this.updateLikedSongs(likedSongs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
class="track"
|
class="track"
|
||||||
:class="trackClass"
|
:class="trackClass"
|
||||||
:style="trackStyle"
|
:style="trackStyle"
|
||||||
|
:title="track.reason"
|
||||||
@mouseover="focus = true"
|
@mouseover="focus = true"
|
||||||
@mouseleave="focus = false"
|
@mouseleave="focus = false"
|
||||||
>
|
>
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
>
|
>
|
||||||
<svg-icon icon-class="play"></svg-icon>
|
<svg-icon icon-class="play"></svg-icon>
|
||||||
</button>
|
</button>
|
||||||
<span v-show="!focus">{{ track.no }}</span>
|
<span v-show="!focus || !track.playable">{{ track.no }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="title-and-artist">
|
<div class="title-and-artist">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -66,7 +67,6 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { isLoggedIn } from "@/utils/auth";
|
import { isLoggedIn } from "@/utils/auth";
|
||||||
import { likeATrack } from "@/api/track";
|
|
||||||
|
|
||||||
import ArtistsInLine from "@/components/ArtistsInLine.vue";
|
import ArtistsInLine from "@/components/ArtistsInLine.vue";
|
||||||
import ExplicitSymbol from "@/components/ExplicitSymbol.vue";
|
import ExplicitSymbol from "@/components/ExplicitSymbol.vue";
|
||||||
|
@ -127,21 +127,7 @@ export default {
|
||||||
this.$parent.playThisList(this.track.id);
|
this.$parent.playThisList(this.track.id);
|
||||||
},
|
},
|
||||||
likeThisSong() {
|
likeThisSong() {
|
||||||
let id = this.track.id;
|
this.$parent.likeASong(this.track.id);
|
||||||
let like = true;
|
|
||||||
let likedSongs = this.$parent.liked.songs;
|
|
||||||
if (likedSongs.includes(id)) like = false;
|
|
||||||
likeATrack({ id, like }).then(() => {
|
|
||||||
if (like === false) {
|
|
||||||
this.$store.commit(
|
|
||||||
"updateLikedSongs",
|
|
||||||
likedSongs.filter(d => d !== id)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
likedSongs.push(id);
|
|
||||||
this.$store.commit("updateLikedSongs", likedSongs);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user