feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面
This commit is contained in:
@@ -18,11 +18,20 @@ 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 { Button, Form, Toast } from '@/components/ui';
|
||||
import { Check, Copy } from 'lucide-react';
|
||||
import { FormQuotaInput } from '../../../common/ui/QuotaInput';
|
||||
import CodeViewer from '../../../playground/CodeViewer';
|
||||
import { copy } from '../../../../helpers';
|
||||
import SectionHeader from '../components/SectionHeader';
|
||||
|
||||
// Webhook 请求结构示例(只读展示,与原 CodeViewer 展示的内容相同)
|
||||
const WEBHOOK_EXAMPLE = {
|
||||
type: 'quota_exceed',
|
||||
title: '额度预警通知',
|
||||
content: '您的额度即将用尽,当前剩余额度为 {{value}}',
|
||||
values: ['¥0.99'],
|
||||
timestamp: 1739950503,
|
||||
};
|
||||
|
||||
const NotificationSection = ({
|
||||
t,
|
||||
@@ -58,212 +67,164 @@ const NotificationSection = ({
|
||||
}
|
||||
};
|
||||
|
||||
// 复制示例:沿用原 CodeViewer 的复制方式与提示
|
||||
const handleCopyExample = async () => {
|
||||
try {
|
||||
const success = await copy(JSON.stringify(WEBHOOK_EXAMPLE, null, 2));
|
||||
Toast.success(t('已复制到剪贴板'));
|
||||
if (!success) {
|
||||
throw new Error('Copy operation failed');
|
||||
}
|
||||
} catch (err) {
|
||||
Toast.error(t('复制失败'));
|
||||
console.error('Copy failed:', err);
|
||||
}
|
||||
};
|
||||
|
||||
// 通知方式选项(仅保留邮件通知和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',
|
||||
desc: t('发送到账户邮箱或指定邮箱'),
|
||||
},
|
||||
{
|
||||
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 className='ui-notify-section'>
|
||||
<SectionHeader
|
||||
title={t('通知设置')}
|
||||
description={t('设置额度预警和系统提醒接收方式')}
|
||||
extra={
|
||||
<Button theme='solid' onClick={handleSubmit}>
|
||||
{t('保存设置')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<Form
|
||||
className='ui-notify-form'
|
||||
requiredMark={false}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
initValues={notificationSettings}
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
{/* 通知方式选择 */}
|
||||
<div className='ui-notify-methods-field'>
|
||||
<div className='ui-notify-label'>{t('通知方式')}</div>
|
||||
<div className='ui-notify-methods'>
|
||||
{notifyOptions.map((option) => {
|
||||
const isSelected =
|
||||
notificationSettings.warningType === option.value;
|
||||
return (
|
||||
<button
|
||||
key={option.value}
|
||||
type='button'
|
||||
aria-pressed={isSelected}
|
||||
onClick={() => handleFormChange('warningType', option.value)}
|
||||
className={`ui-notify-method ${isSelected ? 'selected' : ''}`}
|
||||
>
|
||||
<span className='ui-notify-method-text'>
|
||||
<strong>{option.label}</strong>
|
||||
<span>{option.desc}</span>
|
||||
</span>
|
||||
{isSelected && (
|
||||
<Check size={16} className='ui-notify-method-check' />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</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();
|
||||
},
|
||||
{/* 预警阈值 */}
|
||||
<FormQuotaInput
|
||||
field='warningThreshold'
|
||||
label={t('额度预警阈值')}
|
||||
onChange={(val) => handleFormChange('warningThreshold', val)}
|
||||
extraText={t('当剩余额度低于此数值时,通过所选方式发送通知')}
|
||||
style={{ width: 260, maxWidth: '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
|
||||
/>
|
||||
{/* 邮件通知设置 */}
|
||||
{notificationSettings.warningType === 'email' && (
|
||||
<div className='ui-notify-panel'>
|
||||
<Form.Input
|
||||
field='notificationEmail'
|
||||
label={t('通知邮箱')}
|
||||
placeholder={t('留空则使用账号绑定的邮箱')}
|
||||
onChange={(val) => handleFormChange('notificationEmail', val)}
|
||||
extraText={t('不填写则使用账号绑定的邮箱')}
|
||||
showClear
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Webhook通知设置 */}
|
||||
{notificationSettings.warningType === 'webhook' && (
|
||||
<div className='ui-notify-panel'>
|
||||
<Form.Input
|
||||
field='webhookUrl'
|
||||
label={t('Webhook 地址')}
|
||||
placeholder='https://example.com/webhook'
|
||||
onChange={(val) => handleFormChange('webhookUrl', val)}
|
||||
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('接口凭证')}
|
||||
mode='password'
|
||||
placeholder={t('请输入密钥')}
|
||||
onChange={(val) => handleFormChange('webhookSecret', val)}
|
||||
extraText={t('密钥以 Bearer 方式添加到请求头中')}
|
||||
/>
|
||||
|
||||
<div className='ui-notify-code-head'>
|
||||
<span>{t('Webhook 请求结构说明')}</span>
|
||||
<button
|
||||
type='button'
|
||||
className='ui-notify-copy'
|
||||
onClick={handleCopyExample}
|
||||
>
|
||||
{t('复制')}
|
||||
<Copy size={14} />
|
||||
</button>
|
||||
</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>
|
||||
<pre className='ui-notify-code'>
|
||||
{JSON.stringify(WEBHOOK_EXAMPLE, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user