Skip to content

Commit

Permalink
✨ feat: 新增雷达歌单
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Jan 3, 2024
1 parent 1f9141b commit 1a63771
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,8 @@ docker run -d --name SPlayer -p 7899:7899 imsyy/splayer:latest
```

</details>

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=imsyy/SPlayer&type=Date)](https://star-history.com/#imsyy/SPlayer&Date)

16 changes: 16 additions & 0 deletions src/api/recommend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "@/utils/request";
import idMeta from "@/assets/idMeta.json";

/**
* 推荐部分
Expand Down Expand Up @@ -34,6 +35,21 @@ export const getPersonalized = (type, limit = 12) => {
});
};

/**
* 雷达歌单
*/
export const getRadarPlaylist = async () => {
const allRadar = idMeta.radarPlaylist.map((playlist) => {
return axios({
method: "GET",
url: "/playlist/detail",
params: { id: playlist.id },
});
});
const result = await Promise.allSettled(allRadar);
return result.map((res) => res?.value.playlist);
};

/**
* 热门歌手列表
* @param {number} [limit=6] - 要返回的歌手数量,默认为 6 个
Expand Down
28 changes: 28 additions & 0 deletions src/assets/idMeta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"radarPlaylist": [
{
"id": 3136952023,
"name": "私人雷达"
},
{
"id": 5320167908,
"name": "时光雷达"
},
{
"id": 5327906368,
"name": "乐迷雷达"
},
{
"id": 5362359247,
"name": "宝藏雷达"
},
{
"id": 5300458264,
"name": "新歌雷达"
},
{
"id": 5341776086,
"name": "神秘雷达"
}
]
}
1 change: 1 addition & 0 deletions src/stores/musicData.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const useMusicDataStore = defineStore("musicData", {
async setPersonalFmToTrash(id) {
try {
if (!isLogin()) return $message.warning("请登录后使用");
const status = siteStatus();
const result = await setFmToTrash(id);
if (result.code === 200) {
$message.success("已移至垃圾桶");
Expand Down
33 changes: 27 additions & 6 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div v-for="(item, index) in recommendData" :key="index" class="rec-public">
<n-h3 class="title" prefix="bar" @click="item.to ? router.push(item.to) : null">
<n-text class="name">{{ item.name }}</n-text>
<n-icon class="more" depth="3">
<n-icon v-if="item.to" class="more" depth="3">
<SvgIcon icon="chevron-right" />
</n-icon>
</n-h3>
Expand All @@ -53,7 +53,13 @@
import { storeToRefs } from "pinia";
import { useRouter } from "vue-router";
import { getGreetings } from "@/utils/timeTools";
import { getDailyRec, getPersonalized, getTopArtists, getNewAlbum } from "@/api/recommend";
import {
getDailyRec,
getPersonalized,
getRadarPlaylist,
getTopArtists,
getNewAlbum,
} from "@/api/recommend";
import { getDjPersonalRec } from "@/api/dj";
import { siteData, siteSettings } from "@/stores";
import { getCacheData } from "@/utils/helper";
Expand Down Expand Up @@ -99,12 +105,19 @@ const likeSongsCoverData = computed(() => {
// 个性化推荐数据
const recommendData = ref({
playlist: {
name: "推荐歌单",
name: isLogin() ? "专属歌单" : "推荐歌单",
loadingNum: 12,
columns: showSider.value ? undefined : "2 s:3 m:4 l:5 xl:6",
data: [],
to: "/discover/playlists",
},
radar: {
name: "雷达歌单",
loadingNum: 6,
columns: showSider.value ? undefined : "2 s:3 m:4 l:5 xl:6",
data: [],
to: "/discover/playlists",
},
artist: {
name: "歌手推荐",
type: "artist",
Expand Down Expand Up @@ -139,11 +152,13 @@ const recommendData = ref({
// 获取个性化推荐数据
const getRecommendData = async () => {
try {
const [playlistRes, artistRes, mvRes, djRes, albumRes] = await Promise.allSettled([
const [playlistRes, radarRes, artistRes, mvRes, djRes, albumRes] = await Promise.allSettled([
// 歌单
isLogin()
? getCacheData("recPl-P", 5, getDailyRec, "resource")
: getCacheData("recPl", 5, getPersonalized),
// 雷达歌单
getCacheData("recRadar", 30, getRadarPlaylist),
// 歌手
getCacheData("recAr", 5, getTopArtists),
// MV
Expand All @@ -156,8 +171,14 @@ const getRecommendData = async () => {
// 检查请求状态
playlistRes.status === "fulfilled" &&
(recommendData.value.playlist.data = formatData(
playlistRes.value.result || playlistRes.value.recommend,
isLogin()
? playlistRes.value.recommend.filter((playlist) => {
return !playlist.name.includes("私人雷达");
})
: playlistRes.value.result,
));
radarRes.status === "fulfilled" &&
(recommendData.value.radar.data = formatData(radarRes.value));
artistRes.status === "fulfilled" &&
(recommendData.value.artist.data = formatData(artistRes.value.artists, "artist"));
mvRes.status === "fulfilled" &&
Expand All @@ -167,7 +188,7 @@ const getRecommendData = async () => {
albumRes.status === "fulfilled" &&
(recommendData.value.album.data = formatData(albumRes.value.albums, "album"));
// 检查是否有任何请求失败
const anyRejected = [playlistRes, artistRes, mvRes, albumRes].some(
const anyRejected = [playlistRes, radarRes, artistRes, mvRes, albumRes].some(
(res) => res.status === "rejected",
);
if (anyRejected) {
Expand Down

0 comments on commit 1a63771

Please sign in to comment.