feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-04 19:59:06 +08:00
parent 472e534fe1
commit e6c41e7587
576 changed files with 18075 additions and 18912 deletions
+78 -283
View File
@@ -19,6 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useContext, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import UserCenterPageHeader from '../common/UserCenterPageHeader';
import {
API,
showError,
@@ -30,7 +31,6 @@ import {
isPasskeySupported,
setUserData,
clearUserData,
stringToColor,
renderQuota,
isRoot,
isAdmin,
@@ -41,22 +41,10 @@ import {
parseUserSetting,
} from '../../helpers';
import { UserContext } from '../../context/User';
import { Avatar, Tooltip } from '@douyinfe/semi-ui';
import { Tag as AntTag } from 'antd';
import { Avatar, Tooltip, Card, Tabs } from '@/components/ui';
import { useTranslation } from 'react-i18next';
import {
User,
Link2,
Shield,
Bell,
Sparkles,
Crown,
Coins,
BarChart2,
Users,
ChevronRight,
Copy,
Check,
} from 'lucide-react';
import { Check } from 'lucide-react';
// 导入内容区组件
import AccountBindingSection from './personal/sections/AccountBindingSection';
@@ -69,51 +57,14 @@ import EmailBindModal from './personal/modals/EmailBindModal';
import WeChatBindModal from './personal/modals/WeChatBindModal';
import AccountDeleteModal from './personal/modals/AccountDeleteModal';
import ChangePasswordModal from './personal/modals/ChangePasswordModal';
import './personal/personal-settings.css';
// 导航项配置
// 统一使用系统主题色(brand)作为选中态配色
const NAV_ACTIVE_GRADIENT = 'from-brand-from to-brand-to';
const NAV_ACTIVE_CLASS =
'from-brand-from/10 to-brand-to/10 dark:from-brand-from/20 dark:to-brand-to/20';
const NAV_TEXT_CLASS = 'text-brand-deep dark:text-brand';
// 设置页签(原型为纯文字页签,选中态由 Ant Design Tabs 呈现)
const NAV_ITEMS = [
{
key: 'avatar',
icon: User,
label: '头像设置',
description: '设置你的展示形象',
gradient: NAV_ACTIVE_GRADIENT,
activeClass: NAV_ACTIVE_CLASS,
textClass: NAV_TEXT_CLASS,
},
{
key: 'binding',
icon: Link2,
label: '账号绑定',
description: '管理邮箱和第三方登录',
gradient: NAV_ACTIVE_GRADIENT,
activeClass: NAV_ACTIVE_CLASS,
textClass: NAV_TEXT_CLASS,
},
{
key: 'security',
icon: Shield,
label: '安全设置',
description: '保护密码和登录设备',
gradient: NAV_ACTIVE_GRADIENT,
activeClass: NAV_ACTIVE_CLASS,
textClass: NAV_TEXT_CLASS,
},
{
key: 'notification',
icon: Bell,
label: '通知设置',
description: '配置额度预警通知',
gradient: NAV_ACTIVE_GRADIENT,
activeClass: NAV_ACTIVE_CLASS,
textClass: NAV_TEXT_CLASS,
},
{ key: 'avatar', label: '头像设置' },
{ key: 'binding', label: '账号绑定' },
{ key: 'security', label: '安全设置' },
{ key: 'notification', label: '通知设置' },
];
const PersonalSetting = () => {
@@ -578,16 +529,15 @@ const PersonalSetting = () => {
// 获取用户名
const getUsername = () => userState.user?.username || 'User';
const getDisplayName = () => userState.user?.display_name || getUsername();
const getAvatarText = () => getUsername().slice(0, 2).toUpperCase();
const userAvatarUrl = getUserAvatarUrl(userState?.user);
// 获取角色标签
const getRoleTag = () => {
if (isRoot())
return { text: t('超级管理员'), color: 'from-amber-500 to-orange-500' };
if (isAdmin())
return { text: t('管理员'), color: 'from-brand-from to-pink-500' };
return { text: t('普通用户'), color: 'from-blue-500 to-brand-to' };
if (isRoot()) return { text: t('超级管理员') };
if (isAdmin()) return { text: t('管理员') };
return { text: t('普通用户') };
};
// 渲染内容区域
@@ -645,232 +595,77 @@ const PersonalSetting = () => {
const roleInfo = getRoleTag();
return (
<div className='flex flex-col lg:flex-row min-h-screen pt-16 sm:pt-20 bg-[radial-gradient(circle_at_top_left,rgba(14,165,233,0.16),transparent_34%),radial-gradient(circle_at_bottom_right,rgba(245,158,11,0.13),transparent_30%),linear-gradient(135deg,rgba(248,250,252,0.92),rgba(241,245,249,0.72))] dark:bg-[radial-gradient(circle_at_top_left,rgba(14,165,233,0.16),transparent_34%),radial-gradient(circle_at_bottom_right,rgba(245,158,11,0.10),transparent_30%),linear-gradient(135deg,#0f172a,#111827)]'>
{/* 背景装饰 */}
<div className='fixed inset-0 pointer-events-none overflow-hidden'>
<div className='absolute top-20 right-20 w-64 h-64 bg-blue-400/10 dark:bg-blue-600/10 rounded-full blur-3xl' />
<div className='absolute bottom-20 left-20 w-80 h-80 bg-brand-from/10 dark:bg-brand-deep/10 rounded-full blur-3xl' />
</div>
{/* 移动端顶部导航 */}
<div className='lg:hidden sticky top-16 sm:top-20 z-20 bg-white/[0.72] dark:bg-slate-950/[0.72] backdrop-blur-2xl border-b border-white/60 dark:border-white/10'>
{/* 用户简要信息 */}
<div className='flex items-center gap-3 px-4 py-3 border-b border-gray-100 dark:border-gray-800'>
<Avatar
size='small'
src={userAvatarUrl}
color={stringToColor(getUsername())}
className='!w-8 !h-8'
>
{getAvatarText()}
</Avatar>
<div className='flex-1 min-w-0'>
<div className='text-sm font-semibold text-gray-900 dark:text-white truncate'>
{getUsername()}
</div>
<div className='text-xs text-gray-500'>
{renderQuota(userState?.user?.quota)}
<div className='ui-personal-settings min-h-screen pt-16 sm:pt-20'>
<div className='ui-personal-inner uc-page'>
<UserCenterPageHeader
title={t('个人设置')}
subtitle={t('管理你的平台形象、账户安全与通知偏好')}
/>
<Card className='ui-personal-profile'>
<div className='ui-profile-identity'>
<span className='ui-profile-avatar'>
<Avatar shape='square' size={54} src={userAvatarUrl}>
{getAvatarText()}
</Avatar>
</span>
<div className='ui-profile-meta'>
<div className='ui-profile-name'>
<strong>{getDisplayName()}</strong>
<AntTag color='gold' bordered={false}>
{roleInfo.text}
</AntTag>
</div>
<div className='ui-profile-sub'>
<span>
{t('用户名')}:{getUsername()}
</span>
<span aria-hidden='true'>·</span>
<Tooltip
content={userIdCopied ? t('已复制') : t('点击复制用户ID')}
>
<button
type='button'
className='ui-profile-id'
onClick={copyUserId}
>
ID:{userState?.user?.id}
{userIdCopied && <Check size={12} />}
</button>
</Tooltip>
<span aria-hidden='true'>·</span>
<span>
{t('分组')}:{userState?.user?.group || '-'}
</span>
</div>
</div>
</div>
</div>
{/* 横向滚动导航 */}
<div className='overflow-x-auto scrollbar-hide'>
<div className='flex gap-1 p-2 min-w-max'>
{NAV_ITEMS.map((item) => {
const Icon = item.icon;
const isActive = activeNav === item.key;
return (
<button
key={item.key}
onClick={() => setActiveNav(item.key)}
className={`flex items-center gap-1.5 px-3 py-2 rounded-xl text-sm font-medium whitespace-nowrap transition-all border ${
isActive
? `bg-gradient-to-r ${item.activeClass} ${item.textClass} border-white/70 dark:border-white/10 shadow-sm`
: 'text-gray-600 dark:text-gray-400 border-transparent hover:bg-white/60 dark:hover:bg-white/[0.06]'
}`}
>
<Icon size={16} />
<span>{t(item.label)}</span>
</button>
);
})}
</div>
</div>
</div>
{/* 左侧导航栏 - 仅桌面端 */}
<div className='hidden lg:block w-80 shrink-0 p-4 pr-0 relative z-10'>
<div className='sticky top-24 bg-white/[0.62] dark:bg-slate-950/[0.52] backdrop-blur-2xl rounded-[28px] border border-white/70 dark:border-white/10 shadow-[0_24px_70px_rgba(15,23,42,0.10)] overflow-hidden'>
{/* 用户信息头部 */}
<div className='relative p-6 border-b border-white/60 dark:border-white/10'>
{/* 装饰背景 */}
<div className='absolute inset-0 bg-gradient-to-br from-blue-500/5 via-brand-via/5 to-brand-to/5' />
<div className='absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-blue-400/10 to-transparent rounded-full blur-2xl' />
<div className='relative flex items-center gap-4'>
{/* 头像 */}
<div className='relative group'>
<div className='absolute inset-0 bg-gradient-to-br from-blue-500 to-brand-to rounded-full blur-md opacity-50 group-hover:opacity-70 transition-opacity' />
<Avatar
size='large'
src={userAvatarUrl}
color={stringToColor(getUsername())}
className='!w-14 !h-14 relative ring-2 ring-white dark:ring-gray-800'
>
{getAvatarText()}
</Avatar>
<span className='absolute -bottom-0.5 -right-0.5 w-4 h-4 bg-emerald-500 border-2 border-white dark:border-gray-800 rounded-full' />
</div>
{/* 用户信息 */}
<div className='flex-1 min-w-0'>
<div className='flex items-center gap-2'>
<h3 className='text-lg font-bold text-gray-900 dark:text-white truncate'>
{getUsername()}
</h3>
{isRoot() && <Crown size={14} className='text-amber-500' />}
</div>
<div className='flex items-center gap-2 mt-1'>
<span
className={`inline-flex items-center px-2 py-0.5 text-xs font-medium text-white rounded-full bg-gradient-to-r ${roleInfo.color}`}
>
{roleInfo.text}
</span>
<Tooltip
content={userIdCopied ? t('已复制') : t('点击复制用户ID')}
>
<button
onClick={copyUserId}
className='inline-flex items-center gap-1 text-xs text-gray-400 hover:text-blue-500 dark:hover:text-blue-400 transition-colors cursor-pointer group'
>
<span>ID: {userState?.user?.id}</span>
{userIdCopied ? (
<Check size={12} className='text-emerald-500' />
) : (
<Copy
size={12}
className='opacity-0 group-hover:opacity-100 transition-opacity'
/>
)}
</button>
</Tooltip>
</div>
</div>
<div className='ui-profile-stats'>
<div>
<span>{t('可用余额')}</span>
<strong>{renderQuota(userState?.user?.quota)}</strong>
</div>
{/* 余额显示 */}
<div className='relative mt-4 p-3 bg-white/[0.58] dark:bg-white/[0.055] rounded-2xl border border-white/70 dark:border-white/10'>
<div className='flex items-center justify-between'>
<div className='flex items-center gap-2'>
<Coins size={16} className='text-blue-500' />
<span className='text-sm text-gray-600 dark:text-gray-400'>
{t('当前余额')}
</span>
</div>
<Sparkles size={14} className='text-amber-500' />
</div>
<div className='mt-1 text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-brand-to dark:from-blue-400 dark:to-brand-to'>
{renderQuota(userState?.user?.quota)}
</div>
<div>
<span>{t('累计支出')}</span>
<strong>{renderQuota(userState?.user?.used_quota)}</strong>
</div>
{/* 快捷统计 */}
<div className='relative mt-3 grid grid-cols-2 gap-2'>
<Tooltip content={t('历史消耗总额')}>
<div className='flex items-center gap-2 p-2 bg-white/[0.58] dark:bg-white/[0.055] rounded-xl border border-white/60 dark:border-white/10 cursor-default'>
<BarChart2 size={14} className='text-gray-400' />
<span className='text-xs text-gray-500 dark:text-gray-400 truncate'>
{renderQuota(userState?.user?.used_quota)}
</span>
</div>
</Tooltip>
<Tooltip content={t('用户分组')}>
<div className='flex items-center gap-2 p-2 bg-white/[0.58] dark:bg-white/[0.055] rounded-xl border border-white/60 dark:border-white/10 cursor-default'>
<Users size={14} className='text-gray-400' />
<span className='text-xs text-gray-500 dark:text-gray-400 truncate'>
{userState?.user?.group || t('默认')}
</span>
</div>
</Tooltip>
<div>
<span>{t('调用次数')}</span>
<strong>{userState?.user?.request_count || 0}</strong>
</div>
</div>
{/* 导航菜单 */}
<nav className='p-3 space-y-2'>
{NAV_ITEMS.map((item) => {
const Icon = item.icon;
const isActive = activeNav === item.key;
return (
<button
key={item.key}
onClick={() => setActiveNav(item.key)}
className={`relative w-full flex items-center gap-3 px-4 py-3 rounded-2xl transition-all duration-200 group border ${
isActive
? `bg-gradient-to-r ${item.activeClass} border-white/70 dark:border-white/10 shadow-[0_12px_28px_rgba(15,23,42,0.08)]`
: 'border-transparent hover:bg-white/[0.52] dark:hover:bg-white/[0.055]'
}`}
>
{/* 图标 */}
<div
className={`w-9 h-9 rounded-lg flex items-center justify-center transition-all ${
isActive
? `bg-gradient-to-br ${item.gradient} shadow-lg`
: 'bg-white/[0.65] dark:bg-white/[0.06] group-hover:bg-white dark:group-hover:bg-white/[0.1]'
}`}
>
<Icon
size={18}
className={
isActive
? 'text-white'
: 'text-gray-500 dark:text-gray-400'
}
/>
</div>
{/* 标签 */}
<span className='flex-1 text-left min-w-0'>
<span
className={`block text-sm font-semibold transition-colors ${
isActive
? item.textClass
: 'text-gray-700 dark:text-gray-200'
}`}
>
{t(item.label)}
</span>
<span className='mt-0.5 block text-[11px] text-gray-400 dark:text-gray-500 truncate'>
{t(item.description)}
</span>
</span>
{/* 箭头指示器 */}
<ChevronRight
size={16}
className={`transition-all ${
isActive
? `${item.textClass} translate-x-0 opacity-100`
: 'text-gray-300 -translate-x-2 opacity-0 group-hover:translate-x-0 group-hover:opacity-100'
}`}
/>
{/* 选中指示条 */}
{isActive && (
<div className={`absolute left-0 w-1 h-8 bg-gradient-to-b ${item.gradient} rounded-r-full`} />
)}
</button>
);
})}
</nav>
</div>
</div>
{/* 右侧内容区 */}
<div className='flex-1 p-3 sm:p-4 overflow-auto relative z-10'>
<div className='min-h-full bg-white/[0.58] dark:bg-slate-950/[0.46] backdrop-blur-2xl rounded-2xl lg:rounded-[28px] border border-white/70 dark:border-white/10 shadow-[0_24px_80px_rgba(15,23,42,0.10)] p-4 sm:p-6'>
</Card>
<Card className='ui-personal-content'>
<Tabs
activeKey={activeNav}
onChange={setActiveNav}
tabList={NAV_ITEMS.map((item) => ({
itemKey: item.key,
tab: t(item.label),
label: t(item.label),
}))}
/>
{renderContent()}
</div>
</Card>
</div>
{/* 模态框 */}