Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useContext } from 'react';
|
||||
import { Navigate, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { BrainCircuit, Image, Video } from 'lucide-react';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import PageBackground from '../../components/common/PageBackground';
|
||||
import TextModel from './components/TextModel';
|
||||
import ImageGeneration from './components/ImageGeneration';
|
||||
import VideoGeneration from './components/VideoGeneration';
|
||||
import KeyManagement from './components/KeyManagement';
|
||||
import ExperienceSidebar from './components/ExperienceSidebar';
|
||||
import CloudBrain from '../CloudBrain';
|
||||
import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi';
|
||||
import Loading from '../../components/common/ui/Loading';
|
||||
import { DEFAULT_LOGIN_REDIRECT } from '../../helpers/data';
|
||||
import {
|
||||
EXPERIENCE_MODULES,
|
||||
useExperienceModules,
|
||||
} from './useExperienceModules';
|
||||
|
||||
// 移动端底部导航组件
|
||||
const MobileBottomNav = ({ currentPath, navigate, isAvailable }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// 与桌面侧边栏共用 useExperienceModules 判定,运营关闭的子页两端一致隐藏
|
||||
const navItems = [
|
||||
{
|
||||
key: 'cloud-brain',
|
||||
configKey: 'cloudBrain',
|
||||
icon: BrainCircuit,
|
||||
label: t('云端大脑'),
|
||||
path: '/experience-center/cloud-brain',
|
||||
gradient: 'from-emerald-600 to-orange-500',
|
||||
beta: true,
|
||||
},
|
||||
{
|
||||
key: 'image',
|
||||
configKey: 'imageGeneration',
|
||||
icon: Image,
|
||||
label: t('图片'),
|
||||
path: '/experience-center/image-generation',
|
||||
gradient: 'from-pink-500 to-rose-600',
|
||||
},
|
||||
{
|
||||
key: 'video',
|
||||
configKey: 'videoGeneration',
|
||||
icon: Video,
|
||||
label: t('视频'),
|
||||
path: '/experience-center/video-generation',
|
||||
gradient: 'from-cyan-500 to-blue-600',
|
||||
},
|
||||
].filter((item) => isAvailable(item.configKey));
|
||||
|
||||
return (
|
||||
<div className='md:hidden fixed bottom-0 left-0 right-0 z-50 bg-white/90 dark:bg-neutral-900/90 backdrop-blur-xl border-t border-gray-200/80 dark:border-neutral-800/80 safe-area-inset-bottom'>
|
||||
<div className='flex items-center justify-around h-14'>
|
||||
{navItems.map((item) => {
|
||||
const isActive = currentPath.includes(item.key);
|
||||
const IconComponent = item.icon;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={item.key}
|
||||
onClick={() => navigate(item.path)}
|
||||
className={`relative flex flex-col items-center justify-center flex-1 h-full transition-all ${
|
||||
isActive ? 'scale-105' : 'opacity-60'
|
||||
}`}
|
||||
>
|
||||
<div
|
||||
className={`p-1.5 rounded-lg ${isActive ? `bg-gradient-to-br ${item.gradient}` : ''}`}
|
||||
>
|
||||
<IconComponent
|
||||
size={20}
|
||||
className={
|
||||
isActive ? 'text-white' : 'text-gray-500 dark:text-gray-400'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<span
|
||||
className={`text-[10px] mt-0.5 font-medium ${
|
||||
isActive
|
||||
? 'text-gray-900 dark:text-white'
|
||||
: 'text-gray-500 dark:text-gray-400'
|
||||
}`}
|
||||
>
|
||||
{item.label}
|
||||
</span>
|
||||
{item.beta && (
|
||||
<span className='absolute top-0.5 right-[18%] rounded-full bg-orange-500 px-1 font-mono text-[7px] font-bold tracking-wide text-white'>
|
||||
BETA
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ExperienceCenter = () => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const { ready, orgOnly, isAvailable, defaultPath } = useExperienceModules();
|
||||
|
||||
// 跑马灯公告是否存在(用于动态计算顶部间距)
|
||||
const hasMarquee = !!statusState?.status?.marquee_content?.trim();
|
||||
|
||||
// 默认落地:进第一个对当前用户可用的子页;一个都没有时,org_only 用户回企业
|
||||
// 空间,其余用户去默认登录落地页。兜底目标都不在体验中心内,不会重定向循环。
|
||||
const fallbackPath =
|
||||
defaultPath || (orgOnly ? '/org' : DEFAULT_LOGIN_REDIRECT);
|
||||
const isEntryPath = [
|
||||
'/experience-center',
|
||||
'/experience-center/',
|
||||
// 兼容旧路由
|
||||
'/experience-center/ai-creation',
|
||||
].includes(location.pathname);
|
||||
if (isEntryPath) {
|
||||
// 配置/登录态就绪前不判定:默认配置全开,抢跑会落到随后才知道已关闭的页
|
||||
return ready ? <Navigate to={fallbackPath} replace /> : <Loading />;
|
||||
}
|
||||
|
||||
// 运营关闭(或分组不可见、org_only 被后端拦截)的子页,直达链接也转去可用页,
|
||||
// 避免停在菜单里看不到、接口又全报错的页面。大模型体验不在 EXPERIENCE_MODULES
|
||||
// 中,旧链接仍可直达。
|
||||
const currentModule = EXPERIENCE_MODULES.find((m) =>
|
||||
location.pathname.startsWith(m.path),
|
||||
);
|
||||
if (ready && currentModule && !isAvailable(currentModule.configKey)) {
|
||||
return <Navigate to={fallbackPath} replace />;
|
||||
}
|
||||
|
||||
const isTextModel = location.pathname.includes('text-model');
|
||||
const isCloudBrain = location.pathname.includes('cloud-brain');
|
||||
const isVideoGeneration = location.pathname.includes('video-generation');
|
||||
const isImageGeneration = location.pathname.includes('image-generation');
|
||||
// 这些页面内部有自己的滚动容器,不需要外层的 overflow-y-auto
|
||||
const noPadding =
|
||||
isTextModel || isCloudBrain || isVideoGeneration || isImageGeneration;
|
||||
|
||||
if (!CLOUD_BRAIN_UI_ENABLED && isCloudBrain) {
|
||||
return <Navigate to='/experience-center' replace />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`flex flex-col md:flex-row h-screen bg-[var(--surface-bg-base)] transition-colors duration-300 overflow-hidden ${hasMarquee ? 'pt-[96px] sm:pt-[104px]' : 'pt-14 sm:pt-16'}`}
|
||||
>
|
||||
{/* Sidebar - 桌面端 */}
|
||||
<div className='hidden md:block'>
|
||||
<ExperienceSidebar />
|
||||
</div>
|
||||
|
||||
{/* Main Content */}
|
||||
<main
|
||||
className={`
|
||||
flex-1 overflow-hidden relative pb-16 md:pb-2
|
||||
${noPadding ? '' : 'p-4 sm:p-6'}
|
||||
`}
|
||||
>
|
||||
{/* 统一页面背景层 —— 除 text-model 外,ExperienceCenter 是其子页面的唯一背景来源,
|
||||
* 子组件不再各自渲染背景,避免双层叠加。
|
||||
* text-model 特例:TextModel 自带 via-white 亮底保证聊天可读性,由其自身渲染,此处跳过。
|
||||
* 沉浸式生成页(视频/图片)用 rich 大光球,秘钥管理(Token 列表)用 subtle。 */}
|
||||
{!isTextModel && (
|
||||
<PageBackground
|
||||
variant={isVideoGeneration || isImageGeneration ? 'rich' : 'subtle'}
|
||||
animate
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 内容区域 */}
|
||||
<div
|
||||
className={`relative z-10 h-full ${noPadding ? '' : 'overflow-y-auto'}`}
|
||||
>
|
||||
{location.pathname.includes('image-generation') && (
|
||||
<ImageGeneration />
|
||||
)}
|
||||
{location.pathname.includes('video-generation') && (
|
||||
<VideoGeneration />
|
||||
)}
|
||||
{location.pathname.includes('text-model') && <TextModel />}
|
||||
{CLOUD_BRAIN_UI_ENABLED && isCloudBrain && <CloudBrain />}
|
||||
{location.pathname.includes('key-management') && <KeyManagement />}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{/* 移动端底部导航栏 */}
|
||||
<MobileBottomNav
|
||||
currentPath={location.pathname}
|
||||
navigate={navigate}
|
||||
isAvailable={isAvailable}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExperienceCenter;
|
||||
Reference in New Issue
Block a user