feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面
This commit is contained in:
@@ -17,19 +17,30 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { Avatar, Button, Dropdown, Typography } from '@douyinfe/semi-ui';
|
||||
import { ChevronDown, User, Key, LogOut } from 'lucide-react';
|
||||
import {
|
||||
getUserAvatarUrl,
|
||||
stringToColor,
|
||||
isAuthPagePath,
|
||||
} from '../../../helpers';
|
||||
import { Avatar, Button as AntButton, Dropdown as AntDropdown } from 'antd';
|
||||
import { Button } from '@/components/ui';
|
||||
import { ChevronDown, UserRound, KeyRound, LogOut } from 'lucide-react';
|
||||
import { getUserAvatarUrl, isAuthPagePath } from '../../../helpers';
|
||||
import SkeletonWrapper from '../components/SkeletonWrapper';
|
||||
import { useActualTheme } from '../../../context/Theme';
|
||||
import { isHeaderModuleEnabled } from '../../../constants/headerNavModules';
|
||||
|
||||
// 头像菜单项:图标框 + 标题 + 说明(原型 account-menu-label)
|
||||
const AccountMenuLabel = ({ icon, tone, title, description }) => (
|
||||
<div className='ui-account-menu-label'>
|
||||
<span className={`ui-account-menu-icon ui-account-menu-icon-${tone}`}>
|
||||
{icon}
|
||||
</span>
|
||||
<span>
|
||||
{title}
|
||||
<small>{description}</small>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const MENU_ICON_PROPS = { size: 18, strokeWidth: 1.65, 'aria-hidden': true };
|
||||
|
||||
const UserArea = ({
|
||||
userState,
|
||||
isLoading,
|
||||
@@ -38,13 +49,13 @@ const UserArea = ({
|
||||
headerNavModules,
|
||||
rightActions = {},
|
||||
sidebarModulesAdmin = {},
|
||||
isOrgUser = false,
|
||||
logout,
|
||||
navigate,
|
||||
t,
|
||||
}) => {
|
||||
const location = useLocation();
|
||||
const actualTheme = useActualTheme();
|
||||
const isDark = actualTheme === 'dark';
|
||||
const [open, setOpen] = useState(false);
|
||||
const isActionVisible = (key) => rightActions?.[key] !== false;
|
||||
const hasHeaderModuleConfig =
|
||||
headerNavModules && Object.keys(headerNavModules).length > 0;
|
||||
@@ -73,271 +84,113 @@ const UserArea = ({
|
||||
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: (
|
||||
<AccountMenuLabel
|
||||
tone='user'
|
||||
icon={<UserRound {...MENU_ICON_PROPS} />}
|
||||
title={t('个人设置')}
|
||||
description={t('管理账户信息')}
|
||||
/>
|
||||
),
|
||||
onClick: () => navigate('/user-center/settings'),
|
||||
});
|
||||
}
|
||||
if (showKeyManagement) {
|
||||
items.push({
|
||||
key: 'keys',
|
||||
label: (
|
||||
<AccountMenuLabel
|
||||
tone='key'
|
||||
icon={<KeyRound {...MENU_ICON_PROPS} />}
|
||||
title={t('密钥管理')}
|
||||
description={t('查看和管理 API 密钥')}
|
||||
/>
|
||||
),
|
||||
onClick: () => navigate('/user-center/key-management'),
|
||||
});
|
||||
}
|
||||
items.push({ key: 'account-divider', type: 'divider' });
|
||||
items.push({
|
||||
key: 'logout',
|
||||
label: (
|
||||
<AccountMenuLabel
|
||||
tone='logout'
|
||||
icon={<LogOut {...MENU_ICON_PROPS} />}
|
||||
title={t('退出登录')}
|
||||
description={t('安全退出账户')}
|
||||
/>
|
||||
),
|
||||
onClick: logout,
|
||||
});
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
trigger='hover'
|
||||
position='bottomRight'
|
||||
showTick
|
||||
render={
|
||||
<Dropdown.Menu
|
||||
className='!min-w-[180px] !p-2 !backdrop-blur-xl !border !shadow-xl !rounded-xl'
|
||||
style={{
|
||||
backgroundColor: isDark
|
||||
? 'rgba(31,41,55,0.95)'
|
||||
: 'rgba(255,255,255,0.95)',
|
||||
borderColor: isDark ? 'rgba(55,65,81,1)' : 'rgba(243,244,246,1)',
|
||||
boxShadow: isDark
|
||||
? '0 20px 25px -5px rgba(0,0,0,0.3)'
|
||||
: '0 20px 25px -5px rgba(0,0,0,0.05)',
|
||||
}}
|
||||
>
|
||||
{/* 用户信息头部 */}
|
||||
<div
|
||||
className='px-3 py-2 mb-2 border-b'
|
||||
style={{
|
||||
borderColor: isDark
|
||||
? 'rgba(55,65,81,1)'
|
||||
: 'rgba(243,244,246,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<Avatar
|
||||
size='small'
|
||||
src={avatarUrl}
|
||||
color={stringToColor(displayName)}
|
||||
className='!w-8 !h-8 !text-xs'
|
||||
>
|
||||
{displayName[0].toUpperCase()}
|
||||
</Avatar>
|
||||
<div>
|
||||
<div
|
||||
className='text-sm font-semibold'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(243,244,246,0.9)'
|
||||
: 'rgba(31,41,55,1)',
|
||||
}}
|
||||
>
|
||||
{displayName}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{userState.user.email || t('已登录')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isActionVisible('userSettings') &&
|
||||
isTopNavModuleVisible('userCenter') &&
|
||||
isSidebarModuleVisible('userCenter', 'settings') && (
|
||||
<Dropdown.Item
|
||||
onClick={() => {
|
||||
navigate('/user-center/settings');
|
||||
}}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(30,58,138,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(219,234,254,1), rgba(224,231,255,1))',
|
||||
}}
|
||||
>
|
||||
<User
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(96,165,250,1)'
|
||||
: 'rgba(37,99,235,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('个人设置')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('管理账户信息')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
|
||||
{isActionVisible('keyManagement') &&
|
||||
isTopNavModuleVisible('keyManagement') && (
|
||||
<Dropdown.Item
|
||||
onClick={() => {
|
||||
navigate('/key-management');
|
||||
}}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(120,53,15,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(254,243,199,1), rgba(255,237,213,1))',
|
||||
}}
|
||||
>
|
||||
<Key
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(251,191,36,1)'
|
||||
: 'rgba(217,119,6,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('秘钥管理')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('查看和管理API秘钥')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
|
||||
<div
|
||||
className='my-2 border-t'
|
||||
style={{
|
||||
borderColor: isDark
|
||||
? 'rgba(55,65,81,1)'
|
||||
: 'rgba(243,244,246,1)',
|
||||
}}
|
||||
/>
|
||||
|
||||
<Dropdown.Item
|
||||
onClick={logout}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(127,29,29,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(254,226,226,1), rgba(255,228,230,1))',
|
||||
}}
|
||||
>
|
||||
<LogOut
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(248,113,113,1)'
|
||||
: 'rgba(220,38,38,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('退出登录')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('安全退出账户')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<span className='inline-flex'>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='flex items-center gap-2 !pl-1.5 !pr-2.5 !py-1.5 !h-10 !rounded-full hover:!bg-brand/10 dark:hover:!bg-brand/15 !bg-transparent !transition-all !duration-200 hover:!-translate-y-0.5 group'
|
||||
>
|
||||
<div className='relative'>
|
||||
<AntDropdown
|
||||
trigger={['hover']}
|
||||
placement='bottomRight'
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
overlayClassName='ui-account-dropdown'
|
||||
menu={{ items, onClick: () => setOpen(false) }}
|
||||
popupRender={(menu) => (
|
||||
<div className='ui-account-panel'>
|
||||
<div className='ui-account-summary'>
|
||||
<Avatar
|
||||
size='small'
|
||||
shape='square'
|
||||
size={40}
|
||||
src={avatarUrl}
|
||||
color={stringToColor(displayName)}
|
||||
className='!w-7 !h-7 !text-xs ring-2 ring-white dark:ring-gray-800 group-hover:!ring-brand/40 dark:group-hover:!ring-brand/50 transition-all'
|
||||
className='ui-account-avatar'
|
||||
>
|
||||
{displayName[0].toUpperCase()}
|
||||
{avatarInitial}
|
||||
</Avatar>
|
||||
{/* 在线状态点 */}
|
||||
<span className='absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 bg-emerald-500 border-2 border-white dark:border-gray-800 rounded-full' />
|
||||
<div>
|
||||
<strong>{displayName}</strong>
|
||||
<span>{userState.user.email || t('已登录')}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span className='hidden md:flex flex-col items-start'>
|
||||
<Typography.Text
|
||||
className='!text-sm !font-medium !leading-none'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
{displayName}
|
||||
</Typography.Text>
|
||||
</span>
|
||||
<ChevronDown
|
||||
size={14}
|
||||
style={{
|
||||
color: isDark ? 'rgba(209,213,219,1)' : 'rgba(156,163,175,1)',
|
||||
}}
|
||||
className='group-hover:!opacity-80 transition-colors'
|
||||
/>
|
||||
</Button>
|
||||
</span>
|
||||
</Dropdown>
|
||||
{menu}
|
||||
</div>
|
||||
)}
|
||||
>
|
||||
<AntButton
|
||||
type='text'
|
||||
className='ui-header-account'
|
||||
aria-haspopup='menu'
|
||||
aria-expanded={open}
|
||||
>
|
||||
<Avatar
|
||||
shape='square'
|
||||
size={38}
|
||||
src={avatarUrl}
|
||||
className='ui-account-avatar'
|
||||
>
|
||||
{avatarInitial}
|
||||
</Avatar>
|
||||
<span className='ui-header-account-name'>{displayName}</span>
|
||||
<ChevronDown
|
||||
size={10}
|
||||
strokeWidth={1.5}
|
||||
aria-hidden
|
||||
className={`ui-header-account-chevron${open ? ' is-open' : ''}`}
|
||||
/>
|
||||
</AntButton>
|
||||
</AntDropdown>
|
||||
);
|
||||
} else {
|
||||
if (isAuthPage) {
|
||||
@@ -356,7 +209,7 @@ const UserArea = ({
|
||||
let registerButtonClasses = `${commonSizingAndLayoutClass}`;
|
||||
|
||||
const loginButtonTextSpanClass =
|
||||
'!text-xs !text-semi-color-text-1 dark:!text-gray-300 !p-1.5';
|
||||
'!text-xs !text-ui-color-text-1 dark:!text-gray-300 !p-1.5';
|
||||
const registerButtonTextSpanClass = '!text-xs !text-white !p-1.5';
|
||||
|
||||
if (showRegisterButton) {
|
||||
|
||||
Reference in New Issue
Block a user