From 2f41e0237d5010e8acc888d468bb0b7ca66050d6 Mon Sep 17 00:00:00 2001 From: qier222 <68148142+qier222@users.noreply.github.com> Date: Mon, 26 Oct 2020 15:46:02 +0800 Subject: [PATCH 1/2] feat: add like albums & follow artists function --- package.json | 2 +- src/api/album.js | 31 +++ src/api/artist.js | 18 ++ src/api/user.js | 56 +++++- src/components/ButtonTwoTone.vue | 3 + src/components/Cover.vue | 10 +- src/components/CoverRow.vue | 8 +- src/components/MvRow.vue | 43 +++-- src/components/Navbar.vue | 3 +- src/components/Player.vue | 9 +- src/components/TrackList.vue | 16 +- src/components/TrackListItem.vue | 6 +- src/router/index.js | 2 +- src/store/index.js | 14 +- .../{initState.js => initLocalStorage.js} | 22 +-- src/store/mutations.js | 19 +- src/store/state.js | 3 +- src/utils/auth.js | 13 +- src/utils/common.js | 6 +- src/utils/updateApp.js | 28 +++ src/views/album.vue | 37 +++- src/views/artist.vue | 19 +- src/views/library.vue | 178 +++++++++++++++--- src/views/loginAccount.vue | 14 +- src/views/loginUsername.vue | 12 +- src/views/next.vue | 2 +- src/views/playlist.vue | 20 +- src/views/settings.vue | 12 +- 28 files changed, 461 insertions(+), 145 deletions(-) rename src/store/{initState.js => initLocalStorage.js} (87%) create mode 100644 src/utils/updateApp.js diff --git a/package.json b/package.json index 2a6b6cb..87cb65c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "YesPlayMusic", - "version": "0.1.0", + "version": "0.2.0", "private": true, "scripts": { "serve": "vue-cli-service serve", diff --git a/src/api/album.js b/src/api/album.js index 214128e..ef39d14 100644 --- a/src/api/album.js +++ b/src/api/album.js @@ -37,3 +37,34 @@ export function newAlbums(params) { params, }); } + +/** + * 专辑动态信息 + * 说明 : 调用此接口 , 传入专辑 id, 可获得专辑动态信息,如是否收藏,收藏数,评论数,分享数 + * - id - 专辑id + * @param {number} id + */ +export function albumDynamicDetail(id) { + return request({ + url: "/album/detail/dynamic", + method: "get", + params: { id, timestamp: new Date().getTime() }, + }); +} + +/** + * 收藏/取消收藏专辑 + * 说明 : 调用此接口,可收藏/取消收藏专辑 + * - id - 返专辑 id + * - t - 1 为收藏,其他为取消收藏 + * @param {Object} params + * @param {number} params.id + * @param {number} params.t + */ +export function likeAAlbum(params) { + return request({ + url: "/album/sub", + method: "post", + params, + }); +} diff --git a/src/api/artist.js b/src/api/artist.js index 0a5ed88..023f35d 100644 --- a/src/api/artist.js +++ b/src/api/artist.js @@ -12,6 +12,7 @@ export function getArtist(id) { method: "get", params: { id, + timestamp: new Date().getTime(), }, }).then((data) => { data.hotSongs = mapTrackPlayableStatus(data.hotSongs); @@ -71,3 +72,20 @@ export function artistMv(id) { }, }); } + +/** + * 收藏歌手 + * 说明 : 调用此接口 , 传入歌手 id, 可收藏歌手 + * - id: 歌手 id + * - t: 操作,1 为收藏,其他为取消收藏 + * @param {Object} params + * @param {number} params.id + * @param {number} params.t + */ +export function followAArtist(params) { + return request({ + url: "/artist/sub", + method: "post", + params, + }); +} diff --git a/src/api/user.js b/src/api/user.js index dbb3a05..34601f0 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -36,7 +36,7 @@ export function userPlaylist(params) { } /** - * 喜欢音乐列表 + * 喜欢音乐列表(需要登录) * 说明 : 调用此接口 , 传入用户 id, 可获取已喜欢音乐id列表(id数组) * - uid: 用户 id * @param {number} uid @@ -52,8 +52,13 @@ export function userLikedSongsIDs(uid) { }); } +/** + * 每日签到 + * 说明 : 调用此接口可签到获取积分 + * - type: 签到类型 , 默认 0, 其中 0 为安卓端签到 ,1 为 web/PC 签到 + * @param {number} type + */ export function dailySignin(type = 0) { - //可选参数 : type: 签到类型 , 默认 0, 其中 0 为安卓端签到 ,1 为 web/PC 签到 return request({ url: "/daily_signin", method: "post", @@ -62,3 +67,50 @@ export function dailySignin(type = 0) { }, }); } + +/** + * 获取收藏的专辑(需要登录) + * 说明 : 调用此接口可获取到用户收藏的专辑 + * - limit : 返回数量 , 默认为 30 + * - offset : 偏移数量,用于分页 , 如 :( 页数 -1)*30, 其中 30 为 limit 的值 , 默认为 0 + * @param {Object} params + * @param {number} params.limit + * @param {number=} params.offset + */ +export function likedAlbums() { + return request({ + url: "/album/sublist", + method: "get", + params: { + timestamp: new Date().getTime(), + }, + }); +} + +/** + * 获取收藏的歌手(需要登录) + * 说明 : 调用此接口可获取到用户收藏的歌手 + */ +export function likedArtists() { + return request({ + url: "/artist/sublist", + method: "get", + params: { + timestamp: new Date().getTime(), + }, + }); +} + +/** + * 获取收藏的MV(需要登录) + * 说明 : 调用此接口可获取到用户收藏的MV + */ +export function likedMVs() { + return request({ + url: "/mv/sublist", + method: "get", + params: { + timestamp: new Date().getTime(), + }, + }); +} diff --git a/src/components/ButtonTwoTone.vue b/src/components/ButtonTwoTone.vue index 48bec5b..98de7aa 100644 --- a/src/components/ButtonTwoTone.vue +++ b/src/components/ButtonTwoTone.vue @@ -49,10 +49,13 @@ export default { diff --git a/src/views/loginAccount.vue b/src/views/loginAccount.vue index c4ede97..a11dfb5 100644 --- a/src/views/loginAccount.vue +++ b/src/views/loginAccount.vue @@ -89,7 +89,6 @@ import { loginWithPhone, loginWithEmail } from "@/api/auth"; import md5 from "crypto-js/md5"; import { mapMutations } from "vuex"; import { userPlaylist } from "@/api/user"; -import Cookies from "js-cookie"; export default { name: "Login", @@ -112,15 +111,14 @@ export default { NProgress.done(); }, methods: { - ...mapMutations(["updateUser", "updateUserInfo", "updateAccountLogin"]), + ...mapMutations(["updateData"]), afterLogin() { - this.updateAccountLogin(true); - Cookies.set("loginMode", "account", { expires: 3650 }); + this.updateData({ key: "loginMode", value: "account" }); userPlaylist({ - uid: this.$store.state.settings.user.userId, + uid: this.$store.state.data.user.userId, limit: 1, }).then((data) => { - this.updateUserInfo({ + this.updateData({ key: "likedSongPlaylistID", value: data.playlist[0].id, }); @@ -163,7 +161,7 @@ export default { }) .then((data) => { if (data.code !== 502) { - this.updateUser(data.profile); + this.updateData({ key: "user", value: data.profile }); this.afterLogin(); } }) @@ -180,7 +178,7 @@ export default { }) .then((data) => { if (data.code !== 502) { - this.updateUser(data.profile); + this.updateData({ key: "user", value: data.profile }); this.afterLogin(); } }) diff --git a/src/views/loginUsername.vue b/src/views/loginUsername.vue index 5bd617b..f7c1bb5 100644 --- a/src/views/loginUsername.vue +++ b/src/views/loginUsername.vue @@ -52,7 +52,6 @@ import { mapMutations } from "vuex"; import NProgress from "nprogress"; import { search } from "@/api/others"; -import Cookies from "js-cookie"; import { userPlaylist } from "@/api/user"; import { throttle } from "@/utils/common"; @@ -74,7 +73,7 @@ export default { NProgress.done(); }, methods: { - ...mapMutations(["updateUser", "updateUserInfo", "updateUsernameLogin"]), + ...mapMutations(["updateData"]), search() { if (!this.keyword) return; search({ keywords: this.keyword, limit: 9, type: 1002 }).then((data) => { @@ -83,21 +82,20 @@ export default { }); }, confirm() { - this.updateUser(this.activeUser); - this.updateUsernameLogin(true); - Cookies.set("loginMode", "username", { expires: 3650 }); + this.updateData({ key: "user", value: this.activeUser }); + this.updateData({ key: "loginMode", value: "username" }); userPlaylist({ uid: this.activeUser.userId, limit: 1, }).then((data) => { - this.updateUserInfo({ + this.updateData({ key: "likedSongPlaylistID", value: data.playlist[0].id, }); this.$router.push({ path: "/library" }); }); }, - throttleSearch: throttle(function() { + throttleSearch: throttle(function () { this.search(); }, 500), }, diff --git a/src/views/next.vue b/src/views/next.vue index bde1b10..045c22d 100644 --- a/src/views/next.vue +++ b/src/views/next.vue @@ -41,7 +41,7 @@ export default { }, sortedTracks() { function compare(property) { - return function(obj1, obj2) { + return function (obj1, obj2) { var value1 = obj1[property]; var value2 = obj2[property]; return value1 - value2; diff --git a/src/views/playlist.vue b/src/views/playlist.vue index 5f8c02a..831b376 100644 --- a/src/views/playlist.vue +++ b/src/views/playlist.vue @@ -27,9 +27,7 @@ > {{ playlist.creator.nickname }} @@ -47,9 +45,7 @@ {{ $t("play") }}

- {{ - settings.user.nickname + {{ + data.user.nickname }}{{ $t("library.sLikedSongs") }}

@@ -94,6 +90,7 @@ import NProgress from "nprogress"; import { getPlaylistDetail, subscribePlaylist } from "@/api/playlist"; import { playAList } from "@/utils/play"; import { getTrackDetail } from "@/api/track"; +import { isAccountLoggedIn } from "@/utils/auth"; import ButtonTwoTone from "@/components/ButtonTwoTone.vue"; import TrackList from "@/components/TrackList.vue"; @@ -124,7 +121,7 @@ export default { }, created() { if (this.$route.name === "likedSongs") { - this.loadData(this.settings.user.likedSongPlaylistID); + this.loadData(this.data.user.likedSongPlaylistID); } else { this.loadData(this.$route.params.id); } @@ -133,10 +130,13 @@ export default { window.removeEventListener("scroll", this.handleScroll, true); }, computed: { - ...mapState(["player", "settings", "accountLogin"]), + ...mapState(["player", "data"]), isLikeSongsPage() { return this.$route.name === "likedSongs"; }, + accountLogin() { + return isAccountLoggedIn(); + }, }, methods: { ...mapMutations(["appendTrackToPlayerList"]), diff --git a/src/views/settings.vue b/src/views/settings.vue index 54517e8..c9bb454 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -1,20 +1,20 @@