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

View File

@@ -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;
}

View File

@@ -270,16 +270,38 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(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,