mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-19 03:57:28 +08:00
fix: 不喜欢的操作只有每日推荐歌曲才请求接口,去除不喜欢的提示
This commit is contained in:
@@ -136,7 +136,7 @@ import { getMusicDetail } from '@/api/music';
|
||||
import { getUserPlaylist } from '@/api/user';
|
||||
import { navigateToMusicList } from '@/components/common/MusicListNavigator';
|
||||
import { useArtist } from '@/hooks/useArtist';
|
||||
import { usePlayerStore, useUserStore, useRecommendStore } from '@/store';
|
||||
import { usePlayerStore, useRecommendStore, useUserStore } from '@/store';
|
||||
import { Playlist } from '@/types/list';
|
||||
import type { IListDetail } from '@/types/listDetail';
|
||||
import { SongResult } from '@/types/music';
|
||||
@@ -161,7 +161,7 @@ const hotSingerData = ref<IHotSinger>();
|
||||
const dayRecommendData = computed(() => {
|
||||
if (recommendStore.dailyRecommendSongs.length > 0) {
|
||||
return {
|
||||
dailySongs: recommendStore.dailyRecommendSongs,
|
||||
dailySongs: recommendStore.dailyRecommendSongs
|
||||
};
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useDialog, useMessage } from 'naive-ui';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
@@ -7,16 +7,15 @@ import type { SongResult } from '@/types/music';
|
||||
import { getImgUrl } from '@/utils';
|
||||
import { getImageBackground } from '@/utils/linearColor';
|
||||
|
||||
import { dislikeRecommendedSong } from "../api/music";
|
||||
import { useArtist } from './useArtist';
|
||||
import { useDownload } from './useDownload';
|
||||
import { dislikeRecommendedSong } from "../api/music";
|
||||
|
||||
export function useSongItem(props: { item: SongResult; canRemove?: boolean }) {
|
||||
const { t } = useI18n();
|
||||
const playerStore = usePlayerStore();
|
||||
const recommendStore = useRecommendStore();
|
||||
const message = useMessage();
|
||||
const dialog = useDialog();
|
||||
const { downloadMusic } = useDownload();
|
||||
const { navigateToArtist } = useArtist();
|
||||
|
||||
@@ -88,6 +87,11 @@ export function useSongItem(props: { item: SongResult; canRemove?: boolean }) {
|
||||
}
|
||||
};
|
||||
|
||||
// 判断当前歌曲是否为每日推荐歌曲
|
||||
const isDailyRecommendSong = computed(() => {
|
||||
return recommendStore.dailyRecommendSongs.some(song => song.id === props.item.id);
|
||||
});
|
||||
|
||||
// 切换不喜欢状态
|
||||
const toggleDislike = async (e: Event) => {
|
||||
e && e.stopPropagation();
|
||||
@@ -97,13 +101,12 @@ export function useSongItem(props: { item: SongResult; canRemove?: boolean }) {
|
||||
return;
|
||||
}
|
||||
|
||||
dialog.warning({
|
||||
title: t('songItem.dialog.dislike.title'),
|
||||
content: t('songItem.dialog.dislike.content'),
|
||||
positiveText: t('songItem.dialog.dislike.positiveText'),
|
||||
negativeText: t('songItem.dialog.dislike.negativeText'),
|
||||
onPositiveClick: async () => {
|
||||
playerStore.addToDislikeList(props.item.id);
|
||||
|
||||
// 只有当前歌曲是每日推荐歌曲时才调用接口
|
||||
if (!isDailyRecommendSong.value) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
console.log('发送不感兴趣请求,歌曲ID:', props.item.id);
|
||||
const numericId = typeof props.item.id === 'string' ? parseInt(props.item.id) : props.item.id;
|
||||
@@ -135,8 +138,6 @@ export function useSongItem(props: { item: SongResult; canRemove?: boolean }) {
|
||||
} catch (error) {
|
||||
console.error('发送不感兴趣请求时出错:', error);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 添加到下一首播放
|
||||
|
||||
@@ -15,9 +15,9 @@ export * from './modules/lyric';
|
||||
export * from './modules/menu';
|
||||
export * from './modules/music';
|
||||
export * from './modules/player';
|
||||
export * from './modules/recommend';
|
||||
export * from './modules/search';
|
||||
export * from './modules/settings';
|
||||
export * from './modules/user';
|
||||
export * from './modules/recommend';
|
||||
|
||||
export default pinia;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
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[]>([]);
|
||||
@@ -25,7 +26,7 @@ export const useRecommendStore = defineStore('recommend', () => {
|
||||
};
|
||||
|
||||
const replaceSongInDailyRecommend = (oldSongId: number | string, newSong: SongResult) => {
|
||||
const index = dailyRecommendSongs.value.findIndex(song => song.id === oldSongId);
|
||||
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}`);
|
||||
@@ -37,6 +38,6 @@ export const useRecommendStore = defineStore('recommend', () => {
|
||||
return {
|
||||
dailyRecommendSongs,
|
||||
fetchDailyRecommendSongs,
|
||||
replaceSongInDailyRecommend,
|
||||
replaceSongInDailyRecommend
|
||||
};
|
||||
});
|
||||
@@ -358,7 +358,9 @@ const filteredSongs = computed(() => {
|
||||
: displayedSongs.value; // 否则,使用用于分页加载的 displayedSongs
|
||||
|
||||
// 2. 过滤不喜欢的歌曲
|
||||
const dislikeFilteredList = sourceList.filter(song => !playerStore.dislikeList.includes(song.id));
|
||||
const dislikeFilteredList = sourceList.filter(
|
||||
(song) => !playerStore.dislikeList.includes(song.id)
|
||||
);
|
||||
// =================================================================
|
||||
|
||||
// 3. 如果没有搜索词,直接返回处理后的列表
|
||||
@@ -929,7 +931,6 @@ const handleBatchDownload = async () => {
|
||||
await batchDownloadMusic(selectedSongsList);
|
||||
cancelSelect();
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user