fix: 私人推荐歌单 (#1665)

* fix: 私人推荐歌单

* update
This commit is contained in:
memorydream 2022-06-19 20:51:42 +08:00 committed by GitHub
parent 1496a8a0d0
commit 2a2ac5a37d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 15 deletions

View File

@ -26,7 +26,10 @@ export function dailyRecommendPlaylist(params) {
return request({
url: '/recommend/resource',
method: 'get',
params,
params: {
params,
timestamp: Date.now(),
},
});
}
/**

View File

@ -1,5 +1,11 @@
import router from '../router';
import state from '../store/state';
import {
recommendPlaylist,
dailyRecommendPlaylist,
getPlaylistDetail,
} from '@/api/playlist';
import { isAccountLoggedIn } from '@/utils/auth';
export function hasListSource() {
return !state.player.isPersonalFM && state.player.playlistSource.id !== 0;
@ -20,3 +26,36 @@ export function getListSourcePath() {
return `/${state.player.playlistSource.type}/${state.player.playlistSource.id}`;
}
}
export async function getRecommendPlayList(limit, removePrivateRecommand) {
if (isAccountLoggedIn()) {
const playlists = await Promise.all([
dailyRecommendPlaylist(),
recommendPlaylist({ limit }),
]);
let recommend = playlists[0].recommend ?? [];
if (recommend.length) {
if (removePrivateRecommand) recommend = recommend.slice(1);
await replaceRecommendResult(recommend);
}
return recommend.concat(playlists[1].result).slice(0, limit);
} else {
const response = await recommendPlaylist({ limit });
return response.result;
}
}
async function replaceRecommendResult(recommend) {
for (let r of recommend) {
if (specialPlaylist.indexOf(r.id) > -1) {
const data = await getPlaylistDetail(r.id, true);
const playlist = data.playlist;
if (playlist) {
r.name = playlist.name;
r.picUrl = playlist.coverImgUrl;
}
}
}
}
const specialPlaylist = [3136952023, 2829883282, 2829816518, 2829896389];

View File

@ -66,13 +66,9 @@
<script>
import { mapState, mapMutations } from 'vuex';
import NProgress from 'nprogress';
import {
topPlaylist,
highQualityPlaylist,
recommendPlaylist,
toplists,
} from '@/api/playlist';
import { topPlaylist, highQualityPlaylist, toplists } from '@/api/playlist';
import { playlistCategories } from '@/utils/staticData';
import { getRecommendPlayList } from '@/utils/playList';
import ButtonTwoTone from '@/components/ButtonTwoTone.vue';
import CoverRow from '@/components/CoverRow.vue';
@ -155,9 +151,9 @@ export default {
return this.getTopPlayList();
},
getRecommendPlayList() {
recommendPlaylist({ limit: 100 }).then(data => {
getRecommendPlayList(100, true).then(list => {
this.playlists = [];
this.updatePlaylist(data.result);
this.updatePlaylist(list);
});
},
getHighQualityPlaylist() {

View File

@ -69,10 +69,11 @@
</template>
<script>
import { toplists, recommendPlaylist } from '@/api/playlist';
import { toplists } from '@/api/playlist';
import { toplistOfArtists } from '@/api/artist';
import { byAppleMusic } from '@/utils/staticData';
import { newAlbums } from '@/api/album';
import { byAppleMusic } from '@/utils/staticData';
import { getRecommendPlayList } from '@/utils/playList';
import NProgress from 'nprogress';
import { mapState } from 'vuex';
import CoverRow from '@/components/CoverRow.vue';
@ -112,10 +113,8 @@ export default {
setTimeout(() => {
if (!this.show) NProgress.start();
}, 1000);
recommendPlaylist({
limit: 10,
}).then(data => {
this.recommendPlaylist.items = data.result;
getRecommendPlayList(10, false).then(items => {
this.recommendPlaylist.items = items;
NProgress.done();
this.show = true;
});

View File

@ -318,6 +318,10 @@ const specialPlaylist = {
name: '一周原创发现',
gradient: 'gradient-blue-purple',
},
2829883282: {
name: '华语私人雷达',
gradient: 'gradient-yellow-red',
},
3136952023: {
name: '私人雷达',
gradient: 'gradient-radar',