feat: 日推不感兴趣调用官方接口

This commit is contained in:
shano
2025-09-10 00:29:50 +08:00
parent d24d3d63b8
commit fb8b4c9341
7 changed files with 188 additions and 121 deletions
+1
View File
@@ -18,5 +18,6 @@ export * from './modules/player';
export * from './modules/search';
export * from './modules/settings';
export * from './modules/user';
export * from './modules/recommend';
export default pinia;
+42
View File
@@ -0,0 +1,42 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { getDayRecommend } from '@/api/home';
import type { SongResult } from '@/types/music';
import type { IDayRecommend } from '@/types/day_recommend';
export const useRecommendStore = defineStore('recommend', () => {
const dailyRecommendSongs = ref<SongResult[]>([]);
const fetchDailyRecommendSongs = async () => {
try {
const { data } = await getDayRecommend();
const recommendData = data.data as unknown as IDayRecommend;
if (recommendData && Array.isArray(recommendData.dailySongs)) {
dailyRecommendSongs.value = recommendData.dailySongs as any;
console.log(`[Recommend Store] 已加载 ${recommendData.dailySongs.length} 首每日推荐歌曲。`);
} else {
dailyRecommendSongs.value = [];
}
} catch (error) {
console.error('[Recommend Store] 获取每日推荐失败:', error);
dailyRecommendSongs.value = [];
}
};
const replaceSongInDailyRecommend = (oldSongId: number | string, newSong: SongResult) => {
const index = dailyRecommendSongs.value.findIndex(song => song.id === oldSongId);
if (index !== -1) {
dailyRecommendSongs.value.splice(index, 1, newSong as any);
console.log(`[Recommend Store] 已将歌曲 ${oldSongId} 替换为 ${newSong.name}`);
} else {
console.warn(`[Recommend Store] 未在日推列表中找到要替换的歌曲ID: ${oldSongId}`);
}
};
return {
dailyRecommendSongs,
fetchDailyRecommendSongs,
replaceSongInDailyRecommend,
};
});