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
@@ -18,22 +18,28 @@ export function navigateToMusicList(
canRemove?: boolean;
}
) {
const musicStore = useMusicStore();
const { id, type, name, songList, listInfo, canRemove = false } = options;
const musicStore = useMusicStore();
const { id, type, name, songList, listInfo, canRemove = false } = options;
// 保存数据到状态管理
musicStore.setCurrentMusicList(songList, name, listInfo, canRemove);
// 如果是每日推荐,不需要设置 musicStore,直接从 recommendStore 获取
if (type !== 'dailyRecommend') {
musicStore.setCurrentMusicList(songList, name, listInfo, canRemove);
} else {
// 确保 musicStore 的数据被清空,避免显示旧的列表
musicStore.clearCurrentMusicList();
}
// 路由跳转
if (id) {
// 路由跳转
if (id) {
router.push({
name: 'musicList',
params: { id },
query: { type }
});
} else {
} else {
router.push({
name: 'musicList'
name: 'musicList',
query: { type: 'dailyRecommend' }
});
}
}
}
+12 -19
View File
@@ -130,14 +130,13 @@ import { computed, onMounted, ref, watchEffect } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { getDayRecommend, getHotSinger } from '@/api/home';
import { getHotSinger } from '@/api/home';
import { getListDetail } from '@/api/list';
import { getMusicDetail } from '@/api/music';
import { getUserPlaylist } from '@/api/user';
import { navigateToMusicList } from '@/components/common/MusicListNavigator';
import { useArtist } from '@/hooks/useArtist';
import { usePlayerStore, useUserStore } from '@/store';
import { IDayRecommend } from '@/types/day_recommend';
import { usePlayerStore, useUserStore, useRecommendStore } from '@/store';
import { Playlist } from '@/types/list';
import type { IListDetail } from '@/types/listDetail';
import { SongResult } from '@/types/music';
@@ -152,13 +151,21 @@ import {
const userStore = useUserStore();
const playerStore = usePlayerStore();
const recommendStore = useRecommendStore();
const router = useRouter();
const { t } = useI18n();
// 歌手信息
const hotSingerData = ref<IHotSinger>();
const dayRecommendData = ref<IDayRecommend>();
const dayRecommendData = computed(() => {
if (recommendStore.dailyRecommendSongs.length > 0) {
return {
dailySongs: recommendStore.dailyRecommendSongs,
};
}
return null;
});
const userPlaylist = ref<Playlist[]>([]);
// 为歌单弹窗添加的状态
@@ -230,22 +237,8 @@ onMounted(async () => {
loadNonUserData();
});
// 提取每日推荐加载逻辑到单独的函数
const loadDayRecommendData = async () => {
try {
const {
data: { data: dayRecommend }
} = await getDayRecommend();
const dayRecommendSource = dayRecommend as unknown as IDayRecommend;
dayRecommendData.value = {
...dayRecommendSource,
dailySongs: dayRecommendSource.dailySongs.filter(
(song: any) => !playerStore.dislikeList.includes(song.id)
)
};
} catch (error) {
console.error('获取每日推荐失败:', error);
}
await recommendStore.fetchDailyRecommendSongs();
};
// 加载不需要登录的数据