feat: add context menu for album and playlist

master
qier222 4 years ago
parent b137ee2f72
commit 6b3c0383bc

@ -1 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="ellipsis-h" class="svg-inline--fa fa-ellipsis-h fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M328 256c0 39.8-32.2 72-72 72s-72-32.2-72-72 32.2-72 72-72 72 32.2 72 72zm104-72c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72zm-352 0c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72z"></path></svg> <svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="ellipsis-h" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-ellipsis-h fa-w-16 fa-9x"><path fill="currentColor" d="M304 256c0 26.5-21.5 48-48 48s-48-21.5-48-48 21.5-48 48-48 48 21.5 48 48zm120-48c-26.5 0-48 21.5-48 48s21.5 48 48 48 48-21.5 48-48-21.5-48-48-48zm-336 0c-26.5 0-48 21.5-48 48s21.5 48 48 48 48-21.5 48-48-21.5-48-48-48z" class=""></path></svg>

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 472 B

@ -37,7 +37,9 @@ export default {
closeMenu() { closeMenu() {
this.showMenu = false; this.showMenu = false;
this.$parent.closeMenu(); if (this.$parent.closeMenu !== undefined) {
this.$parent.closeMenu();
}
}, },
openMenu(e) { openMenu(e) {

@ -125,10 +125,10 @@ export default {
play: "播放", play: "播放",
playNext: "下一首播放", playNext: "下一首播放",
saveToMyLikedSongs: "添加到我喜欢的音乐", saveToMyLikedSongs: "添加到我喜欢的音乐",
removeFromMyLikedSongs: "从喜欢的音乐中除", removeFromMyLikedSongs: "从喜欢的音乐中除",
}, },
toast: { toast: {
savedToMyLikedSongs: "已添加到我喜欢的音乐", savedToMyLikedSongs: "已添加到我喜欢的音乐",
removedFromMyLikedSongs: "已从喜欢的音乐中除", removedFromMyLikedSongs: "已从喜欢的音乐中除",
}, },
}; };

