From 6586524850cfbeb20a3db989326cbc414f738dc9 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Thu, 18 Dec 2025 15:50:26 +0800 Subject: [PATCH] =?UTF-8?q?live=E9=A1=B5=E9=9D=A2=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E9=A2=91=E9=81=93=E4=BC=9A=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E6=A0=8F=EF=BC=8C=E4=BF=9D=E8=AF=81=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=90=8E=E5=A4=84=E4=BA=8E=E5=90=8C=E4=B8=80=E9=A2=91?= =?UTF-8?q?=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/live/page.tsx | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/app/live/page.tsx b/src/app/live/page.tsx index 188c673..2a26948 100644 --- a/src/app/live/page.tsx +++ b/src/app/live/page.tsx @@ -331,17 +331,6 @@ function LivePageClient() { // 不设置错误,而是显示空状态 setLiveSources([]); setLoading(false); - } finally { - // 移除 URL 搜索参数中的 source 和 id - const newSearchParams = new URLSearchParams(searchParams.toString()); - newSearchParams.delete('source'); - newSearchParams.delete('id'); - - const newUrl = newSearchParams.toString() - ? `?${newSearchParams.toString()}` - : window.location.pathname; - - router.replace(newUrl); } }; @@ -445,6 +434,14 @@ function LivePageClient() { } catch (err) { console.error('保存播放记录失败:', err); } + + // 更新URL参数 + const newSearchParams = new URLSearchParams(searchParams.toString()); + newSearchParams.set('source', source.key); + newSearchParams.set('id', selectedChannel.id); + + const newUrl = `?${newSearchParams.toString()}`; + router.replace(newUrl); } } @@ -527,6 +524,14 @@ function LivePageClient() { setCurrentSource(source); await fetchChannels(source); + + // 更新URL参数 - 切换直播源时清除频道id,因为新的直播源会有不同的频道列表 + const newSearchParams = new URLSearchParams(searchParams.toString()); + newSearchParams.set('source', source.key); + newSearchParams.delete('id'); // 清除频道id + + const newUrl = `?${newSearchParams.toString()}`; + router.replace(newUrl); } catch (err) { console.error('切换直播源失败:', err); // 不设置错误,保持当前状态 @@ -581,6 +586,16 @@ function LivePageClient() { setCurrentChannel(channel); setVideoUrl(channel.url); + // 更新URL参数 + if (currentSource) { + const newSearchParams = new URLSearchParams(searchParams.toString()); + newSearchParams.set('source', currentSource.key); + newSearchParams.set('id', channel.id); + + const newUrl = `?${newSearchParams.toString()}`; + router.replace(newUrl); + } + // 自动滚动到选中的频道位置 setTimeout(() => { scrollToChannel(channel);