diff --git a/chuan-next/src/app/HomePage-new.tsx b/chuan-next/src/app/HomePage-new.tsx index 9f00721..39a3bce 100644 --- a/chuan-next/src/app/HomePage-new.tsx +++ b/chuan-next/src/app/HomePage-new.tsx @@ -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([]); const [pickupCode, setPickupCode] = useState(''); @@ -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() {
- {/* Main Interface */}
@@ -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() {
- {/* Bottom spacing */}
diff --git a/chuan-next/src/app/globals.css b/chuan-next/src/app/globals.css index 505b020..a4cb530 100644 --- a/chuan-next/src/app/globals.css +++ b/chuan-next/src/app/globals.css @@ -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; diff --git a/chuan-next/src/app/page-new.tsx b/chuan-next/src/app/page-new.tsx deleted file mode 100644 index e71332f..0000000 --- a/chuan-next/src/app/page-new.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import HomePageWrapper from './HomePageWrapper'; - -export default HomePageWrapper; diff --git a/chuan-next/src/components/Hero.tsx b/chuan-next/src/components/Hero.tsx index a9a398a..0fefb48 100644 --- a/chuan-next/src/components/Hero.tsx +++ b/chuan-next/src/components/Hero.tsx @@ -1,13 +1,25 @@ "use client"; import React from 'react'; +import { Github } from 'lucide-react'; export default function Hero() { return (
-

- 文件快传 -

+
+

+ 文件快传 +

+ + + 开源 + +

安全、快速、简单的传输服务