import React, { useContext, useEffect, useState } from 'react'; import { Button, Typography, Tag } from '@douyinfe/semi-ui'; import { API, showError, isMobile } from '../../helpers'; import { StatusContext } from '../../context/Status'; import { marked } from 'marked'; import { useTranslation } from 'react-i18next'; import { IconGithubLogo, IconPlay, IconFile } from '@douyinfe/semi-icons'; import { Link } from 'react-router-dom'; import NoticeModal from '../../components/layout/NoticeModal'; import { Moonshot, OpenAI, XAI, Zhipu, Volcengine, Cohere, Claude, Gemini, Suno, Minimax, Wenxin, Spark, Qingyan, DeepSeek, Qwen, Midjourney, Grok, AzureAI, Hunyuan, Xinference } from '@lobehub/icons'; const { Text } = Typography; const Home = () => { const { t, i18n } = useTranslation(); const [statusState] = useContext(StatusContext); const [homePageContentLoaded, setHomePageContentLoaded] = useState(false); const [homePageContent, setHomePageContent] = useState(''); const [noticeVisible, setNoticeVisible] = useState(false); const isDemoSiteMode = statusState?.status?.demo_site_enabled || false; const docsLink = statusState?.status?.docs_link || ''; useEffect(() => { const checkNoticeAndShow = async () => { const lastCloseDate = localStorage.getItem('notice_close_date'); const today = new Date().toDateString(); if (lastCloseDate !== today) { try { const res = await API.get('/api/notice'); const { success, data } = res.data; if (success && data && data.trim() !== '') { setNoticeVisible(true); } } catch (error) { console.error('获取公告失败:', error); } } }; checkNoticeAndShow(); }, []); const displayHomePageContent = async () => { setHomePageContent(localStorage.getItem('home_page_content') || ''); const res = await API.get('/api/home_page_content'); const { success, message, data } = res.data; if (success) { let content = data; if (!data.startsWith('https://')) { content = marked.parse(data); } setHomePageContent(content); localStorage.setItem('home_page_content', content); // 如果内容是 URL,则发送主题模式 if (data.startsWith('https://')) { const iframe = document.querySelector('iframe'); if (iframe) { const theme = localStorage.getItem('theme-mode') || 'light'; iframe.onload = () => { iframe.contentWindow.postMessage({ themeMode: theme }, '*'); iframe.contentWindow.postMessage({ lang: i18n.language }, '*'); }; } } } else { showError(message); setHomePageContent('加载首页内容失败...'); } setHomePageContentLoaded(true); }; useEffect(() => { displayHomePageContent().then(); }, []); return (
setNoticeVisible(false)} isMobile={isMobile()} /> {homePageContentLoaded && homePageContent === '' ? (
{/* Banner 部分 */}
{/* 居中内容区 */}

{i18n.language === 'en' ? ( <> The Unified
LLMs API Gateway ) : ( t('统一的大模型接口网关') )}

{t('更好的价格,更好的稳定性,无需订阅')}

{/* 操作按钮 */}
{isDemoSiteMode && statusState?.status?.version ? ( ) : ( docsLink && ( ) )}
{/* 框架兼容性图标 */}
{t('支持众多的大模型供应商')}
30+
) : (
{homePageContent.startsWith('https://') ? (