From 30ff7b29302f680620871adbae3b92c4590a89d2 Mon Sep 17 00:00:00 2001 From: algerkong Date: Fri, 4 Apr 2025 21:16:27 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E4=BC=98=E5=8C=96=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=AD=8C=E6=9B=B2=E8=8E=B7=E5=8F=96=E5=8A=9F=E8=83=BD?= =?UTF-8?q?,=20=E5=88=86=E7=A6=BB=E7=BD=91=E6=98=93=E4=BA=91=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E5=92=8CB=E7=AB=99=E8=A7=86=E9=A2=91=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/views/history/index.vue | 99 +++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/src/renderer/views/history/index.vue b/src/renderer/views/history/index.vue index e731905..2896679 100644 --- a/src/renderer/views/history/index.vue +++ b/src/renderer/views/history/index.vue @@ -35,6 +35,7 @@ import { onMounted, ref } from 'vue'; import { useI18n } from 'vue-i18n'; +import { getBilibiliProxyUrl, getBilibiliVideoDetail } from '@/api/bilibili'; import { getMusicDetail } from '@/api/music'; import SongItem from '@/components/common/SongItem.vue'; import { useMusicHistory } from '@/hooks/MusicHistoryHook'; @@ -71,27 +72,89 @@ const getHistorySongs = async () => { const endIndex = startIndex + pageSize; const currentPageItems = musicList.value.slice(startIndex, endIndex); - const currentIds = currentPageItems.map((item) => item.id as number); - const res = await getMusicDetail(currentIds); + // 分离网易云音乐和B站视频 + const neteaseItems = currentPageItems.filter((item) => item.source !== 'bilibili'); + const bilibiliItems = currentPageItems.filter((item) => item.source === 'bilibili'); - if (res.data.songs) { - const newSongs = res.data.songs.map((song: SongResult) => { - const historyItem = currentPageItems.find((item) => item.id === song.id); - return { - ...song, - picUrl: song.al?.picUrl || '', - count: historyItem?.count || 0 - }; - }); - - if (currentPage.value === 1) { - displayList.value = newSongs; - } else { - displayList.value = [...displayList.value, ...newSongs]; + // 处理网易云音乐 + let neteaseSongs: SongResult[] = []; + if (neteaseItems.length > 0) { + const currentIds = neteaseItems.map((item) => item.id as number); + const res = await getMusicDetail(currentIds); + if (res.data.songs) { + neteaseSongs = res.data.songs.map((song: SongResult) => { + const historyItem = neteaseItems.find((item) => item.id === song.id); + return { + ...song, + picUrl: song.al?.picUrl || '', + count: historyItem?.count || 0, + source: 'netease' + }; + }); } - - noMore.value = displayList.value.length >= musicList.value.length; } + + // 处理B站视频 + const bilibiliSongs: SongResult[] = []; + for (const item of bilibiliItems) { + try { + const bvid = item.bilibiliData?.bvid; + if (!bvid) continue; + + const res = await getBilibiliVideoDetail(bvid); + const videoDetail = res.data; + + // 找到对应的分P + const page = videoDetail.pages.find((p) => p.cid === item.bilibiliData?.cid); + if (!page) continue; + + bilibiliSongs.push({ + id: `${videoDetail.aid}--${page.cid}`, + name: `${page.part || ''} - ${videoDetail.title}`, + picUrl: getBilibiliProxyUrl(videoDetail.pic), + ar: [ + { + name: videoDetail.owner.name, + id: videoDetail.owner.mid + } + ], + al: { + name: videoDetail.title, + picUrl: getBilibiliProxyUrl(videoDetail.pic) + }, + source: 'bilibili', + count: item.count || 0, + bilibiliData: { + bvid, + cid: page.cid + } + } as SongResult); + } catch (error) { + console.error('获取B站视频详情失败:', error); + } + } + + // 合并两种来源的数据,并保持原有顺序 + const newSongs = currentPageItems + .map((item) => { + if (item.source === 'bilibili') { + return bilibiliSongs.find( + (song) => + song.bilibiliData?.bvid === item.bilibiliData?.bvid && + song.bilibiliData?.cid === item.bilibiliData?.cid + ); + } + return neteaseSongs.find((song) => song.id === item.id); + }) + .filter((song): song is SongResult => !!song); + + if (currentPage.value === 1) { + displayList.value = newSongs; + } else { + displayList.value = [...displayList.value, ...newSongs]; + } + + noMore.value = displayList.value.length >= musicList.value.length; } catch (error) { console.error(t('history.getHistoryFailed'), error); } finally {