@ -9,10 +9,13 @@
:size="288" :size="288"
:type="'album'" :type="'album'"
:id="album.id" :id="album.id"
@click.right.native="openMenu"
/> />
<div class="info"> <div class="info">
<div class="title"> {{ title }}</div> <div class="title" @click.right="openMenu"> {{ title }}</div>
<div class="subtitle" v-if="subtitle !== ''">{{ subtitle }}</div> <div class="subtitle" v-if="subtitle !== ''" @click.right="openMenu">{{
subtitle
}}</div>
<div class="artist"> <div class="artist">
<span v-if="album.artist.id !== 104700"> <span v-if="album.artist.id !== 104700">
<span>{{ album.type | formatAlbumType(album) }} by </span <span>{{ album.type | formatAlbumType(album) }} by </span
@ -39,7 +42,7 @@
<div class="buttons" style="margin-top: 32px"> <div class="buttons" style="margin-top: 32px">
<ButtonTwoTone <ButtonTwoTone
@click.native="playAlbumByID(album.id)" @click.native="playAlbumByID(album.id)"
:iconClass="`play`" iconClass="play"
> >
{{ $t("common.play") }} {{ $t("common.play") }}
</ButtonTwoTone> </ButtonTwoTone>
@ -55,6 +58,14 @@
@click.native="likeAlbum" @click.native="likeAlbum"
> >
</ButtonTwoTone> </ButtonTwoTone>
<ButtonTwoTone
iconClass="more"
:iconButton="true"
:horizontalPadding="0"
color="grey"
@click.native="openMenu"
>
</ButtonTwoTone>
</div> </div>
</div> </div>
</div> </div>
@ -93,8 +104,17 @@
<Modal <Modal
:show="showFullDescription" :show="showFullDescription"
:close="() => (showFullDescription = false)" :close="() => (showFullDescription = false)"
:text="album.description" :showFooter="false"
/> title="专辑介绍"
>{{ album.description }}</Modal
>
<ContextMenu ref="albumMenu">
<div class="item">{{ $t("contextMenu.playNext") }}</div>
<div class="item" @click="likeAlbum(true)">{{
dynamicDetail.isSub ? "从音乐库删除" : "保存到音乐库"
}}</div>
<div class="item">添加到歌单</div>
</ContextMenu>
</div> </div>
</template> </template>
@ -110,6 +130,7 @@ import { isAccountLoggedIn } from "@/utils/auth";
import ExplicitSymbol from "@/components/ExplicitSymbol.vue"; import ExplicitSymbol from "@/components/ExplicitSymbol.vue";
import ButtonTwoTone from "@/components/ButtonTwoTone.vue"; import ButtonTwoTone from "@/components/ButtonTwoTone.vue";
import ContextMenu from "@/components/ContextMenu.vue";
import TrackList from "@/components/TrackList.vue"; import TrackList from "@/components/TrackList.vue";
import CoverRow from "@/components/CoverRow.vue"; import CoverRow from "@/components/CoverRow.vue";
import Cover from "@/components/Cover.vue"; import Cover from "@/components/Cover.vue";
@ -124,6 +145,7 @@ export default {
ExplicitSymbol, ExplicitSymbol,
CoverRow, CoverRow,
Modal, Modal,
ContextMenu,
}, },
data() { data() {
return { return {
@ -180,7 +202,7 @@ export default {
} }
playAlbumByID(id, trackID); playAlbumByID(id, trackID);
}, },
likeAlbum() { likeAlbum(toast = false) {
if (!isAccountLoggedIn()) { if (!isAccountLoggedIn()) {
this.showToast("此操作需要登录网易云账号"); this.showToast("此操作需要登录网易云账号");
return; return;
@ -189,8 +211,13 @@ export default {
id: this.album.id, id: this.album.id,
t: this.dynamicDetail.isSub ? 0 : 1, t: this.dynamicDetail.isSub ? 0 : 1,
}).then((data) => { }).then((data) => {
if (data.code === 200) if (data.code === 200) {
this.dynamicDetail.isSub = !this.dynamicDetail.isSub; this.dynamicDetail.isSub = !this.dynamicDetail.isSub;
if (toast === true)
this.showToast(
this.dynamicDetail.isSub ? "已保存到音乐库" : "已从音乐库删除"
);
}
}); });
}, },
formatTitle() { formatTitle() {
@ -231,6 +258,9 @@ export default {
this.dynamicDetail = data; this.dynamicDetail = data;
}); });
}, },
openMenu(e) {
this.$refs.albumMenu.openMenu(e);
},
}, },
beforeRouteUpdate(to, from, next) { beforeRouteUpdate(to, from, next) {
NProgress.start(); NProgress.start();

@ -10,9 +10,10 @@
:alwaysShowShadow="true" :alwaysShowShadow="true"
:clickToPlay="true" :clickToPlay="true"
:size="288" :size="288"
@click.right.native="openMenu"
/> />
<div class="info"> <div class="info">
<div class="title" <div class="title" @click.right="openMenu"
><span class="lock-icon" v-if="playlist.privacy === 10"> ><span class="lock-icon" v-if="playlist.privacy === 10">
<svg-icon icon-class="lock" /></span <svg-icon icon-class="lock" /></span
>{{ playlist.name }}</div >{{ playlist.name }}</div
@ -64,12 +65,24 @@
@click.native="likePlaylist" @click.native="likePlaylist"
> >
</ButtonTwoTone> </ButtonTwoTone>
<ButtonTwoTone
iconClass="more"
:iconButton="true"
:horizontalPadding="0"
color="grey"
@click.native="openMenu"
>
</ButtonTwoTone>
</div> </div>
</div> </div>
</div> </div>
<div class="special-playlist" v-if="specialPlaylistInfo !== undefined"> <div class="special-playlist" v-if="specialPlaylistInfo !== undefined">
<div class="title" :class="specialPlaylistInfo.gradient"> <div
class="title"
:class="specialPlaylistInfo.gradient"
@click.right="openMenu"
>
<!-- <img :src="playlist.coverImgUrl | resizeImage" /> --> <!-- <img :src="playlist.coverImgUrl | resizeImage" /> -->
{{ specialPlaylistInfo.name }} {{ specialPlaylistInfo.name }}
</div> </div>
@ -99,6 +112,14 @@
@click.native="likePlaylist" @click.native="likePlaylist"
> >
</ButtonTwoTone> </ButtonTwoTone>
<ButtonTwoTone
iconClass="more"
:iconButton="true"
:horizontalPadding="0"
color="grey"
@click.native="openMenu"
>
</ButtonTwoTone>
</div> </div>
</div> </div>
@ -115,20 +136,46 @@
<Modal <Modal
:show="showFullDescription" :show="showFullDescription"
:close="() => (showFullDescription = false)" :close="() => (showFullDescription = false)"
:text="playlist.description" :showFooter="false"
/> title="歌单介绍"
>{{ playlist.description }}</Modal
>
<ContextMenu ref="playlistMenu">
<div class="item">{{ $t("contextMenu.playNext") }}</div>
<div class="item" @click="likePlaylist(true)">{{
playlist.subscribed ? "从音乐库删除" : "保存到音乐库"
}}</div>
<div
class="item"
v-if="playlist.creator.userId === data.user.userId"
@click="editPlaylist"
>编辑歌单信息</div
>
<div
class="item"
v-if="playlist.creator.userId === data.user.userId"
@click="deletePlaylist"
>删除歌单</div
>
</ContextMenu>
</div> </div>
</template> </template>
<script> <script>
import { mapMutations, mapActions, mapState } from "vuex"; import { mapMutations, mapActions, mapState } from "vuex";
import NProgress from "nprogress"; import NProgress from "nprogress";
import { getPlaylistDetail, subscribePlaylist } from "@/api/playlist"; import {
getPlaylistDetail,
subscribePlaylist,
deletePlaylist,
} from "@/api/playlist";
import { playAList } from "@/utils/play"; import { playAList } from "@/utils/play";
import { getTrackDetail } from "@/api/track"; import { getTrackDetail } from "@/api/track";
import { isAccountLoggedIn } from "@/utils/auth"; import { isAccountLoggedIn } from "@/utils/auth";
import ButtonTwoTone from "@/components/ButtonTwoTone.vue"; import ButtonTwoTone from "@/components/ButtonTwoTone.vue";
import ContextMenu from "@/components/ContextMenu.vue";
import TrackList from "@/components/TrackList.vue"; import TrackList from "@/components/TrackList.vue";
import Cover from "@/components/Cover.vue"; import Cover from "@/components/Cover.vue";
import Modal from "@/components/Modal.vue"; import Modal from "@/components/Modal.vue";
@ -227,6 +274,7 @@ export default {
ButtonTwoTone, ButtonTwoTone,
TrackList, TrackList,
Modal, Modal,
ContextMenu,
}, },
data() { data() {
return { return {
@ -270,7 +318,7 @@ export default {
let trackIDs = this.playlist.trackIds.map((t) => t.id); let trackIDs = this.playlist.trackIds.map((t) => t.id);
playAList(trackIDs, this.playlist.id, "playlist", trackID); playAList(trackIDs, this.playlist.id, "playlist", trackID);
}, },
likePlaylist() { likePlaylist(toast = false) {
if (!isAccountLoggedIn()) { if (!isAccountLoggedIn()) {
this.showToast("此操作需要登录网易云账号"); this.showToast("此操作需要登录网易云账号");
return; return;
@ -279,8 +327,13 @@ export default {
id: this.playlist.id, id: this.playlist.id,
t: this.playlist.subscribed ? 2 : 1, t: this.playlist.subscribed ? 2 : 1,
}).then((data) => { }).then((data) => {
if (data.code === 200) if (data.code === 200) {
this.playlist.subscribed = !this.playlist.subscribed; this.playlist.subscribed = !this.playlist.subscribed;
if (toast === true)
this.showToast(
this.playlist.subscribed ? "已保存到音乐库" : "已从音乐库删除"
);
}
getPlaylistDetail(this.id, true).then((data) => { getPlaylistDetail(this.id, true).then((data) => {
this.playlist = data.playlist; this.playlist = data.playlist;
}); });
@ -339,6 +392,25 @@ export default {
this.loadMore(); this.loadMore();
} }
}, },
openMenu(e) {
this.$refs.playlistMenu.openMenu(e);
},
deletePlaylist() {
let confirmation = confirm(`确定要删除歌单 ${this.playlist.name}`);
if (confirmation === true) {
deletePlaylist(this.playlist.id).then((data) => {
if (data.code === 200) {
alert(`已删除歌单 ${this.playlist.name}`);
this.$router.go(-1);
} else {
alert("发生错误");
}
});
}
},
editPlaylist() {
alert("此功能开发中");
},
}, },
}; };
</script> </script>

Loading…
Cancel
Save