feat:滚动条

This commit is contained in:
MatrixSeven
2025-08-01 19:16:41 +08:00
parent ecde1b40c0
commit 664fe2fdaa
4 changed files with 67 additions and 16 deletions

View File

@@ -51,12 +51,6 @@ export default function HomePage() {
router.push(`?${params.toString()}`, { scroll: false });
}, [searchParams, router]);
// 处理tab切换
const handleTabChange = useCallback((value: string) => {
setActiveTab(value as 'file' | 'text' | 'desktop');
updateUrlParams(value);
}, [updateUrlParams]);
// 发送方状态
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
const [pickupCode, setPickupCode] = useState<string>('');
@@ -81,6 +75,56 @@ export default function HomePage() {
showToast(message, type);
}, [showToast]);
// 处理tab切换
const handleTabChange = useCallback((value: string) => {
// 检查是否已经建立连接或生成取件码
const hasActiveConnection = isConnected || pickupCode || isConnecting;
if (hasActiveConnection && value !== activeTab) {
// 如果已有活跃连接且要切换到不同的tab在新窗口打开
const currentUrl = window.location.origin + window.location.pathname;
const newUrl = `${currentUrl}?type=${value}`;
// 在新标签页打开
window.open(newUrl, '_blank');
// 给出提示
let currentMode = '';
let targetMode = '';
switch (activeTab) {
case 'file':
currentMode = '文件传输';
break;
case 'text':
currentMode = '文字传输';
break;
case 'desktop':
currentMode = '桌面共享';
break;
}
switch (value) {
case 'file':
targetMode = '文件传输';
break;
case 'text':
targetMode = '文字传输';
break;
case 'desktop':
targetMode = '桌面共享';
break;
}
showNotification(`当前${currentMode}会话进行中,已在新标签页打开${targetMode}`, 'info');
return;
}
// 如果没有活跃连接,正常切换
setActiveTab(value as 'file' | 'text' | 'desktop');
updateUrlParams(value);
}, [updateUrlParams, isConnected, pickupCode, isConnecting, activeTab, showNotification]);
// 初始化文件传输
const initFileTransfer = useCallback((fileInfo: any) => {
console.log('初始化文件传输:', fileInfo);
@@ -405,7 +449,7 @@ export default function HomePage() {
setCurrentRole('sender');
const baseUrl = window.location.origin;
const link = `${baseUrl}/?code=${code}`;
const link = `${baseUrl}/?type=file&mode=receive&code=${code}`;
setPickupLink(link);
connect(code, 'sender');
@@ -586,7 +630,6 @@ export default function HomePage() {
<div className="relative container mx-auto px-4 sm:px-6 py-8 max-w-6xl">
<Hero />
{/* Main Interface */}
<div className="max-w-4xl mx-auto">
<Tabs value={activeTab} onValueChange={handleTabChange} className="w-full">
<TabsList className="grid w-full grid-cols-3 bg-white/80 backdrop-blur-sm border-0 shadow-lg h-12 sm:h-14 p-1 mb-6">
@@ -724,7 +767,6 @@ export default function HomePage() {
showNotification(errorMessage, 'error');
return ''; // 返回空字符串而不是抛出错误
}
return data.text;
} catch (error) {
console.error('获取文字内容失败:', error);
@@ -766,7 +808,6 @@ export default function HomePage() {
</Tabs>
</div>
{/* Bottom spacing */}
<div className="h-8 sm:h-16"></div>
</div>
</div>

View File

@@ -85,6 +85,7 @@ body {
color: hsl(var(--foreground));
font-family: var(--font-geist-sans), -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
overflow-x: hidden;
overflow-y: hidden;
min-height: 100vh;
margin: 0;
padding: 0;

View File

@@ -1,3 +0,0 @@
import HomePageWrapper from './HomePageWrapper';
export default HomePageWrapper;

View File

@@ -1,13 +1,25 @@
"use client";
import React from 'react';
import { Github } from 'lucide-react';
export default function Hero() {
return (
<div className="text-center mb-8 sm:mb-12 animate-fade-in-up">
<h1 className="text-3xl sm:text-4xl md:text-5xl font-bold bg-gradient-to-r from-blue-600 via-purple-600 to-indigo-600 bg-clip-text text-transparent mb-4">
</h1>
<div className="flex items-center justify-center space-x-3 mb-4">
<h1 className="text-3xl sm:text-4xl md:text-5xl font-bold bg-gradient-to-r from-blue-600 via-purple-600 to-indigo-600 bg-clip-text text-transparent">
</h1>
<a
href="https://github.com/MatrixSeven/file-transfer-go"
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center space-x-1 px-3 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm rounded-full transition-colors duration-200 hover:scale-105 transform"
>
<Github className="w-4 h-4" />
<span className="hidden sm:inline"></span>
</a>
</div>
<p className="text-base sm:text-lg text-slate-600 max-w-2xl mx-auto leading-relaxed px-4">
<br />