mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-17 02:07:29 +08:00
feat: 日推不感兴趣调用官方接口
This commit is contained in:
@@ -2,17 +2,19 @@ import { useDialog, useMessage } from 'naive-ui';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { usePlayerStore } from '@/store';
|
||||
import { usePlayerStore, useRecommendStore } from '@/store';
|
||||
import type { SongResult } from '@/types/music';
|
||||
import { getImgUrl } from '@/utils';
|
||||
import { getImageBackground } from '@/utils/linearColor';
|
||||
|
||||
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();
|
||||
@@ -89,6 +91,7 @@ export function useSongItem(props: { item: SongResult; canRemove?: boolean }) {
|
||||
// 切换不喜欢状态
|
||||
const toggleDislike = async (e: Event) => {
|
||||
e && e.stopPropagation();
|
||||
|
||||
if (isDislike.value) {
|
||||
playerStore.removeFromDislikeList(props.item.id);
|
||||
return;
|
||||
@@ -99,8 +102,39 @@ export function useSongItem(props: { item: SongResult; canRemove?: boolean }) {
|
||||
content: t('songItem.dialog.dislike.content'),
|
||||
positiveText: t('songItem.dialog.dislike.positiveText'),
|
||||
negativeText: t('songItem.dialog.dislike.negativeText'),
|
||||
onPositiveClick: () => {
|
||||
onPositiveClick: async () => {
|
||||
playerStore.addToDislikeList(props.item.id);
|
||||
try {
|
||||
console.log('发送不感兴趣请求,歌曲ID:', props.item.id);
|
||||
const numericId = typeof props.item.id === 'string' ? parseInt(props.item.id) : props.item.id;
|
||||
const response = await dislikeRecommendedSong(numericId);
|
||||
if (response.data.data) {
|
||||
console.log(response)
|
||||
const newSongData = response.data.data;
|
||||
const newSong: SongResult = {
|
||||
...newSongData,
|
||||
name: newSongData.name,
|
||||
id: newSongData.id,
|
||||
picUrl: newSongData.al?.picUrl || newSongData.album?.picUrl,
|
||||
ar: newSongData.ar || newSongData.artists,
|
||||
al: newSongData.al || newSongData.album,
|
||||
song: {
|
||||
...newSongData.song,
|
||||
id: newSongData.id,
|
||||
name: newSongData.name,
|
||||
artists: newSongData.ar || newSongData.artists,
|
||||
album: newSongData.al || newSongData.album,
|
||||
},
|
||||
source: 'netease',
|
||||
count: 0,
|
||||
};
|
||||
recommendStore.replaceSongInDailyRecommend(props.item.id, newSong);
|
||||
} else {
|
||||
console.warn('标记不感兴趣API成功,但未返回新歌曲。', response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('发送不感兴趣请求时出错:', error);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user