Files
monkey-ai-web/src/pages/ExperienceCenter/index.jsx
T
zhanjunhao 4270689372 feat(experience-center): 侧栏、页头与生成页布局对齐用户中心规范
- 侧栏:结构、样式与收起交互对齐用户中心,去掉标题块与装饰
- 页头:云端大脑 / 图片生成 / 视频生成统一用户中心页头规格,去掉标题图标,页底与 /console/analytics 统一
- 云端大脑:专家广场 / 我的任务改为线型页签(对齐数据看板),页头操作右置
- 图片生成:参数栏固定、右侧整列局部滚动;工具栏单行,筛选固定宽度省略并悬停提示,清除筛选前置;两行卡片按可视高度拉伸并与左栏底边对齐;空状态居中;对比勾选框缩小居中
- 视频生成:任务队列浮层覆盖展开,表格对齐密钥管理列表,分页移出滚动区修复抖动,任务 ID 完整展示,状态去图标居中
- 三页底部内边距减半统一

验证:ESLint / Prettier / git diff --check 通过,单测 875 项通过;本地 Playwright 浅深主题 × 1920×951 / 1920×1080 / 393×851 布局与交互、6 套主题色兼容回归通过(图片 / 视频任务为模拟数据)
2026-11-20 21:38:31 +08:00

238 lines
9.6 KiB
React

import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
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 { useMarquee } from '../../hooks/common/useMarquee';
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 { isCreationStudioEnabled } from '../../helpers/creationStudio';
import { badgeText } from '../../hooks/creation/creationWatch';
import {
useCreationUnread,
useCreationWatchPoller,
} from '../../hooks/creation/useCreationWatch';
import {
EXPERIENCE_MODULES,
useExperienceModules,
} from './useExperienceModules';
// 移动端底部导航组件(exp-mobile-bottom-nav:新创作台展开态期间由 creation-dock.css 隐藏)
const MobileBottomNav = ({ currentPath, navigate, isAvailable, unread }) => {
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',
unread: unread?.image || 0,
},
{
key: 'video',
configKey: 'videoGeneration',
icon: Video,
label: t('视频'),
path: '/experience-center/video-generation',
gradient: 'from-cyan-500 to-blue-600',
unread: unread?.video || 0,
},
].filter((item) => isAvailable(item.configKey));
return (
<div className='exp-mobile-bottom-nav 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'>
{I18N_TECHNICAL_TEXT.BETA}
</span>
)}
{item.unread > 0 && !isActive ? (
<span
className='exp-unread-badge absolute top-1 right-[22%]'
aria-label={t('{{n}} 个新作品', { n: item.unread })}
>
{badgeText(item.unread)}
</span>
) : null}
</button>
);
})}
</div>
</div>
);
};
const ExperienceCenter = () => {
const location = useLocation();
const navigate = useNavigate();
const [statusState] = useContext(StatusContext);
const { ready, orgOnly, isAvailable, defaultPath } = useExperienceModules();
// 跑马灯公告是否存在(用于动态计算顶部间距)
const { visible: hasMarquee } = useMarquee();
// 新创作台:用户在体验中心其他页面时轻量轮询已提交的任务,完成后显示未读角标(WP C-4)
const creationStudioEnabled = isCreationStudioEnabled(statusState?.status);
useCreationWatchPoller(creationStudioEnabled);
const unread = useCreationUnread(creationStudioEnabled);
// 默认落地:进第一个对当前用户可用的子页;一个都没有时,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 />;
}
// 新创作台:视口高度用 dvh,微信 H5 / 移动端键盘弹起时底部创作台与生成按钮保持可见
const dynamicViewport =
(isVideoGeneration || isImageGeneration) && creationStudioEnabled;
// 云端大脑 / 图片生成 / 视频生成(非新创作台)与 /console/analytics 统一纯色页底:
// 读取 --uc-page-bg(浅色 #f8fafc,深色 --surface-bg-base),不叠加装饰光晕层
const consolePageBg =
isCloudBrain ||
((isVideoGeneration || isImageGeneration) && !creationStudioEnabled);
return (
<div
className={`flex flex-col md:flex-row ${dynamicViewport ? 'h-screen supports-[height:100dvh]:h-dvh' : 'h-screen'} ${consolePageBg ? 'bg-[var(--uc-page-bg,var(--surface-bg-base))]' : 'bg-[var(--surface-bg-base)]'} overflow-hidden ${hasMarquee ? 'pt-[91px] md:pt-[107px]' : 'pt-14 md:pt-[72px]'}`}
>
{/* Sidebar - 桌面端 */}
<div className='hidden md:block flex-shrink-0 h-full'>
<ExperienceSidebar unread={unread} />
</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 &&
!consolePageBg &&
(!(isVideoGeneration || isImageGeneration) ||
creationStudioEnabled) && (
<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}
unread={unread}
/>
</div>
);
};
export default ExperienceCenter;