From 1f96c07ee73dcc3c17f55a4b8d0959cb40d95373 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Thu, 7 May 2026 17:53:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E4=B9=90=E5=A2=9E=E5=8A=A0=E7=A8=8D?= =?UTF-8?q?=E5=90=8E=E6=92=AD=E6=94=BE=EF=BC=8C=E6=8E=92=E8=A1=8C=E6=A6=9C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=92=AD=E6=94=BE=E5=85=A8=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/music/page.tsx | 186 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 166 insertions(+), 20 deletions(-) diff --git a/src/app/music/page.tsx b/src/app/music/page.tsx index a6e57ea..bf47727 100644 --- a/src/app/music/page.tsx +++ b/src/app/music/page.tsx @@ -114,6 +114,7 @@ export default function MusicPage() { const [loadingUserPlaylists, setLoadingUserPlaylists] = useState(false); const [loadingUserPlaylistSongs, setLoadingUserPlaylistSongs] = useState(false); const [loadingPlayAll, setLoadingPlayAll] = useState(false); // 播放全部加载状态 + const [loadingCurrentPlayAll, setLoadingCurrentPlayAll] = useState(false); // 当前排行榜/详情页播放全部加载状态 const [deletingPlaylistId, setDeletingPlaylistId] = useState(null); // 正在删除的歌单ID useEffect(() => { @@ -515,6 +516,77 @@ export default function MusicPage() { } }; + // 当前排行榜歌单:播放全部 + const handlePlayAllCurrentSongs = async () => { + setLoadingCurrentPlayAll(true); + + try { + if (songs.length === 0) { + setToast({ + message: '当前歌单为空', + type: 'error', + onClose: () => setToast(null), + }); + return; + } + + await fetch('/api/music/v2/history', { method: 'DELETE' }); + + const baseTime = Date.now(); + const recordsToAdd = songs.map((song, i) => ({ + song: { + songId: song.id, + source: song.platform, + songmid: song.songmid, + name: song.name, + artist: song.artist, + album: song.album, + cover: song.pic, + durationSec: song.duration || 0, + durationText: song.durationText, + }, + playProgressSec: 0, + lastPlayedAt: baseTime + i, + playCount: 1, + lastQuality: quality, + })); + + await fetch('/api/music/v2/history', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ records: recordsToAdd }), + }); + + const newRecords: PlayRecord[] = songs.map((song, i) => ({ + platform: song.platform, + id: song.id, + playTime: 0, + duration: song.duration || 0, + timestamp: baseTime + i, + })); + + setPlayRecords(newRecords); + setPlaylist(songs); + setPlaylistIndex(0); + await playSong(songs[0], 0); + + setToast({ + message: `已开始播放 ${currentPlaylistTitle || '当前歌单'}`, + type: 'success', + onClose: () => setToast(null), + }); + } catch (error) { + console.error('排行榜播放全部失败:', error); + setToast({ + message: '播放全部失败', + type: 'error', + onClose: () => setToast(null), + }); + } finally { + setLoadingCurrentPlayAll(false); + } + }; + // 搜索歌曲 const searchSongs = async () => { if (!searchKeyword.trim()) return; @@ -543,6 +615,44 @@ export default function MusicPage() { setShowAddToPlaylistModal(true); }; + // 稍后播放:追加到当前播放列表末尾,不立即播放 + const handlePlayLater = (song: Song, e: React.MouseEvent) => { + e.stopPropagation(); + + if (!currentSong && playlist.length === 0 && playRecords.length === 0) { + playSong(song, -1); + return; + } + + const platform = song.platform || currentSource; + const exists = playlist.some((item) => item.id === song.id && item.platform === platform); + + if (exists) { + setToast({ + message: '歌曲已在播放列表中', + type: 'info', + onClose: () => setToast(null), + }); + return; + } + + const record: PlayRecord = { + platform, + id: song.id, + playTime: 0, + duration: song.duration || 0, + timestamp: Date.now(), + }; + + setPlayRecords((prev) => [...prev, record]); + setPlaylist((prev) => [...prev, { ...song, platform }]); + setToast({ + message: '已加入稍后播放', + type: 'success', + onClose: () => setToast(null), + }); + }; + // 加载用户歌单列表 const loadUserPlaylists = async () => { try { @@ -1478,7 +1588,7 @@ export default function MusicPage() { {/* Main Content */} -
+
{loading && (
加载中...
@@ -1502,7 +1612,7 @@ export default function MusicPage() { className="w-full text-left rounded-xl border border-white/10 bg-white/5 hover:bg-white/10 transition-colors px-4 py-3" >
-
+
{String(index + 1).padStart(2, '0')}
@@ -1535,12 +1645,36 @@ export default function MusicPage() { {currentView === 'songs' && !loading && (
-

- {currentPlaylistTitle} -

- - {songs.length} 首歌曲 - +
+

+ {currentPlaylistTitle} +

+ + {songs.length} 首歌曲 + +
+
{songs.map((song, index) => ( @@ -1553,7 +1687,7 @@ export default function MusicPage() { }`} >
playSong(song, index)} > {index + 1} @@ -1577,15 +1711,27 @@ export default function MusicPage() { > {getSourceLabel()}
- +
+ + +
))}
@@ -1717,7 +1863,7 @@ export default function MusicPage() { key={`${song.platform}+${song.id}`} className="flex items-center gap-3 p-3 rounded-lg bg-white/5 hover:bg-white/10 transition-colors" > -
{index + 1}
+
{index + 1}
{song.pic && ( {playlist.length > 0 && ( - + {playlist.length > 9 ? '9+' : playlist.length} )}