fix: 修复顶部导航和侧边栏菜单连点bug,封装公共侧边栏菜单组件并统一ui样式与交互

This commit is contained in:
zhanjunhao
2026-11-27 18:58:52 +08:00
parent 1e7780bdce
commit 6e41115d40
26 changed files with 875 additions and 805 deletions
+8
View File
@@ -10,6 +10,14 @@
## 2026-11-27 ## 2026-11-27
### 统一页面级侧栏并修复高频连点
- **范围** 体验中心、用户中心、控制台、企业中心、文档和伙伴工作台。
- **变更** 页面链接去重与节流,统一侧栏外壳、菜单项、分组、折叠和加载占位。
- **影响** 当前项连点不再重复写入导航历史,桌面折叠偏好跨页面同步,移动抽屉与底栏保留各自的入口。
- **回滚** 恢复本次侧栏组件、样式和交互 hook。
- **关联** 全站 UI 基线第 4.3 节。
### 优化右侧顶栏快捷操作 ### 优化右侧顶栏快捷操作
- **范围** 顶栏教程、WeyAi 下载、充值、推广、主题、语言和头像菜单。 - **范围** 顶栏教程、WeyAi 下载、充值、推广、主题、语言和头像菜单。
+3 -2
View File
@@ -65,8 +65,9 @@
### 4.3 侧栏 ### 4.3 侧栏
- 控制台侧栏显示、路由选中项变化或滚动区尺寸变化后,当前菜单超出可视范围时,仅滚动菜单区域使其完整可见;已可见时不移动,不滚动正文、不抢焦点,也不强制展开用户手动收起的分组。 - 页面级侧栏共用 `CenterSidebar` 和 `src/styles/center-layout.css`:展开 216px、收起 64px;菜单行高 42px、行距 6px,图标 16px / 1.5px 线宽;折叠入口文案“收起导航”。抽屉保留完整文字,窄屏的底部或横向导航沿用各页面的布局。
- 企业中心与用户中心共用 `src/styles/center-layout.css`:展开 216px、收起 64px;菜单行高 42px、行距 6px,图标 16px / 1.5px 线宽;折叠入口文案“收起导航”。 - 当前菜单超出可视范围时,仅滚动菜单区域使其完整可见;已可见时不移动。侧栏使用当前路由去重,快速切换保留最新目标。折叠按钮和分组操作过滤同一控件的连点。
- 体验、用户、控制台和企业中心的加载占位复用侧栏外壳,保持宽度、菜单起点及底部折叠条位置。企业身份和分组标题保留对应占位。
- 企业信息区为无底框网格图标(24px / 1.65 线宽),内边距 28px 16px 26px,图文间距 10px;企业名与身份 12px / 20px 行高,身份上距 2px。 - 企业信息区为无底框网格图标(24px / 1.65 线宽),内边距 28px 16px 26px,图文间距 10px;企业名与身份 12px / 20px 行高,身份上距 2px。
- 个人侧栏只保留容器外侧分隔线,内层 Menu 不叠加 `border-inline-end`;企业侧栏不提供菜单搜索。 - 个人侧栏只保留容器外侧分隔线,内层 Menu 不叠加 `border-inline-end`;企业侧栏不提供菜单搜索。
- 内容外壳设 `min-width: 0`,防止宽表格挤压;桌面滚动区保留稳定槽位并补足 16px 留白,移动端不补。 - 内容外壳设 `min-width: 0`,防止宽表格挤压;桌面滚动区保留稳定槽位并补足 16px 留白,移动端不补。
+6 -5
View File
@@ -515,7 +515,9 @@ function App() {
element={ element={
CLOUD_BRAIN_UI_ENABLED ? ( CLOUD_BRAIN_UI_ENABLED ? (
<PrivateRoute> <PrivateRoute>
<Suspense fallback={<Loading />} key={location.pathname}> <Suspense
fallback={<CenterRouteLoading variant='experience' />}
>
<ExperienceCenter /> <ExperienceCenter />
</Suspense> </Suspense>
</PrivateRoute> </PrivateRoute>
@@ -530,14 +532,13 @@ function App() {
moduleAuthConfig.experienceCenter ? ( moduleAuthConfig.experienceCenter ? (
<PrivateRoute> <PrivateRoute>
<Suspense <Suspense
fallback={<Loading></Loading>} fallback={<CenterRouteLoading variant='experience' />}
key={location.pathname}
> >
<ExperienceCenter /> <ExperienceCenter />
</Suspense> </Suspense>
</PrivateRoute> </PrivateRoute>
) : ( ) : (
<Suspense fallback={<Loading></Loading>} key={location.pathname}> <Suspense fallback={<CenterRouteLoading variant='experience' />}>
<ExperienceCenter /> <ExperienceCenter />
</Suspense> </Suspense>
) )
@@ -960,7 +961,7 @@ function App() {
element={ element={
<PrivateRoute> <PrivateRoute>
{isOrgCenterAvailable ? ( {isOrgCenterAvailable ? (
<Suspense fallback={<CenterRouteLoading />}> <Suspense fallback={<CenterRouteLoading variant='org' />}>
<Organization /> <Organization />
</Suspense> </Suspense>
) : ( ) : (
+9 -2
View File
@@ -12,6 +12,7 @@ import React, {
} from 'react'; } from 'react';
import { useIsMobile } from '../../hooks/common/useIsMobile'; import { useIsMobile } from '../../hooks/common/useIsMobile';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed'; import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
import { useSidebarToggleGuard } from '../../hooks/common/useSidebarToggleGuard';
import { CenterSidebarLoading } from './components/CenterSidebarLoading'; import { CenterSidebarLoading } from './components/CenterSidebarLoading';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { API } from '../../helpers/api'; import { API } from '../../helpers/api';
@@ -67,6 +68,7 @@ const PageLayout = () => {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const [collapsed] = useSidebarCollapsed(); const [collapsed] = useSidebarCollapsed();
const [drawerOpen, setDrawerOpen] = useState(false); const [drawerOpen, setDrawerOpen] = useState(false);
const canToggleSidebar = useSidebarToggleGuard();
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const location = useLocation(); const location = useLocation();
@@ -360,7 +362,9 @@ const PageLayout = () => {
> >
<Suspense fallback={null}> <Suspense fallback={null}>
<HeaderBar <HeaderBar
onMobileMenuToggle={() => setDrawerOpen((prev) => !prev)} onMobileMenuToggle={() => {
if (canToggleSidebar('drawer')) setDrawerOpen((open) => !open);
}}
drawerOpen={drawerOpen} drawerOpen={drawerOpen}
/> />
</Suspense> </Suspense>
@@ -418,7 +422,10 @@ const PageLayout = () => {
> >
<Suspense <Suspense
fallback={ fallback={
<CenterSidebarLoading forceExpanded={siderForceExpanded} /> <CenterSidebarLoading
variant='console'
forceExpanded={siderForceExpanded}
/>
} }
> >
<SiderBar <SiderBar
+87 -198
View File
@@ -1,16 +1,12 @@
import {
ChevronDown as ActionChevronDown,
ChevronRight as ActionChevronRight,
ChevronLeft as ActionChevronLeft,
} from '@/components/common/icons/ActionIcons';
import { consoleMenuPaths, getConsoleMenuKeys } from '../console/consoleRoutes'; import { consoleMenuPaths, getConsoleMenuKeys } from '../console/consoleRoutes';
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'; import React, { useContext, useEffect, useMemo, useState } from 'react';
import { revealActiveSidebarItem } from '../../helpers/sidebarScroll'; import { useLocation } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { getLucideIcon } from '../../helpers/render'; import { getLucideIcon } from '../../helpers/render';
import '../../styles/center-layout.css'; import '../../styles/center-layout.css';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed'; import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
import { useSidebarNavigation } from '../../hooks/common/useTopNavigation';
import { useSidebarGroups } from '../../hooks/common/useSidebarGroups';
import { useSidebar } from '../../hooks/common/useSidebar'; import { useSidebar } from '../../hooks/common/useSidebar';
import { usePartnerWorkspaceEntry } from '../../hooks/common/usePartnerWorkspaceEntry'; import { usePartnerWorkspaceEntry } from '../../hooks/common/usePartnerWorkspaceEntry';
import { isAdmin, isRoot, showError } from '../../helpers'; import { isAdmin, isRoot, showError } from '../../helpers';
@@ -28,6 +24,12 @@ import {
loadPersonalConsentGranted, loadPersonalConsentGranted,
readPersonalConsentCache, readPersonalConsentCache,
} from '../smart-router/api'; } from '../smart-router/api';
import {
CenterSidebar,
CenterSidebarGroup,
CenterSidebarItem,
CenterSidebarSubmenu,
} from './components/CenterSidebar';
import { CenterSidebarLoading } from './components/CenterSidebarLoading'; import { CenterSidebarLoading } from './components/CenterSidebarLoading';
import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi'; import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi';
import { useAuthzView, usePerm } from '../../authz'; import { useAuthzView, usePerm } from '../../authz';
@@ -57,6 +59,7 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [persistedCollapsed, toggleCollapsed] = useSidebarCollapsed(); const [persistedCollapsed, toggleCollapsed] = useSidebarCollapsed();
const collapsed = forceExpanded ? false : persistedCollapsed; const collapsed = forceExpanded ? false : persistedCollapsed;
const followSidebarLink = useSidebarNavigation(onNavigate);
const { const {
isModuleVisible, isModuleVisible,
hasSectionVisibleModules, hasSectionVisibleModules,
@@ -99,7 +102,6 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
}, [platformView]); }, [platformView]);
const [selectedKeys, setSelectedKeys] = useState(['home']); const [selectedKeys, setSelectedKeys] = useState(['home']);
const navigationRef = useRef(null);
// 平台关闭智能路由后,仍有生效中出境同意的普通用户保留入口以便撤回(§9.5,与企业"仅授权模式"同口径) // 平台关闭智能路由后,仍有生效中出境同意的普通用户保留入口以便撤回(§9.5,与企业"仅授权模式"同口径)
const [routerConsentGranted, setRouterConsentGranted] = useState( const [routerConsentGranted, setRouterConsentGranted] = useState(
() => readPersonalConsentCache() === '1', () => readPersonalConsentCache() === '1',
@@ -120,8 +122,9 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
}; };
}, [smartRouterEnabled]); }, [smartRouterEnabled]);
const [chatItems, setChatItems] = useState([]); const [chatItems, setChatItems] = useState([]);
const [openedKeys, setOpenedKeys] = useState([]); const submenus = useSidebarGroups();
const [foldedGroups, setFoldedGroups] = useState([]); const groups = useSidebarGroups();
const { setGroup: setSubmenu } = submenus;
const location = useLocation(); const location = useLocation();
const [routerMapState, setRouterMapState] = useState(routerMap); const [routerMapState, setRouterMapState] = useState(routerMap);
@@ -549,9 +552,7 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
setSelectedKeys([ setSelectedKeys([
validChildKeys.includes(childKey) ? childKey : 'commission-overview', validChildKeys.includes(childKey) ? childKey : 'commission-overview',
]); ]);
setOpenedKeys((keys) => setSubmenu('commission', true);
keys.includes('commission') ? keys : [...keys, 'commission'],
);
return; return;
} }
let matchingKeys = getConsoleMenuKeys(currentPath, routerMapState); let matchingKeys = getConsoleMenuKeys(currentPath, routerMapState);
@@ -570,39 +571,7 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
if (matchingKeys.length) { if (matchingKeys.length) {
setSelectedKeys(matchingKeys); setSelectedKeys(matchingKeys);
} }
}, [location.pathname, location.search, routerMapState]); }, [location.pathname, location.search, routerMapState, setSubmenu]);
useEffect(() => {
const navigation = navigationRef.current;
if (!navigation || sidebarLoading) return;
let frame;
const scheduleReveal = () => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(() => revealActiveSidebarItem(navigation));
};
scheduleReveal();
const resizeObserver = new ResizeObserver(scheduleReveal);
resizeObserver.observe(navigation);
const mutationObserver = new MutationObserver(scheduleReveal);
mutationObserver.observe(navigation, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['hidden'],
});
return () => {
cancelAnimationFrame(frame);
resizeObserver.disconnect();
mutationObserver.disconnect();
};
}, [
sidebarLoading,
selectedKeys,
collapsed,
forceExpanded,
openedKeys,
foldedGroups,
]);
const renderMenuIcon = (key) => const renderMenuIcon = (key) =>
React.cloneElement(getLucideIcon(key), { React.cloneElement(getLucideIcon(key), {
@@ -614,186 +583,106 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
}); });
const renderGroup = (key, label, items) => ( const renderGroup = (key, label, items) => (
<div key={key} className='ui-org-nav-group'> <CenterSidebarGroup
{!collapsed && ( key={key}
<button label={label}
type='button' collapsed={collapsed}
className='app-action-button ui-org-group-toggle' folded={groups.keys.includes(key)}
aria-expanded={!foldedGroups.includes(key)} onToggle={() => groups.toggle(key)}
onClick={() => >
setFoldedGroups((previous) => {items}
previous.includes(key) </CenterSidebarGroup>
? previous.filter((group) => group !== key)
: [...previous, key],
)
}
>
<span>{label}</span>
<ActionChevronDown
size={13}
className={foldedGroups.includes(key) ? 'is-folded' : ''}
aria-hidden='true'
/>
</button>
)}
<div
className='ui-org-group-items'
hidden={!collapsed && foldedGroups.includes(key)}
>
{items}
</div>
</div>
); );
// nested:二级菜单项(无图标,靠缩进与引导线表达层级);forceActive:收起态父项代表任一子项选中
const renderNavItem = ( const renderNavItem = (
item, item,
{ nested = false, forceActive = false } = {}, { nested = false, forceActive = false } = {},
) => { ) => {
if (item.className === 'tableHiddle') return null; if (item.className === 'tableHiddle') return null;
const active = forceActive || selectedKeys.includes(item.itemKey); const to = routerMapState[item.itemKey] || routerMap[item.itemKey] || '#';
return ( return (
<Link <CenterSidebarItem
key={item.itemKey} key={item.itemKey}
to={routerMapState[item.itemKey] || routerMap[item.itemKey] || '#'} to={to}
onClick={onNavigate} label={item.text}
className={`ui-center-menu-item${nested ? ' ui-console-submenu-item' : ''}`} active={forceActive || selectedKeys.includes(item.itemKey)}
data-active={active || undefined} collapsed={collapsed}
aria-current={active ? 'page' : undefined} nested={nested}
title={collapsed ? item.text : undefined} icon={!nested && renderMenuIcon(item.itemKey)}
> onClick={(event) => followSidebarLink(to, event)}
{!nested && renderMenuIcon(item.itemKey)} />
{!collapsed && (
<span className='ui-center-menu-label'>{item.text}</span>
)}
</Link>
); );
}; };
const renderSubItem = (item) => { const renderSubItem = (item) => {
if (!item.items?.length) return renderNavItem(item); if (!item.items?.length) return renderNavItem(item);
const open = openedKeys.includes(item.itemKey);
const childActive = item.items.some((child) => const childActive = item.items.some((child) =>
selectedKeys.includes(child.itemKey), selectedKeys.includes(child.itemKey),
); );
// 收起态没有展开空间:父项作为入口直达模块首页,任一子项选中时父项高亮 if (collapsed) return renderNavItem(item, { forceActive: childActive });
if (collapsed) {
return renderNavItem(
{ ...item, items: undefined },
{ forceActive: childActive },
);
}
const groupId = `ui-console-submenu-${item.itemKey}`;
return ( return (
<div key={item.itemKey} className='ui-console-submenu'> <CenterSidebarSubmenu
<button key={item.itemKey}
type='button' label={item.text}
className='ui-center-menu-item ui-console-submenu-toggle' icon={renderMenuIcon(item.itemKey)}
data-child-active={childActive || undefined} open={submenus.keys.includes(item.itemKey)}
aria-expanded={open} childActive={childActive}
aria-controls={groupId} onToggle={() => submenus.toggle(item.itemKey)}
onClick={() => >
setOpenedKeys((previous) => {item.items.map((child) => renderNavItem(child, { nested: true }))}
previous.includes(item.itemKey) </CenterSidebarSubmenu>
? previous.filter((key) => key !== item.itemKey)
: [...previous, item.itemKey],
)
}
>
{renderMenuIcon(item.itemKey)}
<span className='ui-center-menu-label'>{item.text}</span>
<ActionChevronDown
size={14}
className='ui-console-submenu-arrow'
aria-hidden
/>
</button>
<div
id={groupId}
role='group'
aria-label={item.text}
className='ui-org-group-items ui-console-submenu-items'
hidden={!open}
>
{item.items.map((child) => renderNavItem(child, { nested: true }))}
</div>
</div>
); );
}; };
if (sidebarLoading) if (sidebarLoading)
return <CenterSidebarLoading forceExpanded={forceExpanded} />; return (
<CenterSidebarLoading variant='console' forceExpanded={forceExpanded} />
);
return ( return (
<div <CenterSidebar
className='ui-console-sidebar ui-center-sidebar' className='ui-console-sidebar'
data-collapsed={collapsed} collapsed={collapsed}
style={{ mobile={forceExpanded}
width: forceExpanded onToggle={toggleCollapsed}
? 'var(--sidebar-width)'
: 'var(--sidebar-current-width)',
background: 'var(--surface-sidebar)',
}}
> >
<nav ref={navigationRef} className='ui-center-sidebar-nav'> {/* 聊天区域 */}
{/* 聊天区域 */} {hasSectionVisibleModules('chat') &&
{hasSectionVisibleModules('chat') && renderGroup('chat-group', t('聊天'), chatMenuItems.map(renderSubItem))}
renderGroup(
'chat-group',
t('聊天'),
chatMenuItems.map(renderSubItem),
)}
{/* 控制台区域 */} {/* 控制台区域 */}
{hasSectionVisibleModules('console') && {hasSectionVisibleModules('console') &&
renderGroup( renderGroup(
'console-group', 'console-group',
t('控制台'), t('控制台'),
workspaceItems.map((item) => renderNavItem(item)), workspaceItems.map((item) => renderNavItem(item)),
)} )}
{/* 个人中心区域 */} {/* 个人中心区域 */}
{hasSectionVisibleModules('personal') && {hasSectionVisibleModules('personal') &&
renderGroup( renderGroup(
'personal-group', 'personal-group',
t('个人中心'), t('个人中心'),
financeItems.map((item) => renderNavItem(item)), financeItems.map((item) => renderNavItem(item)),
)} )}
{/* 管理员区域:按角色、权限下放及菜单配置过滤。分佣管理为子菜单,走 renderSubItem。 */} {/* 管理员区域:按角色、权限下放及菜单配置过滤。分佣管理为子菜单,走 renderSubItem。 */}
{(isAdmin() || visibleAdminItems.length > 0) && {(isAdmin() || visibleAdminItems.length > 0) &&
renderGroup( renderGroup(
'admin-group', 'admin-group',
t('管理员'), t('管理员'),
visibleAdminItems.map(renderSubItem), visibleAdminItems.map(renderSubItem),
)} )}
{/* 权限管理区域:至少有一项可见时显示 */} {/* 权限管理区域:至少有一项可见时显示 */}
{authzItems.length > 0 && {authzItems.length > 0 &&
renderGroup( renderGroup(
'authz-group', 'authz-group',
t('权限管理'), t('权限管理'),
authzItems.map((item) => renderNavItem(item)), authzItems.map((item) => renderNavItem(item)),
)} )}
</nav> </CenterSidebar>
{/* 底部折叠按钮 —— 抽屉态不提供:收起后抽屉会变成 60px 窄条,等于自废 */}
{!forceExpanded && (
<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>
)}
</div>
); );
}; };
@@ -0,0 +1,192 @@
import React, { useEffect, useId, useRef } from 'react';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import {
ChevronDown,
ChevronLeft,
ChevronRight,
} from '@/components/common/icons/ActionIcons';
import { revealActiveSidebarItem } from '../../../helpers/sidebarScroll';
export function CenterSidebar({
children,
className = '',
collapsed = false,
loading = false,
mobile = false,
header,
footer,
onToggle,
label,
navigationClassName = '',
}) {
const { t } = useTranslation();
const navigation = useRef(null);
const navId = useId();
useEffect(() => {
const node = navigation.current;
if (loading || !node) return;
let frame;
const schedule = () => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(() => revealActiveSidebarItem(node));
};
const resize = new ResizeObserver(schedule);
resize.observe(node);
const mutation = new MutationObserver(schedule);
mutation.observe(node, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ['aria-current', 'hidden'],
});
schedule();
return () => {
cancelAnimationFrame(frame);
resize.disconnect();
mutation.disconnect();
};
}, [collapsed, loading]);
const CollapseIcon = collapsed ? ChevronRight : ChevronLeft;
return (
<aside
className={`ui-center-sidebar ${className}`}
data-collapsed={collapsed}
data-mobile={mobile || undefined}
aria-busy={loading || undefined}
>
{header}
<nav
id={navId}
ref={navigation}
className={`ui-center-sidebar-nav ${navigationClassName}`}
aria-label={label || t('主导航')}
>
{children}
</nav>
{footer}
{onToggle && !mobile && (
<button
type='button'
className='app-action-button ui-center-sidebar-collapse'
onClick={onToggle}
aria-controls={navId}
aria-expanded={!collapsed}
aria-label={collapsed ? t('展开导航') : t('收起导航')}
>
<CollapseIcon size={16} aria-hidden='true' />
{!collapsed && <span>{t('收起导航')}</span>}
</button>
)}
</aside>
);
}
export function CenterSidebarItem({
to,
label,
icon,
active,
collapsed,
nested,
trailing,
className = '',
...props
}) {
const Element = to ? Link : 'button';
return (
<Element
{...(to ? { to } : { type: 'button' })}
className={`ui-center-menu-item${nested ? ' ui-console-submenu-item' : ''} ${className}`}
data-active={active || undefined}
aria-current={active ? 'page' : undefined}
aria-label={collapsed ? label : undefined}
title={collapsed ? label : undefined}
{...props}
>
{icon}
{!collapsed && <span className='ui-center-menu-label'>{label}</span>}
{trailing}
</Element>
);
}
export function CenterSidebarGroup({
children,
label,
collapsed,
folded,
onToggle,
}) {
const id = useId();
return (
<div className='ui-org-nav-group'>
{!collapsed && (
<button
type='button'
className='app-action-button ui-org-group-toggle'
aria-controls={id}
aria-expanded={!folded}
onClick={onToggle}
>
<span>{label}</span>
<ChevronDown
size={13}
className={folded ? 'is-folded' : ''}
aria-hidden='true'
/>
</button>
)}
<div id={id} className='ui-org-group-items' hidden={!collapsed && folded}>
{children}
</div>
</div>
);
}
export function CenterSidebarSubmenu({
children,
label,
icon,
collapsed,
open,
childActive,
onToggle,
className = '',
}) {
const id = useId();
return (
<div className={`ui-console-submenu ${className}`}>
<CenterSidebarItem
className='ui-console-submenu-toggle'
icon={icon}
label={label}
collapsed={collapsed}
data-child-active={childActive || undefined}
aria-expanded={open}
aria-controls={id}
onClick={onToggle}
trailing={
!collapsed && (
<ChevronDown
size={14}
className='ui-console-submenu-arrow'
aria-hidden='true'
/>
)
}
/>
<div
id={id}
role='group'
aria-label={label}
className='ui-org-group-items ui-console-submenu-items'
hidden={!open}
>
{children}
</div>
</div>
);
}
@@ -1,25 +1,56 @@
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useSidebarCollapsed } from '../../../hooks/common/useSidebarCollapsed'; import { useSidebarCollapsed } from '../../../hooks/common/useSidebarCollapsed';
import { CenterSidebar } from './CenterSidebar';
const rows = [0, 1, 2, 3, 4, 5]; const rows = [0, 1, 2, 3, 4, 5];
export function CenterSidebarLoading({ forceExpanded = false }) { export function CenterSidebarLoading({
const [collapsed] = useSidebarCollapsed(); forceExpanded = false,
const { t } = useTranslation(); variant = 'user',
}) {
const [persistedCollapsed] = useSidebarCollapsed();
const collapsed = !forceExpanded && persistedCollapsed;
const identity = variant === 'org' && !collapsed;
const grouped = !collapsed && (variant === 'org' || variant === 'console');
return ( return (
<div <CenterSidebar
className='ui-center-sidebar ui-center-sidebar-placeholder' className={`ui-${variant}-sidebar ui-center-sidebar-placeholder`}
data-collapsed={!forceExpanded && collapsed} collapsed={collapsed}
data-mobile={forceExpanded || undefined} mobile={forceExpanded}
aria-busy='true' loading
aria-label={t('主导航')} header={
identity && (
<div
className='ui-org-identity ui-center-sidebar-placeholder-identity'
aria-hidden='true'
>
<span />
<span />
</div>
)
}
footer={
!forceExpanded && (
<div
className='ui-center-sidebar-placeholder-footer'
aria-hidden='true'
>
<span />
</div>
)
}
> >
<div <div
className='ui-center-sidebar-nav ui-center-sidebar-placeholder-rows' className='ui-org-group-items ui-center-sidebar-placeholder-rows'
aria-hidden='true' aria-hidden='true'
> >
{grouped && (
<div className='ui-center-sidebar-placeholder-group'>
<span />
</div>
)}
{rows.map((row) => ( {rows.map((row) => (
<div key={row} className='ui-center-menu-item'> <div key={row} className='ui-center-menu-item'>
<span /> <span />
@@ -27,25 +58,17 @@ export function CenterSidebarLoading({ forceExpanded = false }) {
</div> </div>
))} ))}
</div> </div>
{!forceExpanded && ( </CenterSidebar>
<div
className='ui-center-sidebar-placeholder-footer'
aria-hidden='true'
>
<span />
</div>
)}
</div>
); );
} }
export function CenterRouteLoading() { export function CenterRouteLoading({ variant }) {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<div className='ui-center-route-loading' role='status'> <div className='ui-center-route-loading' role='status'>
<div className='hidden md:block'> <div className='hidden md:block'>
<CenterSidebarLoading /> <CenterSidebarLoading variant={variant} />
</div> </div>
<div className='ui-center-route-loading-body'>{t('加载中...')}</div> <div className='ui-center-route-loading-body'>{t('加载中...')}</div>
</div> </div>
+5
View File
@@ -1,6 +1,8 @@
import { useCallback, useSyncExternalStore } from 'react'; import { useCallback, useSyncExternalStore } from 'react';
const KEY = 'default_collapse_sidebar'; const KEY = 'default_collapse_sidebar';
const TOGGLE_INTERVAL = 180;
let lastToggleAt = -Infinity;
/* /*
* 侧栏折叠态是「一份跨组件共享的状态」,不能用 useState—— * 侧栏折叠态是「一份跨组件共享的状态」,不能用 useState——
@@ -65,6 +67,9 @@ export const useSidebarCollapsed = () => {
); );
const toggle = useCallback(() => { const toggle = useCallback(() => {
const now = performance.now();
if (now - lastToggleAt < TOGGLE_INTERVAL) return;
lastToggleAt = now;
setCollapsedState(!collapsedState); setCollapsedState(!collapsedState);
}, []); }, []);
+44
View File
@@ -0,0 +1,44 @@
import { useCallback, useRef, useState } from 'react';
import { useSidebarToggleGuard } from './useSidebarToggleGuard';
function readGroups(storageKey) {
if (!storageKey) return [];
try {
const saved = JSON.parse(localStorage.getItem(storageKey));
return Array.isArray(saved) ? saved : [];
} catch {
return [];
}
}
export function useSidebarGroups(storageKey) {
const [keys, setKeys] = useState(() => readGroups(storageKey));
const current = useRef(keys);
const canToggle = useSidebarToggleGuard();
const setGroup = useCallback(
(key, included, persist = false) => {
const previous = current.current;
if (!key || previous.includes(key) === included) return;
const next = included
? [...previous, key]
: previous.filter((item) => item !== key);
current.current = next;
setKeys(next);
if (persist && storageKey) {
try {
localStorage.setItem(storageKey, JSON.stringify(next));
} catch {
// Keep the in-memory preference if storage is unavailable.
}
}
},
[storageKey],
);
const toggle = (key) => {
if (canToggle(key)) setGroup(key, !current.current.includes(key), true);
};
return { keys, toggle, setGroup };
}
+16
View File
@@ -0,0 +1,16 @@
import { useCallback, useRef } from 'react';
const TOGGLE_INTERVAL = 180;
export function useSidebarToggleGuard() {
const lastToggle = useRef(new Map());
return useCallback((key) => {
const now = performance.now();
if (now - (lastToggle.current.get(key) ?? -Infinity) < TOGGLE_INTERVAL) {
return false;
}
lastToggle.current.set(key, now);
return true;
}, []);
}
+13 -3
View File
@@ -6,6 +6,14 @@ const NAVIGATION_INTERVAL = 180;
const normalizePathname = (path) => path.replace(/\/+$/, '') || '/'; const normalizePathname = (path) => path.replace(/\/+$/, '') || '/';
export function useTopNavigation() { export function useTopNavigation() {
return useThrottledNavigation();
}
export function useSidebarNavigation(onNavigate) {
return useThrottledNavigation({ exact: true, onNavigate });
}
function useThrottledNavigation({ exact = false, onNavigate } = {}) {
const location = useLocation(); const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const timer = useRef(); const timer = useRef();
@@ -18,7 +26,7 @@ export function useTopNavigation() {
!to || !to ||
event?.defaultPrevented || event?.defaultPrevented ||
(event && (event &&
(event.button !== 0 || ((event.button != null && event.button !== 0) ||
event.metaKey || event.metaKey ||
event.altKey || event.altKey ||
event.ctrlKey || event.ctrlKey ||
@@ -34,9 +42,10 @@ export function useTopNavigation() {
if ( if (
normalizePathname(target.pathname) === normalizePathname(target.pathname) ===
normalizePathname(current.pathname) && normalizePathname(current.pathname) &&
(!target.search || target.search === current.search) && (target.search === current.search || (!exact && !target.search)) &&
(!target.hash || target.hash === current.hash) (target.hash === current.hash || (!exact && !target.hash))
) { ) {
onNavigate?.();
return; return;
} }
@@ -46,6 +55,7 @@ export function useTopNavigation() {
if (window.history.state?.key !== originKey) return; if (window.history.state?.key !== originKey) return;
lastNavigationAt.current = performance.now(); lastNavigationAt.current = performance.now();
navigate(to); navigate(to);
onNavigate?.();
}; };
const wait = const wait =
NAVIGATION_INTERVAL - (performance.now() - lastNavigationAt.current); NAVIGATION_INTERVAL - (performance.now() - lastNavigationAt.current);
+54 -20
View File
@@ -49,6 +49,13 @@ import {
import { BillingColumns, AdjustmentColumns } from './operations'; import { BillingColumns, AdjustmentColumns } from './operations';
import { commissionLabel } from './labels'; import { commissionLabel } from './labels';
import { PARTNER_NAVIGATION, partnerView } from './partnerNavigation'; import { PARTNER_NAVIGATION, partnerView } from './partnerNavigation';
import { useSidebarToggleGuard } from '../../hooks/common/useSidebarToggleGuard';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
import { useIsMobile } from '../../hooks/common/useIsMobile';
import {
CenterSidebar,
CenterSidebarItem,
} from '../../components/layout/components/CenterSidebar';
import './partnerPortal.css'; import './partnerPortal.css';
import OrgPageHeader from '../Organization/components/OrgPageHeader'; import OrgPageHeader from '../Organization/components/OrgPageHeader';
import OrgModal from '../Organization/components/OrgModal'; import OrgModal from '../Organization/components/OrgModal';
@@ -100,6 +107,10 @@ export default function PartnerPortal({
const [searchParams, setSearchParams] = useSearchParams(); const [searchParams, setSearchParams] = useSearchParams();
const [localActive, setLocalActive] = useState('overview'); const [localActive, setLocalActive] = useState('overview');
const active = embedded ? partnerView(location.search) : localActive; const active = embedded ? partnerView(location.search) : localActive;
const canChangeSidebarTab = useSidebarToggleGuard();
const mobile = useIsMobile();
const [persistedCollapsed, toggleCollapsed] = useSidebarCollapsed();
const sidebarCollapsed = !mobile && persistedCollapsed;
const internalSearch = useRef(null); const internalSearch = useRef(null);
const setActive = (key) => { const setActive = (key) => {
if (!embedded) { if (!embedded) {
@@ -1307,31 +1318,54 @@ export default function PartnerPortal({
className={`commission-v2 commission-admin-workspace partner-portal${embedded ? ' partner-portal--embedded' : ''}`} className={`commission-v2 commission-admin-workspace partner-portal${embedded ? ' partner-portal--embedded' : ''}`}
> >
{!embedded && ( {!embedded && (
<aside className='commission-v2-sider'> <CenterSidebar
<div className='commission-brand'> className='commission-v2-sider'
<span className='commission-brand-mark' /> navigationClassName='commission-navigation'
{t('合作分佣')} label={t('伙伴分佣导航')}
</div> collapsed={sidebarCollapsed}
<nav className='commission-navigation' aria-label={t('伙伴分佣导航')}> onToggle={mobile ? undefined : toggleCollapsed}
header={
!sidebarCollapsed && (
<div className='commission-brand'>
<span className='commission-brand-mark' />
{t('合作分佣')}
</div>
)
}
>
{!sidebarCollapsed && (
<div className='commission-nav-group'>{t('伙伴工作台')}</div> <div className='commission-nav-group'>{t('伙伴工作台')}</div>
)}
<div className='ui-org-group-items commission-nav-items'>
{NAVIGATION.map(({ key, label, icon: Icon }) => ( {NAVIGATION.map(({ key, label, icon: Icon }) => (
<button <CenterSidebarItem
type='button'
key={key} key={key}
className={`commission-nav-item${active === key ? ' is-active' : ''}`} label={t(label)}
aria-current={active === key ? 'page' : undefined} collapsed={sidebarCollapsed}
className='commission-nav-item'
active={active === key}
icon={<Icon size={16} strokeWidth={1.5} aria-hidden='true' />}
disabled={mutationLoading} disabled={mutationLoading}
onClick={() => navigate(key)} onClick={() => {
> if (
<Icon size={17} /> (active !== key || selected) &&
<span>{t(label)}</span> canChangeSidebarTab(key)
{key === 'bills' && pending.length > 0 && ( ) {
<span className='commission-nav-badge'>{pending.length}</span> navigate(key);
)} }
</button> }}
trailing={
key === 'bills' &&
pending.length > 0 && (
<span className='commission-nav-badge'>
{pending.length}
</span>
)
}
/>
))} ))}
</nav> </div>
</aside> </CenterSidebar>
)} )}
<Layout> <Layout>
<header className='commission-workspace-bar' hidden={embedded}> <header className='commission-workspace-bar' hidden={embedded}>
-5
View File
@@ -1,8 +1,3 @@
.partner-portal .commission-v2-sider {
width: 220px;
flex-basis: 220px;
}
/* Organization owns the global header, sidebar and scroll container. */ /* Organization owns the global header, sidebar and scroll container. */
.partner-portal-scope--embedded { .partner-portal-scope--embedded {
display: flex; display: flex;
+20 -47
View File
@@ -109,11 +109,9 @@
flex-direction: column; flex-direction: column;
min-width: 0; min-width: 0;
} }
.commission-v2-sider { .commission-v2-sider.ui-center-sidebar {
flex: 0 0 220px; flex: none;
width: 220px; height: auto;
background: var(--surface-sidebar);
border-right: 1px solid var(--border-subtle);
} }
.commission-brand { .commission-brand {
display: flex; display: flex;
@@ -141,41 +139,6 @@
color: var(--text-tertiary); color: var(--text-tertiary);
font-size: 12px; font-size: 12px;
} }
.commission-nav-item {
display: flex;
align-items: center;
gap: 10px;
width: 100%;
height: 38px;
margin: 2px 0;
padding: 0 12px;
border: 0;
border-radius: var(--commission-radius);
background: transparent;
color: var(--text-secondary);
font: inherit;
font-size: 14px;
text-align: left;
cursor: pointer;
}
.commission-nav-item svg {
flex-shrink: 0;
stroke-width: 2px;
}
.commission-nav-item:hover {
background: var(--surface-bg-base);
color: var(--text-primary);
}
.commission-nav-item.is-active {
background: var(--commission-primary-soft);
color: var(--commission-primary-readable);
font-weight: 500;
box-shadow: inset 2px 0 0 var(--commission-primary);
}
.commission-nav-item:focus-visible {
outline: 2px solid var(--commission-primary);
outline-offset: -2px;
}
.commission-nav-badge { .commission-nav-badge {
margin-left: auto; margin-left: auto;
padding: 0 6px; padding: 0 6px;
@@ -185,6 +148,16 @@
font-size: 12px; font-size: 12px;
line-height: 16px; line-height: 16px;
} }
.commission-v2-sider[data-collapsed='true'] .commission-nav-item {
position: relative;
}
.commission-v2-sider[data-collapsed='true'] .commission-nav-badge {
position: absolute;
inset-block-start: 2px;
inset-inline-end: 0;
}
.commission-workspace-bar { .commission-workspace-bar {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -736,10 +709,6 @@
padding-top: 12px; padding-top: 12px;
} }
@media (max-width: 1100px) { @media (max-width: 1100px) {
.commission-v2-sider {
flex-basis: 200px;
width: 200px;
}
.commission-page-header { .commission-page-header {
flex-wrap: wrap; flex-wrap: wrap;
} }
@@ -755,7 +724,7 @@
.commission-admin-workspace { .commission-admin-workspace {
flex-direction: column; flex-direction: column;
} }
.commission-v2-sider { .commission-v2-sider.ui-center-sidebar {
flex: 0 0 auto; flex: 0 0 auto;
width: 100%; width: 100%;
border-right: 0; border-right: 0;
@@ -764,7 +733,7 @@
.commission-brand { .commission-brand {
display: none; display: none;
} }
.commission-navigation { .commission-v2-sider .commission-navigation {
display: flex; display: flex;
gap: 4px; gap: 4px;
overflow-x: auto; overflow-x: auto;
@@ -773,8 +742,12 @@
.commission-nav-group { .commission-nav-group {
display: none; display: none;
} }
.commission-nav-item { .commission-nav-items:not([hidden]) {
flex-direction: row;
}
.commission-v2-sider button.commission-nav-item {
width: auto; width: auto;
padding-inline: 12px;
flex: 0 0 auto; flex: 0 0 auto;
} }
.commission-workspace-bar { .commission-workspace-bar {
+48 -37
View File
@@ -1,11 +1,29 @@
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js'; import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import {
BookOpen,
BrainCircuit,
Code,
Gem,
Download,
Lightbulb,
Columns2,
} from 'lucide-react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { copy, showError, showSuccess } from '../../helpers'; import { copy, showError, showSuccess } from '../../helpers';
import {
CenterSidebar,
CenterSidebarItem,
} from '../../components/layout/components/CenterSidebar';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
import { useIsMobile } from '../../hooks/common/useIsMobile';
import './styles.css'; import './styles.css';
const Docs = () => { const Docs = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const mobile = useIsMobile();
const [persistedCollapsed, toggleCollapsed] = useSidebarCollapsed();
const collapsed = !mobile && persistedCollapsed;
const contentRef = useRef(null); const contentRef = useRef(null);
const [activeTab, setActiveTab] = useState('overview'); const [activeTab, setActiveTab] = useState('overview');
const [activeOS, setActiveOS] = useState('windows'); const [activeOS, setActiveOS] = useState('windows');
@@ -13,13 +31,13 @@ const Docs = () => {
// 导航菜单配置 // 导航菜单配置
const navItems = [ const navItems = [
{ id: 'overview', icon: 'fa-home', label: t('概述') }, { id: 'overview', icon: BookOpen, label: t('概述') },
{ id: 'claude-code', icon: 'fa-brain', label: 'Claude Code' }, { id: 'claude-code', icon: BrainCircuit, label: 'Claude Code' },
{ id: 'codex', icon: 'fa-code', label: 'CodeX' }, { id: 'codex', icon: Code, label: 'CodeX' },
{ id: 'gemini', icon: 'fa-gem', label: 'Gemini CLI' }, { id: 'gemini', icon: Gem, label: 'Gemini CLI' },
{ id: 'deployment', icon: 'fa-download', label: t('部署指南') }, { id: 'deployment', icon: Download, label: t('部署指南') },
{ id: 'best-practices', icon: 'fa-lightbulb', label: t('最佳实践') }, { id: 'best-practices', icon: Lightbulb, label: t('最佳实践') },
{ id: 'comparison', icon: 'fa-chart-bar', label: t('工具对比') }, { id: 'comparison', icon: Columns2, label: t('工具对比') },
]; ];
// 复制代码功能:走公共 copy,HTTP 部署下 navigator.clipboard 为 undefined, // 复制代码功能:走公共 copy,HTTP 部署下 navigator.clipboard 为 undefined,
@@ -44,38 +62,31 @@ const Docs = () => {
return ( return (
<div className='mt-[60px]'> <div className='mt-[60px]'>
<div className='docs-container'> <div className='docs-container'>
{/* 左侧边栏 */} <CenterSidebar
<aside className='docs-sidebar'> className='docs-sidebar'
<nav className='docs-nav'> navigationClassName='docs-nav'
<div className='docs-nav-section'> collapsed={collapsed}
{navItems.slice(0, 4).map((item) => ( mobile={mobile}
<div onToggle={toggleCollapsed}
key={item.id} >
className={`docs-nav-item ${activeTab === item.id ? 'active' : ''}`} {[navItems.slice(0, 4), navItems.slice(4)].map((items) => (
onClick={() => setActiveTab(item.id)} <div
> key={items[0].id}
<i className={`fas ${item.icon}`}></i> className='ui-org-group-items docs-nav-section'
<span>{item.label}</span> >
</div> {items.map(({ id, label, icon: Icon }) => (
<CenterSidebarItem
key={id}
label={label}
icon={<Icon size={16} strokeWidth={1.5} aria-hidden='true' />}
collapsed={collapsed}
active={activeTab === id}
onClick={() => setActiveTab(id)}
/>
))} ))}
</div> </div>
))}
<div className='docs-nav-divider'></div> </CenterSidebar>
<div className='docs-nav-section'>
{navItems.slice(4).map((item) => (
<div
key={item.id}
className={`docs-nav-item ${activeTab === item.id ? 'active' : ''}`}
onClick={() => setActiveTab(item.id)}
>
<i className={`fas ${item.icon}`}></i>
<span>{item.label}</span>
</div>
))}
</div>
</nav>
</aside>
{/* 右侧内容区域 */} {/* 右侧内容区域 */}
<main className='docs-content' ref={contentRef}> <main className='docs-content' ref={contentRef}>
+18 -87
View File
@@ -7,74 +7,19 @@
background: var(--ui-color-bg-0); background: var(--ui-color-bg-0);
} }
/* 侧边栏 */ /* 文档导航在窄屏保留横向布局。 */
.docs-sidebar { .docs-sidebar {
width: 260px;
background: var(--ui-color-bg-2);
border-right: 1px solid var(--ui-color-border);
flex-shrink: 0;
overflow-y: auto;
position: sticky; position: sticky;
top: 64px; top: var(--app-header-height, 72px);
height: calc(100vh - 64px); height: calc(100vh - var(--app-header-height, 72px));
} }
.docs-nav { .docs-sidebar .docs-nav {
padding: 1.5rem 0; padding-top: 24px;
} }
.docs-nav-section { .docs-nav-section + .docs-nav-section {
padding: 0.5rem 0; margin-top: 18px;
}
.docs-nav-item {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.875rem 1.5rem;
color: var(--ui-color-text-2);
cursor: pointer;
transition: all 0.2s ease;
position: relative;
font-weight: 500;
}
.docs-nav-item::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 3px;
background: var(--ui-color-primary);
opacity: 0;
transition: opacity 0.2s ease;
}
.docs-nav-item i {
font-size: 1rem;
width: 20px;
text-align: center;
}
.docs-nav-item:hover {
background: var(--ui-color-fill-0);
color: var(--ui-color-primary);
}
.docs-nav-item.active {
background: var(--ui-color-primary-light-default);
color: var(--ui-color-primary);
}
.docs-nav-item.active::before {
opacity: 1;
}
.docs-nav-divider {
height: 1px;
background: var(--ui-color-border);
margin: 1rem 1.5rem;
} }
/* 内容区域 */ /* 内容区域 */
@@ -942,10 +887,6 @@
/* 响应式 */ /* 响应式 */
@media (max-width: 1024px) { @media (max-width: 1024px) {
.docs-sidebar {
width: 220px;
}
.docs-content { .docs-content {
padding: 1.5rem; padding: 1.5rem;
} }
@@ -965,33 +906,23 @@
border-bottom: 1px solid var(--ui-color-border); border-bottom: 1px solid var(--ui-color-border);
} }
.docs-nav { .docs-sidebar .docs-nav {
display: flex; display: flex;
gap: 6px;
overflow-x: auto; overflow-x: auto;
padding: 0.5rem; padding: 8px;
} }
.docs-nav-section { .docs-nav-section:not([hidden]) {
display: flex; flex-direction: row;
padding: 0; flex: none;
margin-top: 0;
} }
.docs-nav-item { .docs-sidebar button.ui-center-menu-item {
padding: 0.75rem 1rem; width: auto;
white-space: nowrap; flex: none;
} padding-inline: 12px;
/* 不能隐藏文字只留图标:图标是 <i class="fas fa-*">,而 FontAwesome
全站从未引入(index.html 无 link、package.json 无依赖),字形根本渲染不出来。
隐藏文字后手机端侧栏会变成 7 个纯空白方块,没有任何可辨认的导航。
.docs-nav 本身已是 flex + overflow-x:auto,保留文字即成为可横滑的 chip 条。 */
.docs-nav-item span {
display: inline;
font-size: 0.8125rem;
}
.docs-nav-divider {
display: none;
} }
.docs-content { .docs-content {
@@ -1,16 +1,18 @@
import { I18N_TECHNICAL_TEXT } from '../../../i18n/technicalText.js'; import { I18N_TECHNICAL_TEXT } from '../../../i18n/technicalText.js';
import {
ChevronRight as ActionChevronRight,
ChevronLeft as ActionChevronLeft,
} from '@/components/common/icons/ActionIcons';
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { Link, useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { BrainCircuit, Image, Video } from 'lucide-react'; import { BrainCircuit, Image, Video } from 'lucide-react';
import { useSidebarCollapsed } from '../../../hooks/common/useSidebarCollapsed'; import { useSidebarCollapsed } from '../../../hooks/common/useSidebarCollapsed';
import { useSidebarNavigation } from '../../../hooks/common/useTopNavigation';
import { useExperienceModules } from '../useExperienceModules'; import { useExperienceModules } from '../useExperienceModules';
import { badgeText } from '../../../hooks/creation/creationWatch'; import { badgeText } from '../../../hooks/creation/creationWatch';
import {
CenterSidebar,
CenterSidebarItem,
} from '../../../components/layout/components/CenterSidebar';
/** /**
* 体验中心桌面侧栏:结构、样式与收起交互对齐用户中心侧栏(UserCenterSidebar), * 体验中心桌面侧栏:结构、样式与收起交互对齐用户中心侧栏(UserCenterSidebar),
* 共用 center-layout.css 的 .ui-center-sidebar / .ui-center-menu-item / .ui-center-sidebar-collapse, * 共用 center-layout.css 的 .ui-center-sidebar / .ui-center-menu-item / .ui-center-sidebar-collapse,
@@ -22,6 +24,7 @@ import { badgeText } from '../../../hooks/creation/creationWatch';
const ExperienceSidebar = ({ unread }) => { const ExperienceSidebar = ({ unread }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [collapsed, toggleCollapsed] = useSidebarCollapsed(); const [collapsed, toggleCollapsed] = useSidebarCollapsed();
const followSidebarLink = useSidebarNavigation();
const location = useLocation(); const location = useLocation();
const { isAvailable } = useExperienceModules(); const { isAvailable } = useExperienceModules();
@@ -67,69 +70,59 @@ const ExperienceSidebar = ({ unread }) => {
''; '';
return ( return (
<aside <CenterSidebar
className='ui-experience-sidebar ui-center-sidebar' className='ui-experience-sidebar'
data-collapsed={collapsed} collapsed={collapsed}
onToggle={toggleCollapsed}
> >
<nav className='ui-center-sidebar-nav'> <div className='ui-org-group-items'>
<div className='ui-org-group-items'> {navItems.map((item) => {
{navItems.map((item) => { const active = selectedKey === item.itemKey;
const active = selectedKey === item.itemKey; const Icon = item.icon;
const Icon = item.icon; const unreadCount =
const unreadCount = item.unreadKey && !active ? unread?.[item.unreadKey] || 0 : 0;
item.unreadKey && !active ? unread?.[item.unreadKey] || 0 : 0; const unreadLabel = unreadCount
const unreadLabel = unreadCount ? t('{{n}} 个新作品', { n: unreadCount })
? t('{{n}} 个新作品', { n: unreadCount }) : '';
: '';
return ( return (
<Link <CenterSidebarItem
key={item.itemKey} key={item.itemKey}
to={item.to} to={item.to}
className='ui-center-menu-item' label={item.text}
data-active={active || undefined} collapsed={collapsed}
aria-current={active ? 'page' : undefined} active={active}
aria-label={ icon={<Icon size={16} strokeWidth={1.5} aria-hidden='true' />}
unreadLabel ? `${item.text}(${unreadLabel})` : undefined onClick={(event) => followSidebarLink(item.to, event)}
} aria-label={
title={collapsed ? item.text : undefined} unreadLabel
> ? `${item.text}(${unreadLabel})`
<Icon size={16} strokeWidth={1.5} aria-hidden='true' /> : collapsed
{!collapsed && ( ? item.text
<span className='ui-center-menu-label'>{item.text}</span> : undefined
)} }
{!collapsed && item.beta && ( trailing={
<span className='ui-org-beta'> <>
{I18N_TECHNICAL_TEXT.BETA} {!collapsed && item.beta && (
</span> <span className='ui-org-beta'>
)} {I18N_TECHNICAL_TEXT.BETA}
{unreadCount > 0 ? ( </span>
<span )}
className='exp-unread-badge ui-experience-unread' {unreadCount > 0 && (
aria-hidden='true' <span
> className='exp-unread-badge ui-experience-unread'
{badgeText(unreadCount)} aria-hidden='true'
</span> >
) : null} {badgeText(unreadCount)}
</Link> </span>
); )}
})} </>
</div> }
</nav> />
<button );
type='button' })}
className='app-action-button ui-center-sidebar-collapse' </div>
onClick={toggleCollapsed} </CenterSidebar>
aria-label={collapsed ? t('展开导航') : t('收起导航')}
>
{collapsed ? (
<ActionChevronRight size={16} />
) : (
<ActionChevronLeft size={16} />
)}
{!collapsed && <span>{t('收起导航')}</span>}
</button>
</aside>
); );
}; };
+21 -8
View File
@@ -1,10 +1,11 @@
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js'; import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { Navigate, useLocation, useNavigate } from 'react-router-dom'; import { Navigate, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { BrainCircuit, Image, Video } from 'lucide-react'; import { BrainCircuit, Image, Video } from 'lucide-react';
import { StatusContext } from '../../context/Status'; import { StatusContext } from '../../context/Status';
import { useMarquee } from '../../hooks/common/useMarquee'; import { useMarquee } from '../../hooks/common/useMarquee';
import { useSidebarNavigation } from '../../hooks/common/useTopNavigation';
import PageBackground from '../../components/common/PageBackground'; import PageBackground from '../../components/common/PageBackground';
import TextModel from './components/TextModel'; import TextModel from './components/TextModel';
import ImageGeneration from './components/ImageGeneration'; import ImageGeneration from './components/ImageGeneration';
@@ -13,7 +14,10 @@ import KeyManagement from './components/KeyManagement';
import ExperienceSidebar from './components/ExperienceSidebar'; import ExperienceSidebar from './components/ExperienceSidebar';
import CloudBrain from '../CloudBrain'; import CloudBrain from '../CloudBrain';
import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi'; import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi';
import Loading from '../../components/common/ui/Loading'; import {
CenterRouteLoading,
CenterSidebarLoading,
} from '../../components/layout/components/CenterSidebarLoading';
import { DEFAULT_LOGIN_REDIRECT } from '../../helpers/data'; import { DEFAULT_LOGIN_REDIRECT } from '../../helpers/data';
import { isCreationStudioEnabled } from '../../helpers/creationStudio'; import { isCreationStudioEnabled } from '../../helpers/creationStudio';
import { badgeText } from '../../hooks/creation/creationWatch'; import { badgeText } from '../../hooks/creation/creationWatch';
@@ -27,8 +31,9 @@ import {
} from './useExperienceModules'; } from './useExperienceModules';
// 移动端底部导航组件(exp-mobile-bottom-nav:新创作台展开态期间由 creation-dock.css 隐藏) // 移动端底部导航组件(exp-mobile-bottom-nav:新创作台展开态期间由 creation-dock.css 隐藏)
const MobileBottomNav = ({ currentPath, navigate, isAvailable, unread }) => { const MobileBottomNav = ({ currentPath, isAvailable, unread }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const followSidebarLink = useSidebarNavigation();
// 与桌面侧边栏共用 useExperienceModules 判定,运营关闭的子页两端一致隐藏 // 与桌面侧边栏共用 useExperienceModules 判定,运营关闭的子页两端一致隐藏
const navItems = [ const navItems = [
@@ -71,7 +76,9 @@ const MobileBottomNav = ({ currentPath, navigate, isAvailable, unread }) => {
return ( return (
<button <button
key={item.key} key={item.key}
onClick={() => navigate(item.path)} type='button'
aria-current={isActive ? 'page' : undefined}
onClick={(event) => followSidebarLink(item.path, event)}
className={`relative flex flex-col items-center justify-center flex-1 h-full transition-all ${ className={`relative flex flex-col items-center justify-center flex-1 h-full transition-all ${
isActive ? 'scale-105' : 'opacity-60' isActive ? 'scale-105' : 'opacity-60'
}`} }`}
@@ -118,7 +125,6 @@ const MobileBottomNav = ({ currentPath, navigate, isAvailable, unread }) => {
const ExperienceCenter = () => { const ExperienceCenter = () => {
const location = useLocation(); const location = useLocation();
const navigate = useNavigate();
const [statusState] = useContext(StatusContext); const [statusState] = useContext(StatusContext);
const { ready, orgOnly, isAvailable, defaultPath } = useExperienceModules(); const { ready, orgOnly, isAvailable, defaultPath } = useExperienceModules();
@@ -141,7 +147,11 @@ const ExperienceCenter = () => {
].includes(location.pathname); ].includes(location.pathname);
if (isEntryPath) { if (isEntryPath) {
// 配置/登录态就绪前不判定:默认配置全开,抢跑会落到随后才知道已关闭的页 // 配置/登录态就绪前不判定:默认配置全开,抢跑会落到随后才知道已关闭的页
return ready ? <Navigate to={fallbackPath} replace /> : <Loading />; return ready ? (
<Navigate to={fallbackPath} replace />
) : (
<CenterRouteLoading variant='experience' />
);
} }
// 运营关闭(或分组不可见、org_only 被后端拦截)的子页,直达链接也转去可用页, // 运营关闭(或分组不可见、org_only 被后端拦截)的子页,直达链接也转去可用页,
@@ -181,7 +191,11 @@ const ExperienceCenter = () => {
> >
{/* Sidebar - 桌面端 */} {/* Sidebar - 桌面端 */}
<div className='hidden md:block flex-shrink-0 h-full'> <div className='hidden md:block flex-shrink-0 h-full'>
<ExperienceSidebar unread={unread} /> {ready ? (
<ExperienceSidebar unread={unread} />
) : (
<CenterSidebarLoading variant='experience' />
)}
</div> </div>
{/* Main Content */} {/* Main Content */}
@@ -226,7 +240,6 @@ const ExperienceCenter = () => {
{/* 移动端底部导航栏 */} {/* 移动端底部导航栏 */}
<MobileBottomNav <MobileBottomNav
currentPath={location.pathname} currentPath={location.pathname}
navigate={navigate}
isAvailable={isAvailable} isAvailable={isAvailable}
unread={unread} unread={unread}
/> />
@@ -1,94 +1,61 @@
import React, { useEffect, useId, useState } from 'react'; import React, { useEffect } from 'react';
import { Link, useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Wallet } from 'lucide-react'; import { Wallet } from 'lucide-react';
import { ChevronDown as ActionChevronDown } from '@/components/common/icons/ActionIcons'; import {
CenterSidebarItem,
CenterSidebarSubmenu,
} from '../../components/layout/components/CenterSidebar';
import { useSidebarGroups } from '../../hooks/common/useSidebarGroups';
import { import {
PARTNER_NAVIGATION, PARTNER_NAVIGATION,
partnerView, partnerView,
} from '../CommissionV2/partnerNavigation'; } from '../CommissionV2/partnerNavigation';
const GROUP = 'commission';
export default function OrgCommissionNavigation({ export default function OrgCommissionNavigation({
collapsed, collapsed,
expandSidebar, expandSidebar,
query, followSidebarLink,
renderText,
onNavigate,
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const location = useLocation(); const location = useLocation();
const active = location.pathname === '/org/commission'; const active = location.pathname === '/org/commission';
const view = partnerView(location.search); const view = partnerView(location.search);
const [open, setOpen] = useState(active); const { keys, setGroup, toggle } = useSidebarGroups();
const submenuId = useId();
useEffect(() => { useEffect(() => {
if (active) setOpen(true); if (active) setGroup(GROUP, true);
}, [active, location.key]); }, [active, location.key, setGroup]);
const expanded = !collapsed && (open || !!query);
const parentMatches = t('企业分佣').toLowerCase().includes(query);
const children = PARTNER_NAVIGATION.filter(
(item) =>
!query || parentMatches || t(item.label).toLowerCase().includes(query),
);
// 样式与控制台二级菜单一致(center-layout.css 的 .ui-console-submenu-*):父项 16px 图标 + 展开箭头,
// 子项无图标、与父项文字左对齐并带层级引导线;收起态点击先展开侧栏。
return ( return (
<div className='ui-console-submenu org-commission-navigation'> <CenterSidebarSubmenu
<button className='org-commission-navigation'
type='button' label={t('企业分佣')}
className='ui-center-menu-item ui-console-submenu-toggle' icon={<Wallet size={16} strokeWidth={1.5} aria-hidden='true' />}
data-child-active={active || undefined} collapsed={collapsed}
aria-label={t('企业分佣')} open={!collapsed && keys.includes(GROUP)}
title={collapsed ? t('企业分佣') : undefined} childActive={active}
aria-expanded={expanded} onToggle={() => {
aria-controls={submenuId} if (collapsed) {
onClick={() => { expandSidebar();
if (collapsed) { setGroup(GROUP, true);
expandSidebar(); } else toggle(GROUP);
setOpen(true); }}
} else setOpen((value) => !value); >
}} {PARTNER_NAVIGATION.map((item) => {
> const to = `/org/commission?view=${item.key}`;
<Wallet size={16} strokeWidth={1.5} aria-hidden='true' /> return (
{!collapsed && ( <CenterSidebarItem
<> key={item.key}
<span className='ui-center-menu-label'> to={to}
{renderText(t('企业分佣'))} label={t(item.label)}
</span> active={active && view === item.key}
<ActionChevronDown nested
size={14} onClick={(event) => followSidebarLink(to, event)}
className='ui-console-submenu-arrow' />
aria-hidden );
/> })}
</> </CenterSidebarSubmenu>
)}
</button>
<div
id={submenuId}
role='group'
aria-label={t('企业分佣')}
className='ui-org-group-items ui-console-submenu-items'
hidden={!expanded}
>
{children.map((item) => {
const selected = active && view === item.key;
return (
<Link
key={item.key}
to={`/org/commission?view=${item.key}`}
onClick={() => onNavigate?.()}
aria-current={selected ? 'page' : undefined}
data-active={selected || undefined}
className='ui-center-menu-item ui-console-submenu-item'
>
<span className='ui-center-menu-label'>
{renderText(t(item.label))}
</span>
</Link>
);
})}
</div>
</div>
); );
} }
+1 -1
View File
@@ -95,7 +95,7 @@ const OrgResolver = ({
}, [runCheck]); }, [runCheck]);
if (mode === 'checking') { if (mode === 'checking') {
return <CenterRouteLoading />; return <CenterRouteLoading variant='org' />;
} }
if (mode === 'proxy_required') { if (mode === 'proxy_required') {
+96 -163
View File
@@ -1,11 +1,6 @@
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js'; import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
import { import React, { useContext, useEffect, useMemo } from 'react';
ChevronDown as ActionChevronDown, import { useLocation } from 'react-router-dom';
ChevronRight as ActionChevronRight,
ChevronLeft as ActionChevronLeft,
} from '@/components/common/icons/ActionIcons';
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { import {
BarChart3, BarChart3,
@@ -34,6 +29,13 @@ import {
UserCog, UserCog,
} from 'lucide-react'; } from 'lucide-react';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed'; import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
import { useSidebarNavigation } from '../../hooks/common/useTopNavigation';
import { useSidebarGroups } from '../../hooks/common/useSidebarGroups';
import {
CenterSidebar,
CenterSidebarGroup,
CenterSidebarItem,
} from '../../components/layout/components/CenterSidebar';
import { StatusContext } from '../../context/Status'; import { StatusContext } from '../../context/Status';
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules'; import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
import { canAccessOrgSettings } from './orgFeatureFlags'; import { canAccessOrgSettings } from './orgFeatureFlags';
@@ -111,6 +113,7 @@ const OrgSidebar = ({
const [collapsedState, toggleCollapsed] = useSidebarCollapsed(); const [collapsedState, toggleCollapsed] = useSidebarCollapsed();
// 移动端抽屉里始终展开,不允许折叠 // 移动端抽屉里始终展开,不允许折叠
const collapsed = mobile ? false : collapsedState; const collapsed = mobile ? false : collapsedState;
const followSidebarLink = useSidebarNavigation(onNavigate);
const [statusState] = useContext(StatusContext); const [statusState] = useContext(StatusContext);
const orgConfig = useMemo( const orgConfig = useMemo(
() => () =>
@@ -534,31 +537,11 @@ const OrgSidebar = ({
[groups, items], [groups, items],
); );
const navRef = useRef(null); const {
keys: foldedGroups,
// 二级分组折叠:仅记录用户手动收起的组,跨会话记忆 toggle: toggleGroup,
const FOLDED_GROUPS_KEY = 'org_sidebar_folded_groups'; setGroup,
const [foldedGroups, setFoldedGroups] = useState(() => { } = useSidebarGroups('org_sidebar_folded_groups');
try {
const saved = JSON.parse(localStorage.getItem(FOLDED_GROUPS_KEY) || '[]');
return Array.isArray(saved) ? saved : [];
} catch {
return [];
}
});
const toggleGroup = (key) => {
setFoldedGroups((prev) => {
const next = prev.includes(key)
? prev.filter((k) => k !== key)
: [...prev, key];
try {
localStorage.setItem(FOLDED_GROUPS_KEY, JSON.stringify(next));
} catch {
/* 隐私模式等场景下写入失败可忽略,仅丢失记忆 */
}
return next;
});
};
const getSelectedKey = () => { const getSelectedKey = () => {
if (location.pathname === '/org/member-accounts') { if (location.pathname === '/org/member-accounts') {
@@ -580,141 +563,91 @@ const OrgSidebar = ({
const activeGroup = groupedItems.find((g) => const activeGroup = groupedItems.find((g) =>
g.items.some((it) => it.itemKey === selectedKey), g.items.some((it) => it.itemKey === selectedKey),
)?.key; )?.key;
if (!activeGroup) return; setGroup(activeGroup, false);
setFoldedGroups((prev) => }, [selectedKey, groupedItems, location.key, setGroup]);
prev.includes(activeGroup) ? prev.filter((k) => k !== activeGroup) : prev,
);
}, [selectedKey, groupedItems, location.key]);
// 选中项滚入可视区(分组较多时避免高亮项被折叠区/滚动区遮住)
useEffect(() => {
const el = navRef.current?.querySelector('[data-active="true"]');
el?.scrollIntoView({ block: 'nearest' });
}, [selectedKey, location.search]);
return ( return (
<aside <CenterSidebar
className='ui-center-sidebar ui-org-sidebar' className='ui-org-sidebar'
data-collapsed={collapsed} collapsed={collapsed}
data-mobile={mobile || undefined} mobile={mobile}
> onToggle={toggleCollapsed}
{!collapsed && ( header={
<div className='ui-org-identity'> !collapsed && (
<LayoutGrid size={24} strokeWidth={1.65} aria-hidden='true' /> <div className='ui-org-identity'>
<div className='ui-org-identity-copy'> <LayoutGrid size={24} strokeWidth={1.65} aria-hidden='true' />
<span className='ui-org-name' title={orgName || t('企业中心')}> <div className='ui-org-identity-copy'>
{orgName || t('企业中心')} <span className='ui-org-name' title={orgName || t('企业中心')}>
</span> {orgName || t('企业中心')}
{orgRole && <span className='ui-org-role'>{roleLabel}</span>} </span>
</div> {orgRole && <span className='ui-org-role'>{roleLabel}</span>}
{organizations.length > 1 && (
<select
aria-label={t('切换企业')}
className='mt-3 w-full rounded-md border border-[var(--border-subtle)] bg-[var(--surface-card)] px-2 py-1 text-sm'
value={currentOrgId}
onChange={(event) =>
onOrganizationChange?.(Number(event.target.value))
}
>
{!organizations.some((org) => org.id === currentOrgId) && (
<option value={currentOrgId}>{orgName}</option>
)}
{organizations.map((org) => (
<option key={org.id} value={org.id}>
{org.name}
</option>
))}
</select>
)}
</div>
)}
<nav ref={navRef} className='ui-center-sidebar-nav'>
{groupedItems.map((group) => {
const folded = foldedGroups.includes(group.key);
return (
<div key={group.key} className='ui-org-nav-group'>
{!collapsed && (
<button
type='button'
onClick={() => toggleGroup(group.key)}
aria-expanded={!folded}
className='app-action-button ui-org-group-toggle'
>
<span>{group.label}</span>
<ActionChevronDown
size={13}
className={folded ? 'is-folded' : ''}
aria-hidden='true'
/>
</button>
)}
<div className='ui-org-group-items' hidden={folded && !collapsed}>
{group.items.map((item) => {
// 企业分佣二级导航(weiyuan eb3936cf0);企业侧栏无菜单搜索,query 恒为空
if (item.commissionAccess)
return (
<OrgCommissionNavigation
key={item.itemKey}
collapsed={collapsed}
expandSidebar={toggleCollapsed}
query=''
renderText={(text) => text}
onNavigate={onNavigate}
/>
);
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'>
{I18N_TECHNICAL_TEXT.BETA}
</span>
)}
</>
)}
</Link>
);
})}
</div>
</div> </div>
); {organizations.length > 1 && (
})} <select
</nav> aria-label={t('切换企业')}
{!mobile && ( className='mt-3 w-full rounded-md border border-[var(--border-subtle)] bg-[var(--surface-card)] px-2 py-1 text-sm'
<button value={currentOrgId}
type='button' onChange={(event) =>
onClick={toggleCollapsed} onOrganizationChange?.(Number(event.target.value))
className='app-action-button ui-center-sidebar-collapse' }
aria-label={collapsed ? t('展开导航') : t('收起导航')} >
{!organizations.some((org) => org.id === currentOrgId) && (
<option value={currentOrgId}>{orgName}</option>
)}
{organizations.map((org) => (
<option key={org.id} value={org.id}>
{org.name}
</option>
))}
</select>
)}
</div>
)
}
>
{groupedItems.map((group) => (
<CenterSidebarGroup
key={group.key}
label={group.label}
folded={foldedGroups.includes(group.key)}
collapsed={collapsed}
onToggle={() => toggleGroup(group.key)}
> >
{collapsed ? ( {group.items.map((item) => {
<ActionChevronRight size={16} /> if (item.commissionAccess) {
) : ( return (
<ActionChevronLeft size={16} /> <OrgCommissionNavigation
)} key={item.itemKey}
{!collapsed && <span>{t('收起导航')}</span>} collapsed={collapsed}
</button> expandSidebar={toggleCollapsed}
)} followSidebarLink={followSidebarLink}
</aside> />
);
}
const Icon = item.icon;
return (
<CenterSidebarItem
key={item.itemKey}
to={item.itemKey}
label={item.text}
collapsed={collapsed}
active={selectedKey === item.itemKey}
icon={<Icon size={16} strokeWidth={1.5} aria-hidden='true' />}
onClick={(event) => followSidebarLink(item.itemKey, event)}
trailing={
!collapsed &&
item.beta && (
<span className='ui-org-beta'>
{I18N_TECHNICAL_TEXT.BETA}
</span>
)
}
/>
);
})}
</CenterSidebarGroup>
))}
</CenterSidebar>
); );
}; };
+3 -2
View File
@@ -777,7 +777,7 @@ const Organization = () => {
(orgInfo && (orgInfo &&
(loadedOrgScope?.orgId !== orgId || loadedOrgScope?.user !== user)) (loadedOrgScope?.orgId !== orgId || loadedOrgScope?.user !== user))
) { ) {
return <CenterRouteLoading />; return <CenterRouteLoading variant='org' />;
} }
// 待激活占位页:不展示任何企业功能,仅引导联系客服/管理员 // 待激活占位页:不展示任何企业功能,仅引导联系客服/管理员
@@ -817,7 +817,8 @@ const Organization = () => {
} }
if (!firstOrgRoute) { if (!firstOrgRoute) {
if (commissionAccess === 'loading') return <CenterRouteLoading />; if (commissionAccess === 'loading')
return <CenterRouteLoading variant='org' />;
// 企业会话(org_only 员工、企业入口登录)、超管代理、或企业已有模块切到新体系: // 企业会话(org_only 员工、企业入口登录)、超管代理、或企业已有模块切到新体系:
// 显示明确空态,不默认开放、不静默跳走(AC121)。其余(未切换的个人会话)保持原行为回个人中心 // 显示明确空态,不默认开放、不静默跳走(AC121)。其余(未切换的个人会话)保持原行为回个人中心
if ( if (
+29 -45
View File
@@ -1,9 +1,5 @@
import {
ChevronRight as ActionChevronRight,
ChevronLeft as ActionChevronLeft,
} from '@/components/common/icons/ActionIcons';
import React, { useMemo, useContext } from 'react'; import React, { useMemo, useContext } from 'react';
import { Link, useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { import {
isMiniProgramPaymentPath, isMiniProgramPaymentPath,
isMiniProgramWebView, isMiniProgramWebView,
@@ -25,8 +21,14 @@ import { UserContext } from '../../context/User';
import { isSidebarModuleVisible } from '../../helpers/navigationVisibility'; import { isSidebarModuleVisible } from '../../helpers/navigationVisibility';
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules'; import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed'; import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
import { useSidebarNavigation } from '../../hooks/common/useTopNavigation';
import { useWeyAiDownloadEntry } from '../../hooks/common/useWeyAiWebEntry'; import { useWeyAiDownloadEntry } from '../../hooks/common/useWeyAiWebEntry';
import {
CenterSidebar,
CenterSidebarItem,
} from '../../components/layout/components/CenterSidebar';
const UserCenterSidebar = () => { const UserCenterSidebar = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const location = useLocation(); const location = useLocation();
@@ -34,6 +36,7 @@ const UserCenterSidebar = () => {
const [userState] = useContext(UserContext); const [userState] = useContext(UserContext);
const userGroup = userState?.user?.group || 'default'; const userGroup = userState?.user?.group || 'default';
const [collapsed, toggleCollapsed] = useSidebarCollapsed(); const [collapsed, toggleCollapsed] = useSidebarCollapsed();
const followSidebarLink = useSidebarNavigation();
// WeyAi 桌面端下载入口:与顶栏「下载 WeyAi」按钮共用同一套判定 // WeyAi 桌面端下载入口:与顶栏「下载 WeyAi」按钮共用同一套判定
//(下载页开关 + 网页端已配置时沿用其开放范围),两处入口口径一致 //(下载页开关 + 网页端已配置时沿用其开放范围),两处入口口径一致
const { visible: weyaiDownloadEnabled } = useWeyAiDownloadEntry(); const { visible: weyaiDownloadEnabled } = useWeyAiDownloadEntry();
@@ -143,47 +146,28 @@ const UserCenterSidebar = () => {
const selectedKey = getSelectedKey(); const selectedKey = getSelectedKey();
return ( return (
<aside <CenterSidebar
className='ui-user-sidebar ui-center-sidebar' className='ui-user-sidebar'
data-collapsed={collapsed} collapsed={collapsed}
onToggle={toggleCollapsed}
> >
<nav className='ui-center-sidebar-nav'> <div className='ui-org-group-items'>
<div className='ui-org-group-items'> {items.map((item) => {
{items.map((item) => { const Icon = item.icon;
const active = selectedKey === item.itemKey; return (
const Icon = item.icon; <CenterSidebarItem
return ( key={item.itemKey}
<Link to={item.itemKey}
key={item.itemKey} label={item.text}
to={item.itemKey} collapsed={collapsed}
className='ui-center-menu-item' active={selectedKey === item.itemKey}
data-active={active || undefined} icon={<Icon size={16} strokeWidth={1.5} aria-hidden='true' />}
aria-current={active ? 'page' : undefined} onClick={(event) => followSidebarLink(item.itemKey, event)}
title={collapsed ? item.text : undefined} />
> );
<Icon size={16} strokeWidth={1.5} aria-hidden='true' /> })}
{!collapsed && ( </div>
<span className='ui-center-menu-label'>{item.text}</span> </CenterSidebar>
)}
</Link>
);
})}
</div>
</nav>
<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>
); );
}; };
+4 -9
View File
@@ -1,11 +1,5 @@
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
Routes,
Route,
Navigate,
useLocation,
useNavigate,
} from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { import {
KeyRound, KeyRound,
@@ -20,6 +14,7 @@ import {
import { UserContext } from '../../context/User'; import { UserContext } from '../../context/User';
import { isSidebarModuleVisible } from '../../helpers/navigationVisibility'; import { isSidebarModuleVisible } from '../../helpers/navigationVisibility';
import { useMarquee } from '../../hooks/common/useMarquee'; import { useMarquee } from '../../hooks/common/useMarquee';
import { useSidebarNavigation } from '../../hooks/common/useTopNavigation';
import PageBackground from '../../components/common/PageBackground'; import PageBackground from '../../components/common/PageBackground';
import UserCenterSidebar from './UserCenterSidebar'; import UserCenterSidebar from './UserCenterSidebar';
import UserDashboard from './UserDashboard'; import UserDashboard from './UserDashboard';
@@ -42,7 +37,7 @@ import { useUserCenterRoutes } from './useUserCenterRoutes';
const MobileBottomNav = ({ sidebarConfig }) => { const MobileBottomNav = ({ sidebarConfig }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const location = useLocation(); const location = useLocation();
const navigate = useNavigate(); const followSidebarLink = useSidebarNavigation();
const [userState] = useContext(UserContext); const [userState] = useContext(UserContext);
const userGroup = userState?.user?.group; const userGroup = userState?.user?.group;
@@ -123,7 +118,7 @@ const MobileBottomNav = ({ sidebarConfig }) => {
type='button' type='button'
data-active={isActive} data-active={isActive}
aria-current={isActive ? 'page' : undefined} aria-current={isActive ? 'page' : undefined}
onClick={() => navigate(item.path)} onClick={(event) => followSidebarLink(item.path, event)}
className='uc-mobile-nav-item flex flex-col items-center justify-center flex-1 h-full' className='uc-mobile-nav-item flex flex-col items-center justify-center flex-1 h-full'
> >
<IconComponent size={20} /> <IconComponent size={20} />
+47 -10
View File
@@ -24,7 +24,7 @@
.ui-center-route-loading { .ui-center-route-loading {
display: flex; display: flex;
height: 100vh; height: 100vh;
padding-top: var(--console-header-offset, 72px); padding-top: var(--console-header-offset, var(--app-header-height, 72px));
background: var(--surface-bg-base); background: var(--surface-bg-base);
} }
@@ -36,12 +36,15 @@
animation: ui-center-sidebar-placeholder-reveal 100ms ease-out 140ms both; animation: ui-center-sidebar-placeholder-reveal 100ms ease-out 140ms both;
} }
.ui-center-sidebar .ui-center-sidebar-placeholder-rows { .ui-center-sidebar-placeholder-group {
display: flex; display: flex;
flex-direction: column; align-items: center;
gap: 6px; height: 30px;
padding-top: 24px; padding-inline: 16px;
overflow: hidden; }
.ui-center-sidebar-placeholder-identity {
height: 96px;
} }
.ui-center-sidebar-placeholder-rows .ui-center-menu-item { .ui-center-sidebar-placeholder-rows .ui-center-menu-item {
@@ -57,7 +60,12 @@
} }
.ui-center-sidebar-placeholder .ui-center-sidebar-placeholder
:is(.ui-center-menu-item, .ui-center-sidebar-placeholder-footer) :is(
.ui-center-menu-item,
.ui-center-sidebar-placeholder-footer,
.ui-center-sidebar-placeholder-group,
.ui-center-sidebar-placeholder-identity
)
> span { > span {
display: block; display: block;
width: 16px; width: 16px;
@@ -68,6 +76,21 @@
animation: ui-center-sidebar-placeholder-reveal 100ms ease-out 140ms both; animation: ui-center-sidebar-placeholder-reveal 100ms ease-out 140ms both;
} }
.ui-center-sidebar-placeholder-group > span {
width: 48px;
height: 10px;
}
.ui-center-sidebar-placeholder-identity > span:first-child {
width: 24px;
height: 24px;
}
.ui-center-sidebar-placeholder-identity > span + span {
width: 84px;
height: 12px;
}
.ui-center-sidebar-placeholder .ui-center-menu-item > span + span { .ui-center-sidebar-placeholder .ui-center-menu-item > span + span {
width: 60%; width: 60%;
height: 12px; height: 12px;
@@ -110,9 +133,7 @@
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
.ui-center-route-loading-body, .ui-center-route-loading-body,
.ui-center-sidebar-placeholder .ui-center-sidebar-placeholder span {
:is(.ui-center-menu-item, .ui-center-sidebar-placeholder-footer)
> span {
animation-duration: 0ms; animation-duration: 0ms;
} }
} }
@@ -163,6 +184,11 @@
overflow: hidden auto; overflow: hidden auto;
} }
.ui-center-sidebar:not([data-collapsed='true']):not([data-mobile='true'])
.ui-center-sidebar-nav {
scrollbar-gutter: stable;
}
.ui-org-nav-group + .ui-org-nav-group { .ui-org-nav-group + .ui-org-nav-group {
margin-top: 18px; margin-top: 18px;
} }
@@ -214,6 +240,17 @@
text-decoration: none; text-decoration: none;
} }
.ui-center-sidebar button.ui-center-menu-item {
width: 100%;
border: 0;
background: transparent;
text-align: start;
}
.ui-center-sidebar button.ui-center-menu-item:not(:disabled) {
cursor: pointer;
}
.ui-center-menu-item > svg { .ui-center-menu-item > svg {
flex: none; flex: none;
} }
@@ -41,6 +41,13 @@ const mocks = {
'../../hooks/common/useSidebarCollapsed': { '../../hooks/common/useSidebarCollapsed': {
useSidebarCollapsed: () => [false, () => {}], useSidebarCollapsed: () => [false, () => {}],
}, },
'../../hooks/common/useTopNavigation': {
useSidebarNavigation: () => () => {},
},
'../../components/layout/components/CenterSidebar': {
CenterSidebar: 'aside',
CenterSidebarItem: 'link',
},
'../../hooks/common/useWeyAiWebEntry': { '../../hooks/common/useWeyAiWebEntry': {
useWeyAiDownloadEntry: () => ({ visible: false }), useWeyAiDownloadEntry: () => ({ visible: false }),
}, },