From 050989dcfb36b75cee84f870243dfd56049bca52 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Wed, 4 Feb 2026 16:51:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E8=A7=82=E7=9C=8B=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=B8=90=E8=BF=9B=E5=BC=8F=E5=8A=A0=E8=BD=BD=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ContinueWatching.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/ContinueWatching.tsx b/src/components/ContinueWatching.tsx index 57813aa..969e454 100644 --- a/src/components/ContinueWatching.tsx +++ b/src/components/ContinueWatching.tsx @@ -27,7 +27,7 @@ export default function ContinueWatching({ className }: ContinueWatchingProps) { const [showConfirmDialog, setShowConfirmDialog] = useState(false); // 处理播放记录数据更新的函数 - const updatePlayRecords = (allRecords: Record) => { + const updatePlayRecords = (allRecords: Record, limit?: number) => { // 将记录转换为数组并根据 save_time 由近到远排序 const recordsArray = Object.entries(allRecords).map(([key, record]) => ({ ...record, @@ -39,7 +39,10 @@ export default function ContinueWatching({ className }: ContinueWatchingProps) { (a, b) => b.save_time - a.save_time ); - setPlayRecords(sortedRecords); + // 如果指定了 limit,只取前 N 条 + const finalRecords = limit ? sortedRecords.slice(0, limit) : sortedRecords; + + setPlayRecords(finalRecords); }; useEffect(() => { @@ -49,7 +52,14 @@ export default function ContinueWatching({ className }: ContinueWatchingProps) { // 从缓存或API获取所有播放记录 const allRecords = await getAllPlayRecords(); - updatePlayRecords(allRecords); + + // 非 localStorage 模式下,先只显示前 10 条记录 + const storageType = process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage'; + if (storageType !== 'localstorage') { + updatePlayRecords(allRecords, 10); + } else { + updatePlayRecords(allRecords); + } } catch (error) { console.error('获取播放记录失败:', error); setPlayRecords([]); @@ -64,6 +74,7 @@ export default function ContinueWatching({ className }: ContinueWatchingProps) { const unsubscribe = subscribeToDataUpdates( 'playRecordsUpdated', (newRecords: Record) => { + // 同步完成后,加载完整数据(不限制数量) updatePlayRecords(newRecords); } );