Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
+932
View File
@@ -0,0 +1,932 @@
/*
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 <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useContext, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import {
API,
showError,
showInfo,
showSuccess,
setStatusData,
prepareCredentialCreationOptions,
buildRegistrationResult,
isPasskeySupported,
setUserData,
clearUserData,
stringToColor,
renderQuota,
isRoot,
isAdmin,
USER_AVATAR_TYPES,
getAvatarPresetById,
getDefaultAvatarPresetId,
getUserAvatarUrl,
parseUserSetting,
} from '../../helpers';
import { UserContext } from '../../context/User';
import { Avatar, Tooltip } from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next';
import {
User,
Link2,
Shield,
Bell,
Sparkles,
Crown,
Coins,
BarChart2,
Users,
ChevronRight,
Copy,
Check,
} from 'lucide-react';
// 导入内容区组件
import AccountBindingSection from './personal/sections/AccountBindingSection';
import SecuritySection from './personal/sections/SecuritySection';
import NotificationSection from './personal/sections/NotificationSection';
import AvatarSection from './personal/sections/AvatarSection';
// 导入模态框
import EmailBindModal from './personal/modals/EmailBindModal';
import WeChatBindModal from './personal/modals/WeChatBindModal';
import AccountDeleteModal from './personal/modals/AccountDeleteModal';
import ChangePasswordModal from './personal/modals/ChangePasswordModal';
// 导航项配置
// 统一使用系统主题色(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';
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,
},
];
const PersonalSetting = () => {
const [userState, userDispatch] = useContext(UserContext);
let navigate = useNavigate();
const { t } = useTranslation();
// 当前选中的导航项
const [activeNav, setActiveNav] = useState('avatar');
const [inputs, setInputs] = useState({
wechat_verification_code: '',
email_verification_code: '',
email: '',
self_account_deletion_confirmation: '',
original_password: '',
set_new_password: '',
set_new_password_confirmation: '',
});
const [status, setStatus] = useState({});
const [showChangePasswordModal, setShowChangePasswordModal] = useState(false);
const [showWeChatBindModal, setShowWeChatBindModal] = useState(false);
const [showEmailBindModal, setShowEmailBindModal] = useState(false);
const [showAccountDeleteModal, setShowAccountDeleteModal] = useState(false);
const [turnstileEnabled, setTurnstileEnabled] = useState(false);
const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
const [turnstileToken, setTurnstileToken] = useState('');
const [loading, setLoading] = useState(false);
const [disableButton, setDisableButton] = useState(false);
const [countdown, setCountdown] = useState(30);
const [passkeyStatus, setPasskeyStatus] = useState({ enabled: false });
const [passkeyRegisterLoading, setPasskeyRegisterLoading] = useState(false);
const [passkeyDeleteLoading, setPasskeyDeleteLoading] = useState(false);
const [passkeySupported, setPasskeySupported] = useState(false);
const [userIdCopied, setUserIdCopied] = useState(false);
const [savingAvatarSettings, setSavingAvatarSettings] = useState(false);
const [avatarSettings, setAvatarSettings] = useState({
avatarType: USER_AVATAR_TYPES.PRESET,
avatarPreset: getDefaultAvatarPresetId(userState?.user),
customAvatarUrl: '',
});
const [notificationSettings, setNotificationSettings] = useState({
warningType: 'email',
warningThreshold: 100000,
webhookUrl: '',
webhookSecret: '',
notificationEmail: '',
barkUrl: '',
gotifyUrl: '',
gotifyToken: '',
gotifyPriority: 5,
acceptUnsetModelRatioModel: false,
recordIpLog: false,
});
useEffect(() => {
let saved = localStorage.getItem('status');
if (saved) {
const parsed = JSON.parse(saved);
setStatus(parsed);
if (parsed.turnstile_check) {
setTurnstileEnabled(true);
setTurnstileSiteKey(parsed.turnstile_site_key);
} else {
setTurnstileEnabled(false);
setTurnstileSiteKey('');
}
}
(async () => {
try {
const res = await API.get('/api/status');
const { success, data } = res.data;
if (success && data) {
setStatus(data);
setStatusData(data);
if (data.turnstile_check) {
setTurnstileEnabled(true);
setTurnstileSiteKey(data.turnstile_site_key);
} else {
setTurnstileEnabled(false);
setTurnstileSiteKey('');
}
}
} catch (e) {
// ignore
}
})();
getUserData();
isPasskeySupported()
.then(setPasskeySupported)
.catch(() => setPasskeySupported(false));
}, []);
useEffect(() => {
let countdownInterval = null;
if (disableButton && countdown > 0) {
countdownInterval = setInterval(() => {
setCountdown(countdown - 1);
}, 1000);
} else if (countdown === 0) {
setDisableButton(false);
setCountdown(30);
}
return () => clearInterval(countdownInterval);
}, [disableButton, countdown]);
useEffect(() => {
if (userState?.user?.setting) {
const settings = parseUserSetting(userState.user.setting);
setNotificationSettings({
warningType: ['email', 'webhook'].includes(settings.notify_type)
? settings.notify_type
: 'email',
warningThreshold: settings.quota_warning_threshold || 500000,
webhookUrl: settings.webhook_url || '',
webhookSecret: settings.webhook_secret || '',
notificationEmail: settings.notification_email || '',
barkUrl: settings.bark_url || '',
gotifyUrl: settings.gotify_url || '',
gotifyToken: settings.gotify_token || '',
gotifyPriority:
settings.gotify_priority !== undefined ? settings.gotify_priority : 5,
acceptUnsetModelRatioModel:
settings.accept_unset_model_ratio_model || false,
recordIpLog: settings.record_ip_log || false,
});
setAvatarSettings({
avatarType: Object.values(USER_AVATAR_TYPES).includes(
settings.avatar_type,
)
? settings.avatar_type
: USER_AVATAR_TYPES.PRESET,
avatarPreset: getAvatarPresetById(
settings.avatar_preset || getDefaultAvatarPresetId(userState.user),
).id,
customAvatarUrl: settings.custom_avatar_url || '',
});
} else if (userState?.user) {
setAvatarSettings((prev) => ({
...prev,
avatarPreset:
prev.avatarPreset || getDefaultAvatarPresetId(userState.user),
}));
}
}, [userState?.user?.id, userState?.user?.setting]);
const handleInputChange = (name, value) => {
setInputs((inputs) => ({ ...inputs, [name]: value }));
};
const loadPasskeyStatus = async () => {
try {
const res = await API.get('/api/user/passkey');
const { success, data, message } = res.data;
if (success) {
setPasskeyStatus({
enabled: data?.enabled || false,
last_used_at: data?.last_used_at || null,
backup_eligible: data?.backup_eligible || false,
backup_state: data?.backup_state || false,
});
} else {
showError(message);
}
} catch (error) {
// ignore
}
};
const handleRegisterPasskey = async () => {
if (!passkeySupported || !window.PublicKeyCredential) {
showInfo(t('当前设备不支持 Passkey'));
return;
}
setPasskeyRegisterLoading(true);
try {
const beginRes = await API.post('/api/user/passkey/register/begin');
const { success, message, data } = beginRes.data;
if (!success) {
showError(message || t('无法发起 Passkey 注册'));
return;
}
const publicKey = prepareCredentialCreationOptions(
data?.options || data?.publicKey || data,
);
const credential = await navigator.credentials.create({ publicKey });
const payload = buildRegistrationResult(credential);
if (!payload) {
showError(t('Passkey 注册失败,请重试'));
return;
}
const finishRes = await API.post(
'/api/user/passkey/register/finish',
payload,
);
if (finishRes.data.success) {
showSuccess(t('Passkey 注册成功'));
await loadPasskeyStatus();
} else {
showError(finishRes.data.message || t('Passkey 注册失败,请重试'));
}
} catch (error) {
if (error?.name === 'AbortError') {
showInfo(t('已取消 Passkey 注册'));
} else {
showError(t('Passkey 注册失败,请重试'));
}
} finally {
setPasskeyRegisterLoading(false);
}
};
const handleRemovePasskey = async () => {
setPasskeyDeleteLoading(true);
try {
const res = await API.delete('/api/user/passkey');
const { success, message } = res.data;
if (success) {
showSuccess(t('Passkey 已解绑'));
await loadPasskeyStatus();
} else {
showError(message || t('操作失败,请重试'));
}
} catch (error) {
showError(t('操作失败,请重试'));
} finally {
setPasskeyDeleteLoading(false);
}
};
const getUserData = async () => {
let res = await API.get(`/api/user/self`);
const { success, message, data } = res.data;
if (success) {
userDispatch({ type: 'login', payload: data });
setUserData(data);
await loadPasskeyStatus();
} else {
showError(message);
}
};
const deleteAccount = async () => {
if (inputs.self_account_deletion_confirmation !== userState.user.username) {
showError(t('请输入你的账户名以确认删除!'));
return;
}
const res = await API.delete('/api/user/self');
const { success, message } = res.data;
if (success) {
showSuccess(t('账户已删除!'));
await API.get('/api/user/logout');
userDispatch({ type: 'logout' });
clearUserData();
navigate('/login');
} else {
showError(message);
}
};
const bindWeChat = async () => {
if (inputs.wechat_verification_code === '') return;
const res = await API.get(
`/api/oauth/wechat/bind?code=${inputs.wechat_verification_code}`,
);
const { success, message } = res.data;
if (success) {
showSuccess(t('微信账户绑定成功!'));
setShowWeChatBindModal(false);
} else {
showError(message);
}
};
const hasPassword = userState.user?.has_password;
const changePassword = async () => {
if (hasPassword && inputs.original_password === '') {
showError(t('请输入原密码!'));
return;
}
if (inputs.set_new_password === '') {
showError(t('请输入新密码!'));
return;
}
if (hasPassword && inputs.original_password === inputs.set_new_password) {
showError(t('新密码需要和原密码不一致!'));
return;
}
if (inputs.set_new_password !== inputs.set_new_password_confirmation) {
showError(t('两次输入的密码不一致!'));
return;
}
const res = await API.put(`/api/user/self`, {
original_password: inputs.original_password,
password: inputs.set_new_password,
});
const { success, message } = res.data;
if (success) {
showSuccess(hasPassword ? t('密码修改成功!') : t('密码设置成功!'));
// 重新拉取用户数据以更新 has_password 状态
await getUserData();
} else {
showError(message);
}
setShowChangePasswordModal(false);
};
const sendVerificationCode = async () => {
if (inputs.email === '') {
showError(t('请输入邮箱!'));
return;
}
setDisableButton(true);
if (turnstileEnabled && turnstileToken === '') {
showInfo(t('请稍后几秒重试,Turnstile 正在检查用户环境!'));
return;
}
setLoading(true);
const res = await API.get(
`/api/verification?email=${encodeURIComponent(inputs.email)}&turnstile=${turnstileToken}`,
);
const { success, message } = res.data;
if (success) {
showSuccess(t('验证码发送成功,请检查邮箱!'));
} else {
showError(message);
}
setLoading(false);
};
const bindEmail = async () => {
if (inputs.email_verification_code === '') {
showError(t('请输入邮箱验证码!'));
return;
}
setLoading(true);
const res = await API.get(
`/api/oauth/email/bind?email=${encodeURIComponent(inputs.email)}&code=${encodeURIComponent(inputs.email_verification_code)}`,
);
const { success, message } = res.data;
if (success) {
showSuccess(t('邮箱账户绑定成功!'));
setShowEmailBindModal(false);
userState.user.email = inputs.email;
} else {
showError(message);
}
setLoading(false);
};
const handleNotificationSettingChange = (type, value) => {
setNotificationSettings((prev) => ({
...prev,
[type]: value.target
? value.target.value !== undefined
? value.target.value
: value.target.checked
: value,
}));
};
const handleAvatarSettingChange = (type, value) => {
setAvatarSettings((prev) => ({
...prev,
[type]: value,
}));
};
const buildUserSettingPayload = (
nextNotificationSettings = notificationSettings,
nextAvatarSettings = avatarSettings,
) => ({
notify_type: nextNotificationSettings.warningType,
quota_warning_threshold: parseFloat(
nextNotificationSettings.warningThreshold,
),
webhook_url: nextNotificationSettings.webhookUrl,
webhook_secret: nextNotificationSettings.webhookSecret,
notification_email: nextNotificationSettings.notificationEmail,
bark_url: nextNotificationSettings.barkUrl,
gotify_url: nextNotificationSettings.gotifyUrl,
gotify_token: nextNotificationSettings.gotifyToken,
gotify_priority: (() => {
const parsed = parseInt(nextNotificationSettings.gotifyPriority);
return isNaN(parsed) ? 5 : parsed;
})(),
accept_unset_model_ratio_model:
nextNotificationSettings.acceptUnsetModelRatioModel,
record_ip_log: nextNotificationSettings.recordIpLog,
avatar_type: nextAvatarSettings.avatarType,
avatar_preset: nextAvatarSettings.avatarPreset,
custom_avatar_url: nextAvatarSettings.customAvatarUrl,
});
const saveNotificationSettings = async () => {
try {
const res = await API.put('/api/user/setting', buildUserSettingPayload());
if (res.data.success) {
showSuccess(t('设置保存成功'));
await getUserData();
} else {
showError(res.data.message);
}
} catch (error) {
showError(t('设置保存失败'));
}
};
const saveAvatarSettings = async () => {
if (
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
!avatarSettings.customAvatarUrl?.trim()
) {
showError(t('请先填写自定义头像图片 URL'));
return;
}
setSavingAvatarSettings(true);
try {
const res = await API.put('/api/user/setting', buildUserSettingPayload());
if (res.data.success) {
showSuccess(t('头像设置已保存'));
await getUserData();
} else {
showError(res.data.message);
}
} catch (error) {
showError(t('头像设置保存失败'));
} finally {
setSavingAvatarSettings(false);
}
};
// 复制用户ID
const copyUserId = () => {
const userId = String(userState?.user?.id || '');
navigator.clipboard
.writeText(userId)
.then(() => {
setUserIdCopied(true);
setTimeout(() => setUserIdCopied(false), 2000);
})
.catch(() => {
// 降级方案
const textarea = document.createElement('textarea');
textarea.value = userId;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
setUserIdCopied(true);
setTimeout(() => setUserIdCopied(false), 2000);
});
};
// 获取用户名
const getUsername = () => userState.user?.username || 'User';
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' };
};
// 渲染内容区域
const renderContent = () => {
const commonProps = { t, userState, status };
switch (activeNav) {
case 'avatar':
return (
<AvatarSection
{...commonProps}
avatarSettings={avatarSettings}
handleAvatarSettingChange={handleAvatarSettingChange}
saveAvatarSettings={saveAvatarSettings}
savingAvatarSettings={savingAvatarSettings}
/>
);
case 'binding':
return (
<AccountBindingSection
{...commonProps}
setShowEmailBindModal={setShowEmailBindModal}
setShowWeChatBindModal={setShowWeChatBindModal}
/>
);
case 'security':
return (
<SecuritySection
{...commonProps}
setShowChangePasswordModal={setShowChangePasswordModal}
setShowAccountDeleteModal={setShowAccountDeleteModal}
hasPassword={hasPassword}
passkeyStatus={passkeyStatus}
passkeySupported={passkeySupported}
passkeyRegisterLoading={passkeyRegisterLoading}
passkeyDeleteLoading={passkeyDeleteLoading}
onPasskeyRegister={handleRegisterPasskey}
onPasskeyDelete={handleRemovePasskey}
/>
);
case 'notification':
return (
<NotificationSection
{...commonProps}
notificationSettings={notificationSettings}
handleNotificationSettingChange={handleNotificationSettingChange}
saveNotificationSettings={saveNotificationSettings}
/>
);
default:
return null;
}
};
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>
</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>
{/* 余额显示 */}
<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>
{/* 快捷统计 */}
<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>
</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'>
{renderContent()}
</div>
</div>
{/* 模态框 */}
<EmailBindModal
t={t}
showEmailBindModal={showEmailBindModal}
setShowEmailBindModal={setShowEmailBindModal}
inputs={inputs}
handleInputChange={handleInputChange}
sendVerificationCode={sendVerificationCode}
bindEmail={bindEmail}
disableButton={disableButton}
loading={loading}
countdown={countdown}
turnstileEnabled={turnstileEnabled}
turnstileSiteKey={turnstileSiteKey}
setTurnstileToken={setTurnstileToken}
/>
<WeChatBindModal
t={t}
showWeChatBindModal={showWeChatBindModal}
setShowWeChatBindModal={setShowWeChatBindModal}
inputs={inputs}
handleInputChange={handleInputChange}
bindWeChat={bindWeChat}
status={status}
/>
<AccountDeleteModal
t={t}
showAccountDeleteModal={showAccountDeleteModal}
setShowAccountDeleteModal={setShowAccountDeleteModal}
inputs={inputs}
handleInputChange={handleInputChange}
deleteAccount={deleteAccount}
userState={userState}
turnstileEnabled={turnstileEnabled}
turnstileSiteKey={turnstileSiteKey}
setTurnstileToken={setTurnstileToken}
/>
<ChangePasswordModal
t={t}
showChangePasswordModal={showChangePasswordModal}
setShowChangePasswordModal={setShowChangePasswordModal}
inputs={inputs}
handleInputChange={handleInputChange}
changePassword={changePassword}
hasPassword={hasPassword}
turnstileEnabled={turnstileEnabled}
turnstileSiteKey={turnstileSiteKey}
setTurnstileToken={setTurnstileToken}
/>
</div>
);
};
export default PersonalSetting;