feat(experience-center): 统一侧栏与页头,优化云端大脑、图片和视频生成界面
This commit is contained in:
@@ -3,26 +3,28 @@ import {
|
||||
ChevronRight as ActionChevronRight,
|
||||
ChevronLeft as ActionChevronLeft,
|
||||
} from '@/components/common/icons/ActionIcons';
|
||||
import React, { useMemo, useState, useEffect } from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { BrainCircuit, Image, Video, Sparkles } from 'lucide-react';
|
||||
import { BrainCircuit, Image, Video } from 'lucide-react';
|
||||
import { useSidebarCollapsed } from '../../../hooks/common/useSidebarCollapsed';
|
||||
import { useExperienceModules } from '../useExperienceModules';
|
||||
import { badgeText } from '../../../hooks/creation/creationWatch';
|
||||
|
||||
/**
|
||||
* 体验中心桌面侧栏:结构、样式与收起交互对齐用户中心侧栏(UserCenterSidebar),
|
||||
* 共用 center-layout.css 的 .ui-center-sidebar / .ui-center-menu-item / .ui-center-sidebar-collapse,
|
||||
* 收起状态与其他中心侧栏共用 useSidebarCollapsed。
|
||||
*
|
||||
* @param {{ unread?: { image: number, video: number } }} props
|
||||
* unread:新创作台中用户不在该页时完成的作品数(WP C-4 未读角标)
|
||||
*/
|
||||
const ExperienceSidebar = ({ unread }) => {
|
||||
const { t } = useTranslation();
|
||||
const [collapsed, toggleCollapsed] = useSidebarCollapsed();
|
||||
const [selectedKeys, setSelectedKeys] = useState([]);
|
||||
const location = useLocation();
|
||||
const { isAvailable } = useExperienceModules();
|
||||
|
||||
// 统一单一品牌色高亮(云平台风格),不再每项一种颜色
|
||||
const allNavItems = useMemo(
|
||||
() => [
|
||||
{
|
||||
@@ -59,199 +61,75 @@ const ExperienceSidebar = ({ unread }) => {
|
||||
[allNavItems, isAvailable],
|
||||
);
|
||||
|
||||
// 根据当前路径设置选中的菜单项
|
||||
useEffect(() => {
|
||||
const currentPath = location.pathname;
|
||||
const matchingItem = navItems.find((item) =>
|
||||
currentPath.startsWith(item.to),
|
||||
);
|
||||
|
||||
if (matchingItem) {
|
||||
setSelectedKeys([matchingItem.itemKey]);
|
||||
}
|
||||
}, [location.pathname, navItems]);
|
||||
// 选中项直接由当前路径推导,避免额外状态与路由不同步
|
||||
const selectedKey =
|
||||
navItems.find((item) => location.pathname.startsWith(item.to))?.itemKey ||
|
||||
'';
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`
|
||||
relative flex flex-col h-full transition-all duration-300 ease-out
|
||||
bg-white/60 dark:bg-neutral-900/60 backdrop-blur-2xl backdrop-saturate-[1.8]
|
||||
border-r border-white/40 dark:border-neutral-700/50
|
||||
shadow-[1px_0_24px_-4px_rgba(0,0,0,0.06)] dark:shadow-[1px_0_24px_-4px_rgba(0,0,0,0.3)]
|
||||
${collapsed ? 'w-[68px]' : 'w-[240px]'}
|
||||
`}
|
||||
<aside
|
||||
className='ui-experience-sidebar ui-center-sidebar'
|
||||
data-collapsed={collapsed}
|
||||
>
|
||||
{/* 毛玻璃内层光泽 */}
|
||||
<div className='absolute inset-0 bg-gradient-to-b from-white/40 via-white/10 to-white/20 dark:from-white/[0.06] dark:via-transparent dark:to-white/[0.03] pointer-events-none' />
|
||||
{/* 顶部装饰渐变 —— /8 /3 步进 Tailwind 不生成,改用 /10 两 stop 确保可见 */}
|
||||
<div className='absolute top-0 left-0 right-0 h-32 bg-gradient-to-b from-brand-from/10 to-transparent pointer-events-none' />
|
||||
<nav className='ui-center-sidebar-nav'>
|
||||
<div className='ui-org-group-items'>
|
||||
{navItems.map((item) => {
|
||||
const active = selectedKey === item.itemKey;
|
||||
const Icon = item.icon;
|
||||
const unreadCount =
|
||||
item.unreadKey && !active ? unread?.[item.unreadKey] || 0 : 0;
|
||||
const unreadLabel = unreadCount
|
||||
? t('{{n}} 个新作品', { n: unreadCount })
|
||||
: '';
|
||||
|
||||
{/* Logo/标题区域 */}
|
||||
{!collapsed && (
|
||||
<div className='px-4 pt-5 pb-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='p-1.5 bg-gradient-to-br from-brand-from to-brand-to rounded-lg'>
|
||||
<Sparkles size={16} className='text-white' />
|
||||
</div>
|
||||
<span className='font-bold text-gray-900 dark:text-white'>
|
||||
{t('体验中心')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 导航区域 */}
|
||||
<nav
|
||||
className={`relative flex-1 px-3 ${collapsed ? 'pt-4' : 'pt-2'} space-y-1.5 overflow-y-auto overflow-x-hidden`}
|
||||
>
|
||||
{navItems.map((item) => {
|
||||
const isSelected = selectedKeys.includes(item.itemKey);
|
||||
const IconComponent = item.icon;
|
||||
const unreadCount =
|
||||
item.unreadKey && !isSelected ? unread?.[item.unreadKey] || 0 : 0;
|
||||
const unreadLabel = unreadCount
|
||||
? t('{{n}} 个新作品', { n: unreadCount })
|
||||
: '';
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={item.itemKey}
|
||||
to={item.to}
|
||||
aria-label={
|
||||
unreadLabel ? `${item.text}(${unreadLabel})` : undefined
|
||||
}
|
||||
onClick={() => setSelectedKeys([item.itemKey])}
|
||||
className={`
|
||||
group relative flex items-center gap-3 rounded-xl transition-all duration-200
|
||||
${collapsed ? 'justify-center p-3' : 'px-3 py-2.5'}
|
||||
${
|
||||
isSelected
|
||||
? 'bg-brand/10 dark:bg-brand/15 shadow-sm shadow-brand/5'
|
||||
: 'hover:bg-brand/5 dark:hover:bg-brand/10'
|
||||
return (
|
||||
<Link
|
||||
key={item.itemKey}
|
||||
to={item.to}
|
||||
className='ui-center-menu-item'
|
||||
data-active={active || undefined}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
aria-label={
|
||||
unreadLabel ? `${item.text}(${unreadLabel})` : undefined
|
||||
}
|
||||
`}
|
||||
>
|
||||
{/* 选中指示器 —— 统一品牌色 */}
|
||||
{isSelected && (
|
||||
<div className='absolute left-0 top-1/2 -translate-y-1/2 w-1 h-6 rounded-r-full bg-gradient-to-b from-brand-from to-brand-to' />
|
||||
)}
|
||||
|
||||
{/* 图标 —— 激活:品牌渐变实底;非激活:中性,hover 转品牌 */}
|
||||
<div
|
||||
className={`
|
||||
relative flex-shrink-0 p-1.5 rounded-lg transition-all duration-200
|
||||
${
|
||||
isSelected
|
||||
? 'bg-gradient-to-br from-brand-from to-brand-to shadow-lg shadow-brand/25'
|
||||
: 'bg-gray-100/80 dark:bg-neutral-800/80 group-hover:bg-brand/10 group-hover:scale-105'
|
||||
}
|
||||
`}
|
||||
title={collapsed ? item.text : undefined}
|
||||
>
|
||||
<IconComponent
|
||||
size={18}
|
||||
strokeWidth={2}
|
||||
className={
|
||||
isSelected
|
||||
? 'text-white'
|
||||
: 'text-gray-500 dark:text-gray-400 group-hover:text-brand-deep dark:group-hover:text-brand-from transition-colors'
|
||||
}
|
||||
/>
|
||||
{unreadCount > 0 && collapsed ? (
|
||||
<Icon size={16} strokeWidth={1.5} aria-hidden='true' />
|
||||
{!collapsed && (
|
||||
<span className='ui-center-menu-label'>{item.text}</span>
|
||||
)}
|
||||
{!collapsed && item.beta && (
|
||||
<span className='ui-org-beta'>
|
||||
{I18N_TECHNICAL_TEXT.BETA}
|
||||
</span>
|
||||
)}
|
||||
{unreadCount > 0 ? (
|
||||
<span
|
||||
className='exp-unread-badge absolute -top-1.5 -right-1.5'
|
||||
className='exp-unread-badge ui-experience-unread'
|
||||
aria-hidden='true'
|
||||
>
|
||||
{badgeText(unreadCount)}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* 文字 */}
|
||||
{!collapsed && (
|
||||
<span className='flex min-w-0 items-center gap-2'>
|
||||
<span
|
||||
className={`
|
||||
text-sm transition-colors truncate
|
||||
${
|
||||
isSelected
|
||||
? 'text-brand-deep dark:text-brand-from font-semibold'
|
||||
: 'font-medium text-gray-600 dark:text-gray-300 group-hover:text-brand-deep dark:group-hover:text-brand-from'
|
||||
}
|
||||
`}
|
||||
>
|
||||
{item.text}
|
||||
</span>
|
||||
{item.beta && (
|
||||
<span className='shrink-0 rounded-full border border-orange-300/70 bg-orange-50 px-1.5 py-0.5 font-mono text-[8px] font-bold tracking-wider text-orange-700'>
|
||||
{I18N_TECHNICAL_TEXT.BETA}
|
||||
</span>
|
||||
)}
|
||||
{unreadCount > 0 ? (
|
||||
<span className='exp-unread-badge' aria-hidden='true'>
|
||||
{badgeText(unreadCount)}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Tooltip for collapsed state */}
|
||||
{collapsed && (
|
||||
<div
|
||||
className='
|
||||
absolute left-full ml-2 px-2.5 py-1.5
|
||||
bg-gray-900 dark:bg-white text-white dark:text-gray-900
|
||||
text-xs font-medium rounded-lg shadow-lg
|
||||
opacity-0 invisible group-hover:opacity-100 group-hover:visible
|
||||
transition-all duration-200 whitespace-nowrap z-50
|
||||
'
|
||||
>
|
||||
{item.text}
|
||||
<div
|
||||
className='absolute left-0 top-1/2 -translate-x-1 -translate-y-1/2
|
||||
border-4 border-transparent border-r-gray-900 dark:border-r-white'
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{/* 底部分隔线装饰 */}
|
||||
<div className='mx-4 h-px bg-gradient-to-r from-transparent via-gray-200/60 dark:via-neutral-700/60 to-transparent' />
|
||||
|
||||
{/* 底部折叠按钮 */}
|
||||
<div className='relative p-3'>
|
||||
<button
|
||||
onClick={toggleCollapsed}
|
||||
className={[
|
||||
'app-action-button',
|
||||
`
|
||||
flex items-center justify-center gap-2 w-full py-2 rounded-lg
|
||||
text-gray-500 dark:text-gray-400 text-sm font-medium
|
||||
bg-white/50 dark:bg-neutral-800/50
|
||||
border border-gray-200/40 dark:border-neutral-700/40
|
||||
hover:bg-brand/10 dark:hover:bg-brand/15
|
||||
hover:text-brand-deep dark:hover:text-brand-from
|
||||
hover:border-brand/30
|
||||
transition-all duration-200
|
||||
${collapsed ? 'px-2' : 'px-3'}
|
||||
`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')}
|
||||
>
|
||||
{collapsed ? (
|
||||
<ActionChevronRight size={16} strokeWidth={2.5} />
|
||||
) : (
|
||||
<>
|
||||
<ActionChevronLeft size={16} strokeWidth={2.5} />
|
||||
<span>{t('收起')}</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type='button'
|
||||
className='app-action-button ui-center-sidebar-collapse'
|
||||
onClick={toggleCollapsed}
|
||||
aria-label={collapsed ? t('展开导航') : t('收起导航')}
|
||||
>
|
||||
{collapsed ? (
|
||||
<ActionChevronRight size={16} />
|
||||
) : (
|
||||
<ActionChevronLeft size={16} />
|
||||
)}
|
||||
{!collapsed && <span>{t('收起导航')}</span>}
|
||||
</button>
|
||||
</aside>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user