/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { ChevronDown as ActionChevronDown } from '@/components/common/icons/ActionIcons'; import React, { useState } from 'react'; import { Avatar, Button as AntButton, Dropdown as AntDropdown } from 'antd'; import { UserRound, KeyRound, LogOut } from 'lucide-react'; import { getUserAvatarUrl } from '../../../helpers'; import SkeletonWrapper from '../components/SkeletonWrapper'; import { isHeaderModuleEnabled } from '../../../constants/headerNavModules'; // 头像菜单项:图标框 + 标题 + 说明(原型 account-menu-label) const AccountMenuLabel = ({ icon, tone, title, description }) => (
{icon} {title} {description}
); const MENU_ICON_PROPS = { size: 18, strokeWidth: 1.65, 'aria-hidden': true }; const UserArea = ({ userState, isLoading, isMobile, headerNavModules, rightActions = {}, sidebarModulesAdmin = {}, isOrgUser = false, logout, navigate, t, }) => { const [open, setOpen] = useState(false); const isActionVisible = (key) => rightActions?.[key] !== false; const hasHeaderModuleConfig = headerNavModules && Object.keys(headerNavModules).length > 0; const isTopNavModuleVisible = (key) => !hasHeaderModuleConfig || isHeaderModuleEnabled(headerNavModules, key); const isSidebarModuleVisible = (sectionKey, moduleKey) => { const section = sidebarModulesAdmin?.[sectionKey]; if (!section) return true; return section.enabled !== false && section[moduleKey] !== false; }; if (isLoading) { return ( ); } if (userState.user) { const displayName = userState.user.display_name || userState.user.username; const avatarUrl = getUserAvatarUrl(userState.user); const avatarInitial = displayName[0].toUpperCase(); const showSettings = isActionVisible('userSettings') && isTopNavModuleVisible('userCenter') && isSidebarModuleVisible('userCenter', 'settings'); // 「密钥管理快捷入口」由 rightActions.keyManagement 单独控制(运营设置→顶栏管理)。 // 个人用户的 /user-center/key-management 路由不依赖顶栏模块是否显示,故顶栏导航隐藏该模块时 // 头像菜单仍保留入口;企业员工只有在其顶栏模块放开时路由才被放行,继续联动判断。 const showKeyManagement = isActionVisible('keyManagement') && (!isOrgUser || isTopNavModuleVisible('keyManagement')); const items = []; if (showSettings) { items.push({ key: 'settings', label: ( } title={t('个人设置')} description={t('管理账户信息')} /> ), onClick: () => navigate('/user-center/settings'), }); } if (showKeyManagement) { items.push({ key: 'keys', label: ( } title={t('密钥管理')} description={t('查看和管理 API 密钥')} /> ), onClick: () => navigate('/user-center/key-management'), }); } items.push({ key: 'account-divider', type: 'divider' }); items.push({ key: 'logout', label: ( } title={t('退出登录')} description={t('安全退出账户')} /> ), onClick: logout, }); return ( setOpen(false) }} popupRender={(menu) => (
{avatarInitial}
{displayName} {userState.user.email || t('已登录')}
{menu}
)} classNames={{ root: 'ui-account-dropdown' }} > {avatarInitial} {displayName}
); } return null; }; export default UserArea;