feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-06 20:19:43 +08:00
parent 43048626a6
commit a075732cb4
147 changed files with 9816 additions and 8768 deletions
+73 -263
View File
@@ -20,8 +20,7 @@ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import {
BarChart2,
Users,
BarChart3,
Key,
FileSearch,
Receipt,
@@ -29,15 +28,11 @@ import {
ChevronDown,
ChevronLeft,
ChevronRight,
Building2,
Search,
X,
CreditCard,
Network,
FolderKanban,
Folder,
LayoutGrid,
Wallet,
FileClock,
UserRound,
BrainCircuit,
LibraryBig,
@@ -47,7 +42,8 @@ import {
ShieldCheck,
Cable,
Gauge,
Sparkles,
Zap,
Check,
Activity,
} from 'lucide-react';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
@@ -176,7 +172,7 @@ const OrgSidebar = ({
// 让「AI 能力管理」成为纯管理员分组。
itemKey: '/org/my-capabilities',
text: t('我的 AI 能力'),
icon: Sparkles,
icon: Zap,
group: 'overview',
},
{
@@ -237,14 +233,14 @@ const OrgSidebar = ({
{
itemKey: '/org/dashboard',
text: t('数据看板'),
icon: BarChart2,
icon: BarChart3,
group: 'overview',
adminOnly: true,
},
{
itemKey: '/org/members',
text: t('员工管理'),
icon: Users,
icon: UserRound,
group: 'org',
adminOnly: true,
},
@@ -258,13 +254,13 @@ const OrgSidebar = ({
{
itemKey: '/org/project-manage',
text: t('我的项目'),
icon: FolderKanban,
icon: Folder,
group: 'org',
projectScope: true,
},
{
itemKey: '/org/departments',
text: t('部门管理'),
text: t('组织架构'),
icon: Network,
group: 'org',
adminOnly: true,
@@ -272,7 +268,7 @@ const OrgSidebar = ({
{
itemKey: '/org/projects',
text: t('项目管理'),
icon: FolderKanban,
icon: Folder,
group: 'org',
adminOnly: true,
},
@@ -286,12 +282,12 @@ const OrgSidebar = ({
{
itemKey: '/org/requests',
text: isAdmin ? t('审批中心') : t('我的申请'),
icon: FileClock,
icon: Check,
group: 'governance',
},
{
itemKey: '/org/tokens',
text: t('令牌管理'),
text: t('密钥管理'),
icon: Key,
group: 'governance',
},
@@ -448,20 +444,7 @@ const OrgSidebar = ({
[groups, items],
);
// 菜单搜索:命中项按分组展示;搜索中忽略折叠状态,保证结果可见
const [searchText, setSearchText] = useState('');
const searchInputRef = useRef(null);
const navRef = useRef(null);
const query = searchText.trim().toLowerCase();
const visibleGroups = useMemo(() => {
if (!query) return groupedItems;
return groupedItems
.map((g) => ({
...g,
items: g.items.filter((it) => it.text.toLowerCase().includes(query)),
}))
.filter((g) => g.items.length > 0);
}, [groupedItems, query]);
// 二级分组折叠:仅记录用户手动收起的组,跨会话记忆
const FOLDED_GROUPS_KEY = 'org_sidebar_folded_groups';
@@ -519,265 +502,92 @@ const OrgSidebar = ({
el?.scrollIntoView({ block: 'nearest' });
}, [selectedKey]);
// 搜索命中片段高亮
const renderItemText = (text) => {
if (!query) return text;
const idx = text.toLowerCase().indexOf(query);
if (idx === -1) return text;
return (
<>
{text.slice(0, idx)}
<mark className='rounded-sm bg-brand/20 px-0.5 text-inherit'>
{text.slice(idx, idx + query.length)}
</mark>
{text.slice(idx + query.length)}
</>
);
};
return (
<div
className={`
relative flex flex-col h-full transition-all duration-300 ease-out
bg-[var(--surface-sidebar)]
border-r border-[var(--border-subtle)]
${collapsed ? 'w-[64px]' : 'w-[216px]'}
`}
<aside
className='ui-center-sidebar ui-org-sidebar'
data-collapsed={collapsed}
data-mobile={mobile || undefined}
>
{/* 标题区域 */}
{!collapsed && (
<div className='px-4 pt-5 pb-3'>
<div className='flex items-center gap-2'>
<div className='p-1.5 rounded-lg bg-brand/10 text-brand'>
<Building2 size={16} />
</div>
<div className='min-w-0'>
<span className='font-bold text-gray-900 dark:text-white block truncate text-sm'>
{orgName || t('企业中心')}
</span>
{orgRole && (
<span className='text-[10px] text-gray-500 dark:text-gray-400'>
{roleLabel}
</span>
)}
</div>
<div className='ui-org-identity'>
<LayoutGrid size={22} strokeWidth={1.5} aria-hidden='true' />
<div className='ui-org-identity-copy'>
<span className='ui-org-name' title={orgName || t('企业中心')}>
{orgName || t('企业中心')}
</span>
{orgRole && <span className='ui-org-role'>{roleLabel}</span>}
</div>
</div>
)}
{/* 菜单搜索(折叠态显示放大镜按钮,点击先展开侧栏再聚焦输入框) */}
{!collapsed ? (
<div className='px-3 pb-1'>
<div className='relative'>
<Search
size={14}
className='pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-400 dark:text-gray-500'
/>
<input
ref={searchInputRef}
type='text'
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Escape') setSearchText('');
}}
placeholder={t('搜索菜单')}
aria-label={t('搜索菜单')}
className='h-8 w-full rounded-lg border border-transparent bg-[var(--ui-color-fill-0)] pl-8 pr-7 text-sm text-[var(--text-primary)] outline-none transition-colors duration-200 placeholder:text-gray-400 focus:border-brand/40 focus:bg-[var(--surface-card)] dark:placeholder:text-gray-500'
/>
{searchText && (
<button
type='button'
onClick={() => setSearchText('')}
aria-label={t('清空搜索')}
className='absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 dark:hover:text-gray-200'
>
<X size={13} />
</button>
)}
</div>
</div>
) : (
<div className='px-3 pb-1 pt-3'>
<button
type='button'
onClick={() => {
toggleCollapsed();
setTimeout(() => searchInputRef.current?.focus(), 350);
}}
aria-label={t('搜索菜单')}
className='flex w-full items-center justify-center rounded-lg p-2 text-gray-500 transition-colors duration-200 hover:bg-brand/10 hover:text-brand-deep dark:text-gray-400 dark:hover:bg-brand/15 dark:hover:text-brand-from'
>
<Search size={16} />
</button>
</div>
)}
{/* 导航区域 */}
<nav
ref={navRef}
className='app-scrollbar relative flex-1 px-3 pt-1 pb-2 overflow-y-auto overflow-x-hidden'
>
{query && visibleGroups.length === 0 && (
<div className='px-2 py-8 text-center text-xs text-gray-400 dark:text-gray-500'>
{t('没有匹配的菜单')}
</div>
)}
{visibleGroups.map((group, gi) => {
// 搜索中强制展开,保证命中项可见;平时遵循用户的折叠选择
const folded = !query && foldedGroups.includes(group.key);
<nav ref={navRef} className='ui-center-sidebar-nav'>
{groupedItems.map((group) => {
const folded = foldedGroups.includes(group.key);
return (
<div key={group.key} className={gi > 0 ? 'mt-3' : ''}>
{/* 分组标题(展开态,可点击折叠)/ 分隔线(折叠态) */}
{!collapsed ? (
<div key={group.key} className='ui-org-nav-group'>
{!collapsed && (
<button
type='button'
onClick={() => toggleGroup(group.key)}
aria-expanded={!folded}
className='mb-1 flex w-full select-none items-center gap-1.5 rounded-md px-2 py-1 text-[11px] font-semibold uppercase tracking-wider text-gray-400 transition-colors duration-200 hover:bg-[var(--ui-color-fill-0)] hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300'
className='ui-org-group-toggle'
>
<span className='truncate'>{group.label}</span>
<span className='ml-auto text-[10px] font-normal tabular-nums opacity-70'>
{group.items.length}
</span>
<span>{group.label}</span>
<ChevronDown
size={13}
className={`shrink-0 transition-transform duration-200 ${folded ? '-rotate-90' : ''}`}
className={folded ? 'is-folded' : ''}
aria-hidden='true'
/>
</button>
) : (
gi > 0 && (
<div className='mx-2 mb-3 h-px bg-gray-200/50 dark:bg-neutral-700/50' />
)
)}
{/* grid-rows 0fr→1fr 实现平滑的折叠动画 */}
<div
className={`grid transition-[grid-template-rows] duration-200 ease-out ${
folded && !collapsed ? 'grid-rows-[0fr]' : 'grid-rows-[1fr]'
}`}
>
<div className='overflow-hidden'>
<div className='space-y-1.5 pb-0.5'>
{group.items.map((item) => {
const isSelected = selectedKey === item.itemKey;
const IconComponent = item.icon;
return (
<Link
key={item.itemKey}
to={item.itemKey}
onClick={() => onNavigate?.()}
data-active={isSelected || undefined}
className={`
group relative flex items-center gap-3 rounded-lg transition-colors duration-200
${collapsed ? 'justify-center p-3' : 'px-3 py-2'}
${
isSelected
? 'bg-brand/10 dark:bg-brand/15'
: 'hover:bg-brand/5 dark:hover:bg-brand/10'
}
`}
>
{isSelected && (
<div className='absolute left-0 top-1/2 -translate-y-1/2 w-0.5 h-5 rounded-r-full bg-brand transition-all duration-200' />
<div className='ui-org-group-items' hidden={folded && !collapsed}>
{group.items.map((item) => {
const isSelected = selectedKey === item.itemKey;
const IconComponent = item.icon;
return (
<Link
key={item.itemKey}
to={item.itemKey}
onClick={() => onNavigate?.()}
data-active={isSelected || undefined}
aria-current={isSelected ? 'page' : undefined}
title={collapsed ? item.text : undefined}
className='ui-center-menu-item'
>
<IconComponent
size={16}
strokeWidth={1.5}
aria-hidden='true'
/>
{!collapsed && (
<>
<span className='ui-center-menu-label'>
{item.text}
</span>
{item.beta && (
<span className='ui-org-beta'>BETA</span>
)}
<div
className={`
relative flex-shrink-0 p-1.5 rounded-lg transition-colors duration-200
${
isSelected
? 'bg-brand text-white'
: 'text-gray-500 dark:text-gray-400 group-hover:text-brand-deep dark:group-hover:text-brand-from'
}
`}
>
<IconComponent size={18} strokeWidth={2} />
</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'
}
`}
>
{renderItemText(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 dark:border-orange-700/50 dark:bg-orange-950/40 dark:text-orange-300'>
BETA
</span>
)}
</span>
)}
{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>
);
})}
</div>
</div>
</>
)}
</Link>
);
})}
</div>
</div>
);
})}
</nav>
{/* 底部分隔线 */}
{!mobile && (
<div className='mx-4 h-px bg-gradient-to-r from-transparent via-gray-200/60 dark:via-neutral-700/60 to-transparent' />
<button
type='button'
onClick={toggleCollapsed}
className='ui-center-sidebar-collapse'
aria-label={collapsed ? t('展开导航') : t('收起导航')}
>
{collapsed ? <ChevronRight size={16} /> : <ChevronLeft size={16} />}
{!collapsed && <span>{t('收起导航')}</span>}
</button>
)}
{/* 折叠按钮(移动端抽屉里不显示) */}
{!mobile && (
<div className='relative p-3'>
<button
onClick={toggleCollapsed}
className={`
flex items-center justify-center gap-2 w-full py-2 rounded-lg
text-gray-500 dark:text-gray-400 text-sm font-medium
border border-[var(--border-subtle)]
hover:bg-brand/10 dark:hover:bg-brand/15
hover:text-brand-deep dark:hover:text-brand-from
hover:border-brand/30 transition-colors duration-200
${collapsed ? 'px-2' : 'px-3'}
`}
>
{collapsed ? (
<ChevronRight size={16} strokeWidth={2.5} />
) : (
<>
<ChevronLeft size={16} strokeWidth={2.5} />
<span>{t('收起')}</span>
</>
)}
</button>
</div>
)}
</div>
</aside>
);
};