From 9b7afbbcc1532d7fe5a943b7d44e33253ac1e451 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Fri, 9 Jan 2026 09:41:24 +0800 Subject: [PATCH] =?UTF-8?q?play=E5=90=8C=E9=A1=B5=E9=9D=A2=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E6=96=B9=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/play/page.tsx | 11 ++++++----- src/components/VideoCard.tsx | 30 ++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index 7c2e3ca..b7ce3c5 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -509,12 +509,13 @@ function PlayPageClient() { // 监听 URL 参数变化,当切换到不同视频时重新加载页面 useEffect(() => { const urlTitle = searchParams.get('title') || ''; + const reloadParam = searchParams.get('_reload'); - // 只在切换到不同视频时重新加载页面(title变化) - // 换源(source/id变化)由播放器自己处理,不需要刷新页面 - // 如果正在换源,不应该刷新页面 - if (urlTitle && urlTitle !== videoTitle && !isSourceChangingRef.current) { - console.log('[PlayPage] Title changed, reloading page'); + // 只在有 _reload 参数且标题变化时才重新加载页面 + // 这样可以避免初始化、API返回、房间同步等场景的误触发 + // 只有用户主动点击推荐时才会添加 _reload 参数 + if (reloadParam && urlTitle && urlTitle !== videoTitle && !isSourceChangingRef.current) { + console.log('[PlayPage] User clicked recommendation, reloading page'); window.location.href = window.location.href; } diff --git a/src/components/VideoCard.tsx b/src/components/VideoCard.tsx index 5e437e6..cd61e55 100644 --- a/src/components/VideoCard.tsx +++ b/src/components/VideoCard.tsx @@ -270,16 +270,38 @@ const VideoCard = forwardRef(function VideoCard const url = `/live?source=${actualSource.replace('live_', '')}&id=${actualId.replace('live_', '')}`; router.push(url); } else if (from === 'douban' || from === 'tmdb' || (isAggregate && !actualSource && !actualId)) { - const url = `/play?title=${encodeURIComponent(actualTitle.trim())}${actualYear ? `&year=${actualYear}` : '' + // 检测当前是否在 play 页面 + const isCurrentlyOnPlayPage = typeof window !== 'undefined' && window.location.pathname === '/play'; + + let url = `/play?title=${encodeURIComponent(actualTitle.trim())}${actualYear ? `&year=${actualYear}` : '' }${actualSearchType ? `&stype=${actualSearchType}` : ''}${isAggregate ? '&prefer=true' : ''}${actualQuery ? `&stitle=${encodeURIComponent(actualQuery.trim())}` : ''}`; - router.push(url); + + if (isCurrentlyOnPlayPage) { + // 在 play 页面内,添加 _reload 参数强制刷新 + url += `&_reload=${Date.now()}`; + window.location.href = url; + } else { + // 不在 play 页面,正常跳转 + router.push(url); + } } else if (actualSource && actualId) { - const url = `/play?source=${actualSource}&id=${actualId}&title=${encodeURIComponent( + // 检测当前是否在 play 页面 + const isCurrentlyOnPlayPage = typeof window !== 'undefined' && window.location.pathname === '/play'; + + let url = `/play?source=${actualSource}&id=${actualId}&title=${encodeURIComponent( actualTitle )}${actualYear ? `&year=${actualYear}` : ''}${isAggregate ? '&prefer=true' : '' }${actualQuery ? `&stitle=${encodeURIComponent(actualQuery.trim())}` : '' }${actualSearchType ? `&stype=${actualSearchType}` : ''}`; - router.push(url); + + if (isCurrentlyOnPlayPage) { + // 在 play 页面内,添加 _reload 参数强制刷新 + url += `&_reload=${Date.now()}`; + window.location.href = url; + } else { + // 不在 play 页面,正常跳转 + router.push(url); + } } }, [ isUpcoming,