fix: 不喜欢的操作只有每日推荐歌曲才请求接口,去除不喜欢的提示

This commit is contained in:
alger
2025-09-13 23:58:33 +08:00
parent fb8b4c9341
commit 70677dfb14
5 changed files with 102 additions and 99 deletions
+33 -32
View File
@@ -1,42 +1,43 @@
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';
import type { SongResult } from '@/types/music';
export const useRecommendStore = defineStore('recommend', () => {
const dailyRecommendSongs = ref<SongResult[]>([]);
const dailyRecommendSongs = ref<SongResult[]>([]);
const fetchDailyRecommendSongs = async () => {
try {
const { data } = await getDayRecommend();
const recommendData = data.data as unknown as IDayRecommend;
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 = [];
}
};
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}`);
}
};
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,
};
});
return {
dailyRecommendSongs,
fetchDailyRecommendSongs,
replaceSongInDailyRecommend
};
});