/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useContext, useEffect, useState, useRef, useCallback, } from 'react'; import { Button } from '@douyinfe/semi-ui'; import { API, showError } from '../../helpers'; import { StatusContext } from '../../context/Status'; import { useActualTheme } from '../../context/Theme'; import { marked } from 'marked'; import { useTranslation } from 'react-i18next'; import { Link, useNavigate } from 'react-router-dom'; import Moonshot from '@lobehub/icons/es/Moonshot/components/Mono'; import OpenAI from '@lobehub/icons/es/OpenAI/components/Mono'; import Zhipu from '@lobehub/icons/es/Zhipu/components/Color'; import Claude from '@lobehub/icons/es/Claude/components/Color'; import Gemini from '@lobehub/icons/es/Gemini/components/Color'; import Wenxin from '@lobehub/icons/es/Wenxin/components/Color'; import Spark from '@lobehub/icons/es/Spark/components/Color'; import DeepSeek from '@lobehub/icons/es/DeepSeek/components/Color'; import Qwen from '@lobehub/icons/es/Qwen/components/Color'; import Midjourney from '@lobehub/icons/es/Midjourney/components/Mono'; import { Cpu, Server, Code, Box, Users, BarChart3, Key, Network, Rocket, MessageSquare, Palette, Video, } from 'lucide-react'; const Home = () => { const { t, i18n } = useTranslation(); const navigate = useNavigate(); const [statusState] = useContext(StatusContext); // WeyAi 桌面端下载入口(页脚位置):跟随后台「开启桌面端下载页」开关 const weyaiDownloadEnabled = statusState?.status?.weyai_download_enabled === true || statusState?.status?.weyai_download_enabled === 'true'; const actualTheme = useActualTheme(); const [homePageContentLoaded, setHomePageContentLoaded] = useState(false); const [homePageContent, setHomePageContent] = useState(''); const [iframeError, setIframeError] = useState(false); const [iframeLoading, setIframeLoading] = useState(true); const iframeTimeoutRef = useRef(null); const iframeRef = useRef(null); const isUrl = (str) => { return str.startsWith('https://') || str.startsWith('http://'); }; const displayHomePageContent = async () => { // 只对非URL内容使用localStorage缓存,URL内容总是从API获取最新的 const cachedContent = localStorage.getItem('home_page_content') || ''; if (cachedContent && !isUrl(cachedContent)) { setHomePageContent(cachedContent); } setIframeError(false); // 重置 iframe 错误状态 setIframeLoading(true); // 清除之前的超时定时器 if (iframeTimeoutRef.current) { clearTimeout(iframeTimeoutRef.current); } try { const res = await API.get('/api/home_page_content'); const { success, message, data } = res.data; if (success) { let content = data; if (!isUrl(data)) { content = marked.parse(data); } setHomePageContent(content); localStorage.setItem('home_page_content', content); if (isUrl(data)) { // 设置超时检测 - 如果 5 秒内 iframe 未能正常加载,显示备用界面 iframeTimeoutRef.current = setTimeout(() => { // 如果 5 秒后仍在加载状态,且没有收到加载成功的信号,认为加载失败 setIframeLoading(false); // 检查 iframe 是否有内容 if (iframeRef.current) { try { const doc = iframeRef.current.contentDocument || iframeRef.current.contentWindow?.document; if (!doc || !doc.body || doc.body.innerHTML === '') { setIframeError(true); } } catch (err) { // 跨域错误说明 iframe 加载成功了,只是无法访问内容 // 这种情况不设置错误 } } }, 5000); } else { // 非URL内容,立即停止loading状态 setIframeLoading(false); } } else { showError(message); setHomePageContent('加载首页内容失败...'); setIframeLoading(false); } } catch (error) { console.error('Failed to load home page content:', error); showError(t('加载首页内容失败')); setHomePageContent('加载首页内容失败...'); setIframeLoading(false); } finally { setHomePageContentLoaded(true); } }; // iframe 加载成功的回调 const handleIframeLoad = useCallback(() => { // 清除超时定时器 if (iframeTimeoutRef.current) { clearTimeout(iframeTimeoutRef.current); } setIframeLoading(false); // 检测是否真的加载成功 try { if (iframeRef.current) { const doc = iframeRef.current.contentDocument || iframeRef.current.contentWindow?.document; // 如果文档为空或无法访问,可能是被 X-Frame-Options 阻止 if (!doc || (doc.body && doc.body.innerHTML === '')) { setIframeError(true); } else { // 发送主题和语言消息 iframeRef.current.contentWindow?.postMessage( { themeMode: actualTheme }, '*', ); iframeRef.current.contentWindow?.postMessage( { lang: (i18n.language || '').split('-')[0] }, '*', ); } } } catch (err) { // 跨域访问被拒绝,但这并不意味着 iframe 加载失败 // 只是无法访问内容而已,不设置错误 console.log('iframe loaded with cross-origin content'); } }, [actualTheme, i18n.language]); // 清理定时器 useEffect(() => { return () => { if (iframeTimeoutRef.current) { clearTimeout(iframeTimeoutRef.current); } }; }, []); // 监听来自 iframe 的导航消息 // iframe 内的页面可以通过 postMessage 请求父窗口进行导航 // 消息格式: { type: 'navigate', path: '/market' } 或 { type: 'navigate', url: 'https://...' } useEffect(() => { const handleIframeMessage = (event) => { // 安全检查:只在 iframe 存在时处理消息 if (!iframeRef.current) return; // 安全检查:验证消息来源 // 只接受来自 iframe src 同源的消息,或者来自本站的消息 if (homePageContent && isUrl(homePageContent)) { try { const iframeSrcOrigin = new URL(homePageContent).origin; // 只接受来自 iframe 源或本站的消息 if ( event.origin !== iframeSrcOrigin && event.origin !== window.location.origin ) { return; } } catch (e) { // URL 解析失败,拒绝消息 return; } } const data = event.data; // 处理导航请求 if (data && data.type === 'navigate') { if (data.path) { // 内部路径导航,使用 React Router // 安全检查:路径必须以 / 开头,防止 javascript: 等协议注入 if (typeof data.path === 'string' && data.path.startsWith('/')) { navigate(data.path); } } else if (data.url) { // 外部 URL,判断是否是同源 try { const url = new URL(data.url); if (url.origin === window.location.origin) { // 同源 URL,提取路径使用 React Router 导航 navigate(url.pathname + url.search + url.hash); } else { // 跨域 URL,在新窗口打开 window.open(data.url, '_blank', 'noopener,noreferrer'); } } catch (e) { // URL 解析失败,忽略(不再尝试作为路径处理,防止注入) console.warn('Invalid navigation URL:', data.url); } } } }; window.addEventListener('message', handleIframeMessage); return () => { window.removeEventListener('message', handleIframeMessage); }; }, [navigate, homePageContent]); useEffect(() => { displayHomePageContent().then(); }, []); // 核心能力数据 - 全方位 (8 items) const capabilities = [ { icon: , title: t('多模态模型'), desc: t('支持文本、图像、语音等多种模态接入'), }, { icon: , title: t('高并发集群'), desc: t('企业级架构设计,轻松应对高并发场景'), }, { icon: , title: t('极速集成'), desc: t('OpenAI 格式完全兼容,零成本无缝迁移'), }, { icon: , title: t('按量计费'), desc: t('灵活的计费策略,极具竞争力的价格'), }, { icon: , title: t('团队协作'), desc: t('支持多用户管理与配额分配,高效协作'), }, { icon: , title: t('数据看板'), desc: t('多维度用量分析与成本监控,一目了然'), }, { icon: , title: t('令牌管理'), desc: t('精细化的 API Key 权限控制与额度限制'), }, { icon: , title: t('智能路由'), desc: t('自动选择最优通道,保障请求高可用'), }, ]; // 模型列表 const modelIcons = [ { Icon: OpenAI, name: 'OpenAI' }, { Icon: Claude, name: 'Claude' }, { Icon: Gemini, name: 'Gemini' }, { Icon: Midjourney, name: 'Midjourney' }, { Icon: Qwen, name: 'Qwen' }, { Icon: DeepSeek, name: 'DeepSeek' }, { Icon: Zhipu, name: 'ChatGLM' }, { Icon: Moonshot, name: 'Moonshot' }, { Icon: Spark, name: 'Spark' }, { Icon: Wenxin, name: 'Wenxin' }, ]; // Enterprise Style CSS const enterpriseStyles = ` .enterprise-card { background: rgba(255, 255, 255, 0.8); border: 1px solid rgba(226, 232, 240, 1); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); } .dark .enterprise-card { background: rgba(30, 41, 59, 0.6); border: 1px solid rgba(51, 65, 85, 1); } .enterprise-card:hover { transform: translateY(-5px); box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.1); border-color: rgba(59, 130, 246, 0.5); /* Blue hover */ } .dark .enterprise-card:hover { box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.3); border-color: rgba(59, 130, 246, 0.5); background: rgba(30, 41, 59, 0.8); } .hero-gradient { background: linear-gradient(135deg, #f0f9ff 0%, #dbeafe 100%); /* Light Blue */ } .dark .hero-gradient { background: linear-gradient(135deg, #172554 0%, #1e3a8a 100%); /* Dark Blue */ } .text-3d { text-shadow: 0 4px 6px rgba(0,0,0,0.1), 0 1px 3px rgba(0,0,0,0.08); } .dark .text-3d { text-shadow: 0 4px 6px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.2); } @keyframes slideInUp { from { opacity: 0; transform: translateY(50px); } to { opacity: 1; transform: translateY(0); } } .animate-slide-in { animation: slideInUp 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; } @keyframes flowRight { 0% { left: 0; opacity: 0; } 20% { opacity: 1; } 80% { opacity: 1; } 100% { left: 100%; opacity: 0; } } .animate-flow-right { animation: flowRight 2s linear infinite; } /* Hide scrollbar */ .no-scrollbar::-webkit-scrollbar { display: none; } .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; } `; const showIframe = homePageContentLoaded && homePageContent !== '' && isUrl(homePageContent); return (
{' '} {homePageContentLoaded && homePageContent === '' ? ( <> {/* Page 1: Hero Section - Custom Background & Layout */}
{/* Center Column: Text */}

{t('打造全球领先的')} {t('大模型体验中心')}

{t( '集成全球顶尖 AI 算力,为开发者提供一站式、高性能、安全稳定的企业级模型服务网关。', )}

{/* Bottom: Animated Workflow Diagram (Centered) */}
{/* User Node */}
Client
{/* Flow Lines Left -> Center */}
{/* Gateway Node */}
Gateway
{/* Flow Lines Center -> Right */}
{/* Models Nodes (Stacked) */}
{/* Page 2: Model Capabilities - Bento Grid Style */}

{t('多维感知,全能进化')}

{t( '从文本到多模态,覆盖全场景 AI 需求,为您提供最全面的模型支持', )}

{/* Large Card: LLM */}

{t('通用大语言模型')}

{t( '聚合 OpenAI GPT-4、Claude 3.5、Gemini 1.5 等全球最强 LLM。具备卓越的逻辑推理、代码生成、创意写作及多轮对话能力,满足各种复杂任务需求。', )}

Context Window 128k+ Function Calling
{/* Medium Card: Vision */}

{t('视觉理解与生成')}

{t( '支持 Midjourney、DALL-E 3 绘图,以及 GPT-4o 的视觉分析能力。', )}

{/* Small Card: Audio */}

{t('语音交互')}

{t('TTS 语音合成与 Whisper 语音转写,支持情感音色。')}

{/* Small Card: Tools/Net */}

{t('联网与插件')}

{t('实时联网搜索,获取最新资讯,打破模型知识库限制。')}

{/* Page 3: Models Section - Clean Grid */}

{t('支持当前主流的大模型探索')}

{modelIcons.map((item, i) => (
{item.name}
))}

{t('AND MORE... 持续接入中')}

{/* Page 3: Comprehensive Capabilities - Clean Cards */}

{t('全方位服务能力')}

{t('不仅仅是 API 转发,更是您 AI 应用的坚实后盾')}

{capabilities.map((item, index) => (
{item.icon}

{item.title}

{item.desc}

))}
{/* Page 4: User Experience Entry */}

{t('深度体验 AI 能力')}

{t( '直观感受大模型的强大,从视频生成到艺术创作,即刻开启您的 AI 之旅', )}

{t('AI 视频生成')}

{t('上传图片并输入提示词,生成动态视频')}

{t('AI 艺术创作')}

{t('激发无限创意,一键生成精美图像')}

{weyaiDownloadEnabled && (
{t('下载 WeyAi 桌面端')}
)}
) : (
{isUrl(homePageContent) ? ( iframeError ? ( // iframe 加载失败时显示备用界面
{/* 背景装饰 */}

{t('访问外部首页')}

{t( '由于浏览器安全策略限制,无法直接嵌入显示。请点击下方按钮访问。', )}

{t('立即访问')}

{homePageContent}

) : ( <> {iframeLoading && (

{t('正在加载...')}

)}