play同页面跳转方式变更

This commit is contained in:
mtvpls
2026-01-09 09:41:24 +08:00
parent ca66ee92ea
commit 9b7afbbcc1
2 changed files with 32 additions and 9 deletions
+6 -5
View File
@@ -509,12 +509,13 @@ function PlayPageClient() {
// 监听 URL 参数变化,当切换到不同视频时重新加载页面 // 监听 URL 参数变化,当切换到不同视频时重新加载页面
useEffect(() => { useEffect(() => {
const urlTitle = searchParams.get('title') || ''; const urlTitle = searchParams.get('title') || '';
const reloadParam = searchParams.get('_reload');
// 只在切换到不同视频时重新加载页面(title变化) // 只在有 _reload 参数且标题变化时才重新加载页面
// 换源(source/id变化)由播放器自己处理,不需要刷新页面 // 这样可以避免初始化、API返回、房间同步等场景的误触发
// 如果正在换源,不应该刷新页面 // 只有用户主动点击推荐时才会添加 _reload 参数
if (urlTitle && urlTitle !== videoTitle && !isSourceChangingRef.current) { if (reloadParam && urlTitle && urlTitle !== videoTitle && !isSourceChangingRef.current) {
console.log('[PlayPage] Title changed, reloading page'); console.log('[PlayPage] User clicked recommendation, reloading page');
window.location.href = window.location.href; window.location.href = window.location.href;
} }
+26 -4
View File
@@ -270,16 +270,38 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
const url = `/live?source=${actualSource.replace('live_', '')}&id=${actualId.replace('live_', '')}`; const url = `/live?source=${actualSource.replace('live_', '')}&id=${actualId.replace('live_', '')}`;
router.push(url); router.push(url);
} else if (from === 'douban' || from === 'tmdb' || (isAggregate && !actualSource && !actualId)) { } 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())}` : ''}`; }${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) { } 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 actualTitle
)}${actualYear ? `&year=${actualYear}` : ''}${isAggregate ? '&prefer=true' : '' )}${actualYear ? `&year=${actualYear}` : ''}${isAggregate ? '&prefer=true' : ''
}${actualQuery ? `&stitle=${encodeURIComponent(actualQuery.trim())}` : '' }${actualQuery ? `&stitle=${encodeURIComponent(actualQuery.trim())}` : ''
}${actualSearchType ? `&stype=${actualSearchType}` : ''}`; }${actualSearchType ? `&stype=${actualSearchType}` : ''}`;
router.push(url);
if (isCurrentlyOnPlayPage) {
// 在 play 页面内,添加 _reload 参数强制刷新
url += `&_reload=${Date.now()}`;
window.location.href = url;
} else {
// 不在 play 页面,正常跳转
router.push(url);
}
} }
}, [ }, [
isUpcoming, isUpcoming,