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
@@ -0,0 +1,323 @@
/*
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, { useState } from 'react';
import { Button, Popover, Typography, Modal } from '@douyinfe/semi-ui';
import { IconMail, IconShield, IconGithubLogo } from '@douyinfe/semi-icons';
import { Link2, ExternalLink, Check, X } from 'lucide-react';
import {
TelegramBrandIcon,
WechatBrandIcon,
LinuxBrandIcon,
DiscordBrandIcon,
} from '../../../common/icons/BrandIcons';
import TelegramLoginButton from 'react-telegram-login';
import {
onGitHubOAuthClicked,
onOIDCClicked,
onLinuxDOOAuthClicked,
onDiscordOAuthClicked,
} from '../../../../helpers';
// 绑定卡片配置
const BINDING_CARDS = [
{
key: 'email',
icon: IconMail,
gradient: 'from-blue-500 to-cyan-500',
panelClass:
'bg-gradient-to-br from-blue-50/78 to-cyan-50/70 dark:from-blue-500/[0.09] dark:to-cyan-400/[0.07]',
},
{
key: 'wechat',
icon: WechatBrandIcon,
gradient: 'from-green-500 to-emerald-500',
panelClass:
'bg-gradient-to-br from-green-50/78 to-emerald-50/70 dark:from-green-500/[0.09] dark:to-emerald-400/[0.07]',
isBrandIcon: true,
},
{
key: 'github',
icon: IconGithubLogo,
gradient: 'from-gray-700 to-gray-900',
panelClass:
'bg-gradient-to-br from-gray-50/88 to-slate-50/75 dark:from-slate-500/[0.10] dark:to-slate-700/[0.10]',
},
{
key: 'discord',
icon: DiscordBrandIcon,
gradient: 'from-brand-from to-brand-to',
panelClass:
'bg-gradient-to-br from-brand-from/10 to-brand-to/10 dark:from-brand-from/[0.14] dark:to-brand-to/[0.12]',
isBrandIcon: true,
},
{
key: 'oidc',
icon: IconShield,
gradient: 'from-orange-500 to-red-500',
panelClass:
'bg-gradient-to-br from-orange-50/78 to-red-50/70 dark:from-orange-500/[0.10] dark:to-red-500/[0.08]',
},
{
key: 'telegram',
icon: TelegramBrandIcon,
gradient: 'from-sky-500 to-blue-500',
panelClass:
'bg-gradient-to-br from-sky-50/78 to-blue-50/70 dark:from-sky-500/[0.10] dark:to-blue-500/[0.08]',
isBrandIcon: true,
},
{
key: 'linuxdo',
icon: LinuxBrandIcon,
gradient: 'from-yellow-500 to-orange-500',
panelClass:
'bg-gradient-to-br from-yellow-50/78 to-orange-50/70 dark:from-yellow-500/[0.10] dark:to-orange-500/[0.08]',
isBrandIcon: true,
},
];
const AccountBindingSection = ({
t,
userState,
status,
setShowEmailBindModal,
setShowWeChatBindModal,
}) => {
const [showTelegramBindModal, setShowTelegramBindModal] = useState(false);
const isBound = (accountId) => Boolean(accountId);
const renderAccountInfo = (accountId, label) => {
if (!accountId || accountId === '') {
return <span className='text-gray-400'>{t('未绑定')}</span>;
}
const popContent = (
<div className='text-xs p-2'>
<Typography.Paragraph copyable={{ content: accountId }}>
{accountId}
</Typography.Paragraph>
{label && <div className='mt-1 text-[11px] text-gray-500'>{label}</div>}
</div>
);
return (
<Popover content={popContent} position='top' trigger='hover'>
<span className='text-sm text-gray-600 dark:text-gray-300 hover:text-blue-600 cursor-pointer truncate max-w-[120px] inline-block'>
{accountId}
</span>
</Popover>
);
};
const getBindingData = (key) => {
switch (key) {
case 'email':
return {
name: t('邮箱'),
value: userState.user?.email,
label: t('邮箱地址'),
enabled: true,
onBind: () => setShowEmailBindModal(true),
};
case 'wechat':
return {
name: t('微信'),
value: userState.user?.wechat_id,
label: t('微信账号'),
enabled: status.wechat_login,
onBind: () => setShowWeChatBindModal(true),
};
case 'github':
return {
name: 'GitHub',
value: userState.user?.github_id,
label: 'GitHub ID',
enabled: status.github_oauth,
onBind: () => onGitHubOAuthClicked(status.github_client_id),
disableWhenBound: true,
};
case 'discord':
return {
name: 'Discord',
value: userState.user?.discord_id,
label: 'Discord ID',
enabled: status.discord_oauth,
onBind: () => onDiscordOAuthClicked(status.discord_client_id),
disableWhenBound: true,
};
case 'oidc':
return {
name: 'OIDC',
value: userState.user?.oidc_id,
label: 'OIDC ID',
enabled: status.oidc_enabled,
onBind: () =>
onOIDCClicked(
status.oidc_authorization_endpoint,
status.oidc_client_id,
),
disableWhenBound: true,
};
case 'telegram':
return {
name: 'Telegram',
value: userState.user?.telegram_id,
label: 'Telegram ID',
enabled: status.telegram_oauth,
onBind: () => setShowTelegramBindModal(true),
disableWhenBound: true,
};
case 'linuxdo':
return {
name: 'LinuxDO',
value: userState.user?.linux_do_id,
label: 'LinuxDO ID',
enabled: status.linuxdo_oauth,
onBind: () => onLinuxDOOAuthClicked(status.linuxdo_client_id),
disableWhenBound: true,
};
default:
return null;
}
};
return (
<div className='space-y-6'>
{/* 页面标题 */}
<div className='flex items-center gap-3 rounded-3xl border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl px-5 py-4'>
<div className='w-11 h-11 rounded-2xl bg-gradient-to-br from-sky-500 to-cyan-400 flex items-center justify-center shadow-lg shadow-sky-500/20'>
<Link2 className='w-5 h-5 text-white' />
</div>
<div>
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
{t('账号绑定')}
</h2>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{t('管理邮箱和第三方登录方式')}
</p>
</div>
</div>
{/* 绑定卡片网格 */}
<div className='grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4'>
{BINDING_CARDS.map((card) => {
const data = getBindingData(card.key);
if (!data) return null;
// 未启用的绑定方式不显示卡片
if (!data.enabled) return null;
const Icon = card.icon;
const bound = isBound(data.value);
const disabled = data.disableWhenBound && bound;
return (
<div
key={card.key}
className={`relative group p-5 rounded-[22px] border backdrop-blur-xl transition-all duration-300 ${
bound
? 'bg-white/62 dark:bg-white/[0.055] border-white/70 dark:border-white/10'
: `${card.panelClass} border-white/70 dark:border-white/10 hover:border-white dark:hover:border-white/20`
} hover:shadow-[0_18px_45px_rgba(15,23,42,0.10)] hover:-translate-y-0.5`}
>
{/* 状态指示器 */}
<div className='absolute top-3 right-3'>
{bound ? (
<div className='flex items-center gap-1 px-2 py-0.5 bg-emerald-100 dark:bg-emerald-900/30 text-emerald-600 dark:text-emerald-400 rounded-full text-xs font-medium'>
<Check size={12} />
{t('已绑定')}
</div>
) : (
<div className='flex items-center gap-1 px-2 py-0.5 bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 rounded-full text-xs'>
<X size={12} />
{t('未绑定')}
</div>
)}
</div>
{/* 图标和名称 */}
<div className='flex items-center gap-3 mb-4 pr-20'>
<div
className={`w-12 h-12 rounded-2xl flex items-center justify-center bg-gradient-to-br ${card.gradient} shadow-lg`}
>
{card.isBrandIcon ? (
<Icon size={24} color='#FFFFFF' />
) : (
<Icon size='extra-large' className='text-white' />
)}
</div>
<div className='min-w-0'>
<h3 className='font-semibold text-gray-900 dark:text-white'>
{data.name}
</h3>
<div className='text-sm'>
{bound ? renderAccountInfo(data.value, data.label) : null}
</div>
</div>
</div>
{/* 操作按钮 */}
<Button
theme={bound ? 'light' : 'solid'}
type='primary'
size='small'
disabled={disabled}
onClick={data.onBind}
className={`w-full !rounded-lg ${
!bound
? `!bg-gradient-to-r ${card.gradient} !border-0 hover:opacity-90`
: ''
}`}
icon={bound ? null : <ExternalLink size={14} />}
>
{bound
? data.disableWhenBound
? t('已绑定')
: t('修改绑定')
: t('立即绑定')}
</Button>
</div>
);
})}
</div>
{/* Telegram 绑定弹窗 */}
<Modal
title={t('绑定 Telegram')}
visible={showTelegramBindModal}
onCancel={() => setShowTelegramBindModal(false)}
footer={null}
>
<div className='my-3 text-sm text-gray-600'>
{t('点击下方按钮通过 Telegram 完成绑定')}
</div>
<div className='flex justify-center'>
<div className='scale-90'>
<TelegramLoginButton
dataAuthUrl='/api/oauth/telegram/bind'
botName={status.telegram_bot_name}
/>
</div>
</div>
</Modal>
</div>
);
};
export default AccountBindingSection;
@@ -0,0 +1,234 @@
/*
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 from 'react';
import { Button, Input, Radio, RadioGroup, Tag } from '@douyinfe/semi-ui';
import { Image, Palette, Sparkles, Type, Wand2 } from 'lucide-react';
import {
CARTOON_AVATAR_PRESETS,
USER_AVATAR_TYPES,
getCartoonAvatarDataUrl,
getInitialAvatarDataUrl,
} from '../../../../helpers';
const AVATAR_TYPE_OPTIONS = [
{
value: USER_AVATAR_TYPES.PRESET,
label: '卡通形象',
desc: '从系统内置卡通头像中选择,适合默认展示',
icon: Palette,
},
{
value: USER_AVATAR_TYPES.INITIAL,
label: '姓名首字',
desc: '根据用户名自动生成简洁文字头像',
icon: Type,
},
{
value: USER_AVATAR_TYPES.CUSTOM,
label: '图片链接',
desc: '填写公网图片 URL,使用自己的头像',
icon: Image,
},
];
const AvatarSection = ({
t,
userState,
avatarSettings,
handleAvatarSettingChange,
saveAvatarSettings,
savingAvatarSettings,
}) => {
const username =
userState?.user?.display_name || userState?.user?.username || 'User';
const previewUrl =
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
avatarSettings.customAvatarUrl
? avatarSettings.customAvatarUrl
: avatarSettings.avatarType === USER_AVATAR_TYPES.INITIAL
? getInitialAvatarDataUrl(username, 128)
: getCartoonAvatarDataUrl(avatarSettings.avatarPreset, 128);
const customAvatarInvalid =
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
!avatarSettings.customAvatarUrl?.trim();
return (
<div className='space-y-6'>
<div className='flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 rounded-3xl border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl px-5 py-4'>
<div className='flex items-center gap-3'>
<div className='w-11 h-11 rounded-2xl bg-gradient-to-br from-rose-500 to-orange-400 flex items-center justify-center shadow-lg shadow-rose-500/20'>
<Wand2 className='w-5 h-5 text-white' />
</div>
<div>
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
{t('头像设置')}
</h2>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{t('选择你在平台内展示的头像样式')}
</p>
</div>
</div>
<Button
theme='solid'
loading={savingAvatarSettings}
disabled={customAvatarInvalid}
onClick={saveAvatarSettings}
className='!bg-gradient-to-r !from-rose-500 !to-orange-400 !border-0 !rounded-xl !shadow-lg !shadow-rose-500/20'
>
{t('保存头像')}
</Button>
</div>
<div className='grid grid-cols-1 xl:grid-cols-[280px_1fr] gap-5'>
<div className='relative overflow-hidden rounded-[28px] border border-white/70 dark:border-white/10 bg-white/[0.54] dark:bg-white/[0.045] p-5 shadow-[0_20px_55px_rgba(244,63,94,0.10)]'>
<div className='absolute inset-0 bg-[radial-gradient(circle_at_25%_20%,rgba(251,113,133,0.22),transparent_32%),radial-gradient(circle_at_90%_85%,rgba(251,146,60,0.16),transparent_34%)] pointer-events-none' />
<div className='relative flex flex-col items-center text-center'>
<div className='relative mb-4'>
<div className='absolute inset-0 rounded-[32px] bg-gradient-to-br from-rose-500 to-orange-400 blur-lg opacity-30' />
<img
src={previewUrl}
alt={t('头像预览')}
className='relative w-28 h-28 rounded-[32px] object-cover ring-4 ring-white/90 dark:ring-slate-950 shadow-xl'
/>
<span className='absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-emerald-500 border-4 border-white dark:border-slate-950' />
</div>
<div className='text-base font-semibold text-gray-900 dark:text-white'>
{username}
</div>
<div className='mt-2 text-xs text-gray-500 dark:text-gray-400 leading-relaxed'>
{t('该头像会同步展示在右上角用户入口和体验中心文本对话中。')}
</div>
<Tag
color='pink'
shape='circle'
className='mt-4 !bg-white/70 dark:!bg-white/[0.08]'
>
{t('实时预览')}
</Tag>
</div>
</div>
<div className='rounded-[28px] border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl p-5'>
<div className='mb-5'>
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3'>
{t('头像类型')}
</label>
<RadioGroup
type='button'
value={avatarSettings.avatarType}
onChange={(e) =>
handleAvatarSettingChange('avatarType', e.target.value)
}
className='!flex !flex-wrap !gap-2'
>
{AVATAR_TYPE_OPTIONS.map((option) => {
const Icon = option.icon;
return (
<Radio key={option.value} value={option.value}>
<span className='inline-flex items-center gap-1.5'>
<Icon size={14} />
{t(option.label)}
</span>
</Radio>
);
})}
</RadioGroup>
<p className='mt-2 text-xs text-gray-500 dark:text-gray-400'>
{t(
AVATAR_TYPE_OPTIONS.find(
(item) => item.value === avatarSettings.avatarType,
)?.desc || '',
)}
</p>
</div>
{avatarSettings.avatarType === USER_AVATAR_TYPES.PRESET && (
<div>
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3'>
{t('选择卡通形象')}
</label>
<div className='grid grid-cols-2 sm:grid-cols-4 gap-3'>
{CARTOON_AVATAR_PRESETS.map((preset) => {
const selected = avatarSettings.avatarPreset === preset.id;
return (
<button
key={preset.id}
type='button'
onClick={() => {
handleAvatarSettingChange(
'avatarType',
USER_AVATAR_TYPES.PRESET,
);
handleAvatarSettingChange('avatarPreset', preset.id);
}}
className={`group relative rounded-2xl border p-3 transition-all duration-200 ${
selected
? 'border-rose-300 bg-white/[0.82] dark:bg-white/[0.08] shadow-lg shadow-rose-500/10'
: 'border-white/70 dark:border-white/10 bg-white/[0.46] dark:bg-white/[0.035] hover:border-rose-200 dark:hover:border-rose-400/25'
}`}
>
<img
src={getCartoonAvatarDataUrl(preset.id, 96)}
alt={preset.label}
className='mx-auto w-14 h-14 rounded-2xl object-cover transition-transform group-hover:scale-105'
/>
<div className='mt-2 text-xs font-medium text-gray-700 dark:text-gray-200 truncate'>
{t(preset.label)}
</div>
{selected && (
<Sparkles
size={16}
className='absolute top-2 right-2 text-rose-500'
/>
)}
</button>
);
})}
</div>
</div>
)}
{avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM && (
<div className='rounded-2xl border border-sky-100 dark:border-sky-400/20 bg-sky-50/[0.55] dark:bg-sky-400/[0.06] p-4'>
<Input
value={avatarSettings.customAvatarUrl}
onChange={(value) =>
handleAvatarSettingChange('customAvatarUrl', value)
}
placeholder={t(
'请输入图片 URL,例如 https://example.com/avatar.png',
)}
prefix={<Image size={15} className='text-sky-500' />}
showClear
/>
<p className='mt-2 text-xs text-gray-500 dark:text-gray-400'>
{t('支持公网图片链接。若图片加载失败,会回退到默认卡通头像。')}
</p>
</div>
)}
</div>
</div>
</div>
);
};
export default AvatarSection;
@@ -0,0 +1,271 @@
/*
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, { useRef, useEffect } from 'react';
import { Button, Form, Toast } from '@douyinfe/semi-ui';
import { IconMail, IconKey, IconLink } from '@douyinfe/semi-icons';
import { Bell, Mail, Save, Webhook } from 'lucide-react';
import { FormQuotaInput } from '../../../common/ui/QuotaInput';
import CodeViewer from '../../../playground/CodeViewer';
const NotificationSection = ({
t,
notificationSettings,
handleNotificationSettingChange,
saveNotificationSettings,
}) => {
const formApiRef = useRef(null);
useEffect(() => {
if (formApiRef.current && notificationSettings) {
formApiRef.current.setValues(notificationSettings);
}
}, [notificationSettings]);
const handleFormChange = (field, value) => {
handleNotificationSettingChange(field, value);
};
const handleSubmit = () => {
if (formApiRef.current) {
formApiRef.current
.validate()
.then(() => {
saveNotificationSettings();
})
.catch((errors) => {
console.log('表单验证失败:', errors);
Toast.error(t('请检查表单填写是否正确'));
});
} else {
saveNotificationSettings();
}
};
// 通知方式选项(仅保留邮件通知和Webhook)
const notifyOptions = [
{
value: 'email',
label: t('邮件提醒'),
desc: t('发送到绑定邮箱或指定邮箱'),
icon: Mail,
selectedClass:
'border-sky-300 bg-sky-50/82 dark:bg-sky-500/[0.10] dark:border-sky-400/25',
iconClass: 'text-sky-500',
textClass: 'text-sky-700 dark:text-sky-300',
},
{
value: 'webhook',
label: 'Webhook',
desc: t('将提醒推送到外部系统'),
icon: Webhook,
selectedClass:
'border-amber-300 bg-amber-50/82 dark:bg-amber-500/[0.10] dark:border-amber-400/25',
iconClass: 'text-amber-500',
textClass: 'text-amber-700 dark:text-amber-300',
},
];
return (
<div className='space-y-6'>
{/* 页面标题 */}
<div className='flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 rounded-3xl border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl px-5 py-4'>
<div className='flex items-center gap-3'>
<div className='w-11 h-11 rounded-2xl bg-gradient-to-br from-amber-500 to-yellow-400 flex items-center justify-center shadow-lg shadow-amber-500/20'>
<Bell className='w-5 h-5 text-white' />
</div>
<div>
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
{t('通知设置')}
</h2>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{t('设置额度预警和系统提醒接收方式')}
</p>
</div>
</div>
<Button
theme='solid'
onClick={handleSubmit}
icon={<Save size={15} />}
className='!bg-gradient-to-r !from-amber-500 !to-yellow-400 !border-0 !rounded-xl !shadow-lg !shadow-amber-500/20'
>
{t('保存设置')}
</Button>
</div>
{/* 表单内容 */}
<div className='bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl rounded-[28px] border border-white/70 dark:border-white/10 p-5 sm:p-6'>
<Form
getFormApi={(api) => (formApiRef.current = api)}
initValues={notificationSettings}
onSubmit={handleSubmit}
>
{/* 通知方式选择 */}
<div className='mb-6'>
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3'>
{t('通知方式')}
</label>
<div className='grid grid-cols-1 sm:grid-cols-2 gap-3'>
{notifyOptions.map((option) => {
const Icon = option.icon;
const isSelected =
notificationSettings.warningType === option.value;
return (
<button
key={option.value}
type='button'
onClick={() =>
handleFormChange('warningType', option.value)
}
className={`p-4 rounded-2xl border transition-all text-left ${
isSelected
? option.selectedClass
: 'border-white/70 dark:border-white/10 bg-white/48 dark:bg-white/[0.035] hover:bg-white/72 dark:hover:bg-white/[0.07]'
}`}
>
<div className='flex items-center gap-3'>
<div className='w-10 h-10 rounded-2xl bg-white/70 dark:bg-white/[0.07] flex items-center justify-center'>
<Icon
size={20}
className={isSelected ? option.iconClass : 'text-gray-400'}
/>
</div>
<div className='min-w-0'>
<div
className={`text-sm font-semibold ${
isSelected
? option.textClass
: 'text-gray-700 dark:text-gray-200'
}`}
>
{option.label}
</div>
<div className='mt-0.5 text-xs text-gray-500 dark:text-gray-400 truncate'>
{option.desc}
</div>
</div>
</div>
</button>
);
})}
</div>
</div>
{/* 预警阈值 */}
<FormQuotaInput
field='warningThreshold'
label={t('额度预警阈值')}
onChange={(val) => handleFormChange('warningThreshold', val)}
extraText={t(
'当剩余额度低于此数值时,系统将通过选择的方式发送通知',
)}
style={{ maxWidth: '320px', width: '100%' }}
rules={[
{ required: true, message: t('请输入预警阈值') },
{
validator: (rule, value) => {
const numValue = Number(value);
if (isNaN(numValue) || numValue <= 0) {
return Promise.reject(t('预警阈值必须为正数'));
}
return Promise.resolve();
},
},
]}
/>
{/* 邮件通知设置 */}
{notificationSettings.warningType === 'email' && (
<div className='mt-4 p-4 bg-sky-50/55 dark:bg-sky-500/[0.07] rounded-2xl border border-sky-100 dark:border-sky-400/20'>
<Form.Input
field='notificationEmail'
label={t('通知邮箱')}
placeholder={t('留空则使用账号绑定的邮箱')}
onChange={(val) => handleFormChange('notificationEmail', val)}
prefix={<IconMail />}
extraText={t(
'设置用于接收额度预警的邮箱地址,不填则使用账号绑定的邮箱',
)}
showClear
/>
</div>
)}
{/* Webhook通知设置 */}
{notificationSettings.warningType === 'webhook' && (
<div className='mt-4 p-4 bg-amber-50/55 dark:bg-amber-500/[0.07] rounded-2xl border border-amber-100 dark:border-amber-400/20 space-y-4'>
<Form.Input
field='webhookUrl'
label={t('Webhook地址')}
placeholder={t(
'请输入Webhook地址,例如: https://example.com/webhook',
)}
onChange={(val) => handleFormChange('webhookUrl', val)}
prefix={<IconLink />}
extraText={t('只支持HTTPS,系统将以POST方式发送通知')}
showClear
rules={[
{
required: notificationSettings.warningType === 'webhook',
message: t('请输入Webhook地址'),
},
{
pattern: /^https:\/\/.+/,
message: t('Webhook地址必须以https://开头'),
},
]}
/>
<Form.Input
field='webhookSecret'
label={t('接口凭证')}
placeholder={t('请输入密钥')}
onChange={(val) => handleFormChange('webhookSecret', val)}
prefix={<IconKey />}
extraText={t('密钥将以Bearer方式添加到请求头中')}
showClear
/>
<div>
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
{t('Webhook请求结构说明')}
</label>
<div style={{ height: '180px' }}>
<CodeViewer
content={{
type: 'quota_exceed',
title: '额度预警通知',
content: '您的额度即将用尽,当前剩余额度为 {{value}}',
values: ['¥0.99'],
timestamp: 1739950503,
}}
title='webhook'
language='json'
/>
</div>
</div>
</div>
)}
</Form>
</div>
</div>
);
};
export default NotificationSection;
@@ -0,0 +1,146 @@
/*
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 from 'react';
import { Button, Switch } from '@douyinfe/semi-ui';
import { Lock, Eye, DollarSign, MapPin } from 'lucide-react';
const PrivacySection = ({
t,
notificationSettings,
handleNotificationSettingChange,
saveNotificationSettings,
}) => {
// 隐私设置卡片
const PrivacyCard = ({
icon: Icon,
gradient,
title,
description,
checked,
onChange,
}) => (
<div className='p-5 rounded-xl bg-white/50 dark:bg-gray-800/50 border border-gray-100 dark:border-gray-700/50 hover:shadow-lg transition-all'>
<div className='flex items-start gap-4'>
<div
className={`w-12 h-12 rounded-xl flex items-center justify-center bg-gradient-to-br ${gradient} shadow-lg flex-shrink-0`}
>
<Icon className='w-6 h-6 text-white' />
</div>
<div className='flex-1 min-w-0'>
<div className='flex items-center justify-between'>
<div>
<h3 className='font-semibold text-gray-900 dark:text-white mb-1'>
{title}
</h3>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{description}
</p>
</div>
<Switch
checked={checked}
onChange={onChange}
size='large'
checkedText={t('开')}
uncheckedText={t('关')}
/>
</div>
</div>
</div>
</div>
);
return (
<div>
{/* 页面标题 */}
<div className='flex items-center justify-between mb-6'>
<div className='flex items-center gap-3'>
<div className='w-10 h-10 rounded-xl bg-gradient-to-br from-brand-from to-pink-600 flex items-center justify-center shadow-lg shadow-brand/25'>
<Lock className='w-5 h-5 text-white' />
</div>
<div>
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
{t('隐私设置')}
</h2>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{t('控制您的数据记录和价格偏好')}
</p>
</div>
</div>
<Button
theme='solid'
onClick={saveNotificationSettings}
className='!bg-gradient-to-r !from-brand-from !to-pink-500 !border-0 !rounded-lg'
>
{t('保存设置')}
</Button>
</div>
{/* 隐私设置列表 */}
<div className='space-y-4'>
{/* IP记录设置 */}
<PrivacyCard
icon={MapPin}
gradient='from-rose-500 to-pink-500'
title={t('记录请求与错误日志IP')}
description={t('开启后,仅"消费"和"错误"日志将记录您的客户端IP地址')}
checked={notificationSettings.recordIpLog}
onChange={(value) =>
handleNotificationSettingChange('recordIpLog', value)
}
/>
{/* 未设置价格模型 */}
<PrivacyCard
icon={DollarSign}
gradient='from-amber-500 to-orange-500'
title={t('接受未设置价格模型')}
description={t(
'当模型没有设置价格时仍接受调用,仅当您信任该网站时使用,可能会产生高额费用',
)}
checked={notificationSettings.acceptUnsetModelRatioModel}
onChange={(value) =>
handleNotificationSettingChange('acceptUnsetModelRatioModel', value)
}
/>
</div>
{/* 提示信息 */}
<div className='mt-6 p-4 bg-brand/50 dark:bg-brand-deep/10 rounded-xl border border-brand/10 dark:border-brand-deep/30'>
<div className='flex items-start gap-3'>
<div className='w-8 h-8 rounded-lg bg-brand/10 dark:bg-brand-deep/30 flex items-center justify-center flex-shrink-0'>
<Eye size={16} className='text-brand' />
</div>
<div>
<h4 className='font-medium text-gray-900 dark:text-white mb-1'>
{t('隐私提示')}
</h4>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{t(
'我们重视您的隐私。您的设置选择将仅应用于您的账户,不会影响其他用户。如需删除历史数据,请联系客服。',
)}
</p>
</div>
</div>
</div>
</div>
);
};
export default PrivacySection;
@@ -0,0 +1,205 @@
/*
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 from 'react';
import { Button, Modal } from '@douyinfe/semi-ui';
import { IconLock, IconDelete } from '@douyinfe/semi-icons';
import { Shield, Lock, Fingerprint, Trash2, AlertTriangle } from 'lucide-react';
const SecuritySection = ({
t,
status,
setShowChangePasswordModal,
setShowAccountDeleteModal,
hasPassword,
passkeyStatus,
passkeySupported,
passkeyRegisterLoading,
passkeyDeleteLoading,
onPasskeyRegister,
onPasskeyDelete,
}) => {
const passkeyEnabled = passkeyStatus?.enabled;
const lastUsedLabel = passkeyStatus?.last_used_at
? new Date(passkeyStatus.last_used_at).toLocaleString()
: t('尚未使用');
// 安全设置卡片
const SecurityCard = ({
icon: Icon,
gradient,
title,
description,
children,
danger = false,
}) => (
<div
className={`p-5 rounded-[24px] border backdrop-blur-xl transition-all ${
danger
? 'bg-gradient-to-br from-red-50/70 to-rose-50/60 dark:from-red-500/[0.09] dark:to-rose-500/[0.07] border-red-100/80 dark:border-red-400/20'
: 'bg-white/54 dark:bg-white/[0.045] border-white/70 dark:border-white/10'
} hover:shadow-[0_18px_50px_rgba(15,23,42,0.10)]`}
>
<div className='flex items-start gap-4'>
<div
className={`w-12 h-12 rounded-2xl flex items-center justify-center bg-gradient-to-br ${gradient} shadow-lg flex-shrink-0`}
>
<Icon className='w-6 h-6 text-white' />
</div>
<div className='flex-1 min-w-0'>
<h3 className='font-semibold text-gray-900 dark:text-white mb-1'>
{title}
</h3>
<p className='text-sm text-gray-500 dark:text-gray-400 mb-4'>
{description}
</p>
{children}
</div>
</div>
</div>
);
return (
<div className='space-y-6'>
{/* 页面标题 */}
<div className='flex items-center gap-3 rounded-3xl border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl px-5 py-4'>
<div className='w-11 h-11 rounded-2xl bg-gradient-to-br from-emerald-500 to-teal-400 flex items-center justify-center shadow-lg shadow-emerald-500/20'>
<Shield className='w-5 h-5 text-white' />
</div>
<div>
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
{t('安全设置')}
</h2>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{t('集中管理密码和免密登录')}
</p>
</div>
</div>
{/* 安全设置卡片列表 */}
<div className='space-y-4'>
{/* 密码管理 */}
<SecurityCard
icon={Lock}
gradient='from-blue-500 to-brand-to'
title={t('密码管理')}
description={
hasPassword
? t('定期更改密码可以提高账户安全性')
: t('设置密码后可使用账号密码登录')
}
>
<Button
theme='solid'
onClick={() => setShowChangePasswordModal(true)}
className='!bg-gradient-to-r !from-blue-500 !to-brand-to !border-0 !rounded-lg'
icon={<IconLock />}
>
{hasPassword ? t('修改密码') : t('设置密码')}
</Button>
</SecurityCard>
{/* Passkey 登录 - 仅管理员启用时显示 */}
{status.passkey_login && (
<SecurityCard
icon={Fingerprint}
gradient={
passkeyEnabled
? 'from-emerald-500 to-teal-500'
: 'from-brand-from to-pink-500'
}
title={t('Passkey 登录')}
description={
passkeyEnabled
? t('已启用 Passkey,无需密码即可登录')
: t('使用 Passkey 实现免密且更安全的登录体验')
}
>
<div className='mb-4 space-y-2'>
<div className='flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400'>
<span>{t('最后使用时间')}:</span>
<span className='font-medium text-gray-700 dark:text-gray-300'>
{lastUsedLabel}
</span>
</div>
{!passkeySupported && (
<div className='flex items-center gap-2 text-sm text-amber-600 dark:text-amber-400'>
<AlertTriangle size={14} />
{t('当前设备不支持 Passkey')}
</div>
)}
</div>
<Button
theme='solid'
type={passkeyEnabled ? 'danger' : 'primary'}
onClick={
passkeyEnabled
? () => {
Modal.confirm({
title: t('确认解绑 Passkey'),
content: t(
'解绑后将无法使用 Passkey 登录,确定要继续吗?',
),
okText: t('确认解绑'),
cancelText: t('取消'),
okType: 'danger',
onOk: onPasskeyDelete,
});
}
: onPasskeyRegister
}
className={`!rounded-lg ${
passkeyEnabled
? '!bg-gradient-to-r !from-red-500 !to-rose-500 !border-0'
: '!bg-gradient-to-r !from-brand-from !to-pink-500 !border-0'
}`}
disabled={!passkeySupported && !passkeyEnabled}
loading={
passkeyEnabled ? passkeyDeleteLoading : passkeyRegisterLoading
}
>
{passkeyEnabled ? t('解绑 Passkey') : t('注册 Passkey')}
</Button>
</SecurityCard>
)}
{/* 危险区域 - 删除账户 */}
<SecurityCard
icon={Trash2}
gradient='from-red-500 to-rose-500'
title={t('删除账户')}
description={t('此操作不可逆,所有数据将被永久删除')}
danger
>
<Button
type='danger'
theme='solid'
onClick={() => setShowAccountDeleteModal(true)}
className='!bg-gradient-to-r !from-red-500 !to-rose-500 !border-0 !rounded-lg'
icon={<IconDelete />}
>
{t('删除账户')}
</Button>
</SecurityCard>
</div>
</div>
);
};
export default SecuritySection;
@@ -0,0 +1,373 @@
/*
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, { useState, useEffect, useContext } from 'react';
import { Button, Switch, Row, Col } from '@douyinfe/semi-ui';
import {
LayoutGrid,
MessageSquare,
BarChart2,
User,
Shield,
} from 'lucide-react';
import { API, showSuccess, showError } from '../../../../helpers';
import { StatusContext } from '../../../../context/Status';
import { useUserPermissions } from '../../../../hooks/common/useUserPermissions';
import { useSidebar } from '../../../../hooks/common/useSidebar';
const SidebarSection = ({ t }) => {
const [statusState] = useContext(StatusContext);
const [sidebarLoading, setSidebarLoading] = useState(false);
const [sidebarModulesUser, setSidebarModulesUser] = useState({
chat: { enabled: true, playground: true, chat: true },
console: {
enabled: true,
detail: true,
token: true,
log: true,
midjourney: true,
task: true,
monitor: true,
},
personal: { enabled: true, topup: true, personal: true },
admin: {
enabled: true,
analytics: true,
channel: true,
models: true,
redemption: true,
user: true,
subscription: true,
'admin-token': true,
organizations: true,
order: true,
invoice: true,
setting: true,
},
});
const [adminConfig, setAdminConfig] = useState(null);
const {
hasSidebarSettingsPermission,
isSidebarSectionAllowed,
isSidebarModuleAllowed,
} = useUserPermissions();
const { refreshUserConfig } = useSidebar();
const handleSectionChange = (sectionKey) => (checked) => {
setSidebarModulesUser((prev) => ({
...prev,
[sectionKey]: { ...prev[sectionKey], enabled: checked },
}));
};
const handleModuleChange = (sectionKey, moduleKey) => (checked) => {
setSidebarModulesUser((prev) => ({
...prev,
[sectionKey]: { ...prev[sectionKey], [moduleKey]: checked },
}));
};
const saveSidebarSettings = async () => {
setSidebarLoading(true);
try {
const res = await API.put('/api/user/self', {
sidebar_modules: JSON.stringify(sidebarModulesUser),
});
if (res.data.success) {
showSuccess(t('侧边栏设置保存成功'));
await refreshUserConfig();
} else {
showError(res.data.message);
}
} catch (error) {
showError(t('保存失败'));
}
setSidebarLoading(false);
};
const resetSidebarModules = () => {
setSidebarModulesUser({
chat: { enabled: true, playground: true, chat: true },
console: {
enabled: true,
detail: true,
token: true,
log: true,
midjourney: true,
task: true,
},
personal: { enabled: true, topup: true, personal: true },
admin: {
enabled: true,
channel: true,
models: true,
redemption: true,
user: true,
setting: true,
},
});
};
useEffect(() => {
const loadSidebarConfigs = async () => {
try {
if (statusState?.status?.SidebarModulesAdmin) {
setAdminConfig(JSON.parse(statusState.status.SidebarModulesAdmin));
}
const userRes = await API.get('/api/user/self');
if (userRes.data.success && userRes.data.data.sidebar_modules) {
setSidebarModulesUser(JSON.parse(userRes.data.data.sidebar_modules));
}
} catch (error) {
console.error('加载边栏配置失败:', error);
}
};
loadSidebarConfigs();
}, [statusState]);
const isAllowedByAdmin = (sectionKey, moduleKey = null) => {
if (!adminConfig) return true;
if (moduleKey) {
return (
adminConfig[sectionKey]?.enabled && adminConfig[sectionKey]?.[moduleKey]
);
}
return adminConfig[sectionKey]?.enabled;
};
// 区域配置
const sectionConfigs = [
{
key: 'chat',
title: t('聊天区域'),
description: t('操练场和聊天功能'),
icon: MessageSquare,
gradient: 'from-blue-500 to-cyan-500',
modules: [
{
key: 'playground',
title: t('操练场'),
description: t('AI模型测试环境'),
},
{ key: 'chat', title: t('聊天'), description: t('聊天会话管理') },
],
},
{
key: 'console',
title: t('控制台区域'),
description: t('数据管理和日志查看'),
icon: BarChart2,
gradient: 'from-emerald-500 to-teal-500',
modules: [
{ key: 'detail', title: t('数据看板'), description: t('系统数据统计') },
{ key: 'token', title: t('令牌管理'), description: t('API令牌管理') },
{ key: 'log', title: t('使用日志'), description: t('API使用记录') },
{
key: 'midjourney',
title: t('绘图日志'),
description: t('绘图任务记录'),
},
{ key: 'task', title: t('任务日志'), description: t('系统任务记录') },
],
},
{
key: 'personal',
title: t('个人中心区域'),
description: t('用户个人功能'),
icon: User,
gradient: 'from-brand-from to-pink-500',
modules: [
{ key: 'topup', title: t('钱包管理'), description: t('余额充值管理') },
{
key: 'personal',
title: t('个人设置'),
description: t('个人信息设置'),
},
],
},
{
key: 'admin',
title: t('管理员区域'),
description: t('系统管理功能'),
icon: Shield,
gradient: 'from-orange-500 to-red-500',
modules: [
{ key: 'channel', title: t('渠道管理'), description: t('API渠道配置') },
{ key: 'models', title: t('模型管理'), description: t('AI模型配置') },
{
key: 'redemption',
title: t('兑换码管理'),
description: t('兑换码生成管理'),
},
{ key: 'user', title: t('用户管理'), description: t('用户账户管理') },
{
key: 'setting',
title: t('系统设置'),
description: t('系统参数配置'),
},
],
},
]
.filter((section) => isSidebarSectionAllowed(section.key))
.map((section) => ({
...section,
modules: section.modules.filter((module) =>
isSidebarModuleAllowed(section.key, module.key),
),
}))
.filter(
(section) => section.modules.length > 0 && isAllowedByAdmin(section.key),
);
if (!hasSidebarSettingsPermission()) {
return (
<div className='flex items-center justify-center h-64 text-gray-500'>
{t('您没有权限访问此设置')}
</div>
);
}
return (
<div>
{/* 页面标题 */}
<div className='flex items-center justify-between mb-6'>
<div className='flex items-center gap-3'>
<div className='w-10 h-10 rounded-xl bg-gradient-to-br from-cyan-500 to-blue-600 flex items-center justify-center shadow-lg shadow-cyan-500/25'>
<LayoutGrid className='w-5 h-5 text-white' />
</div>
<div>
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
{t('边栏设置')}
</h2>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{t('个性化设置侧边栏的显示功能')}
</p>
</div>
</div>
<div className='flex gap-2'>
<Button
type='tertiary'
theme='light'
onClick={resetSidebarModules}
className='!rounded-lg !border !border-gray-200 dark:!border-neutral-700'
style={{ color: '#4b5563' }}
>
{t('重置为默认')}
</Button>
<Button
theme='solid'
onClick={saveSidebarSettings}
loading={sidebarLoading}
className='!bg-gradient-to-r !from-cyan-500 !to-blue-500 !border-0 !rounded-lg'
>
{t('保存设置')}
</Button>
</div>
</div>
{/* 区域设置列表 */}
<div className='space-y-6'>
{sectionConfigs.map((section) => {
const Icon = section.icon;
return (
<div
key={section.key}
className='bg-white/50 dark:bg-gray-800/50 rounded-xl border border-gray-100 dark:border-gray-700/50 overflow-hidden'
>
{/* 区域标题和总开关 */}
<div
className={`flex justify-between items-center p-5 bg-gradient-to-r ${section.gradient} bg-opacity-5`}
>
<div className='flex items-center gap-3'>
<div
className={`w-10 h-10 rounded-lg bg-gradient-to-br ${section.gradient} flex items-center justify-center shadow-lg`}
>
<Icon className='w-5 h-5 text-white' />
</div>
<div>
<h3 className='font-semibold text-gray-900 dark:text-white'>
{section.title}
</h3>
<p className='text-sm text-gray-500 dark:text-gray-400'>
{section.description}
</p>
</div>
</div>
<Switch
checked={sidebarModulesUser[section.key]?.enabled}
onChange={handleSectionChange(section.key)}
size='large'
/>
</div>
{/* 功能模块网格 */}
<div className='p-5'>
<Row gutter={[12, 12]}>
{section.modules
.filter((module) =>
isAllowedByAdmin(section.key, module.key),
)
.map((module) => (
<Col key={module.key} xs={24} sm={12} md={8} lg={6}>
<div
className={`p-4 rounded-xl border transition-all ${
sidebarModulesUser[section.key]?.enabled
? 'border-gray-200 dark:border-gray-700 hover:border-blue-300 dark:hover:border-blue-700'
: 'border-gray-100 dark:border-gray-800 opacity-50'
}`}
>
<div className='flex justify-between items-center'>
<div>
<div className='font-medium text-sm text-gray-900 dark:text-white'>
{module.title}
</div>
<div className='text-xs text-gray-500 dark:text-gray-400 mt-0.5'>
{module.description}
</div>
</div>
<Switch
checked={
sidebarModulesUser[section.key]?.[module.key]
}
onChange={handleModuleChange(
section.key,
module.key,
)}
size='small'
disabled={
!sidebarModulesUser[section.key]?.enabled
}
/>
</div>
</div>
</Col>
))}
</Row>
</div>
</div>
);
})}
</div>
</div>
);
};
export default SidebarSection;