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
@@ -18,7 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Modal, Button, Space } from '@douyinfe/semi-ui';
import { Modal, Button, Space } from '@/components/ui';
const CopyTokensModal = ({ visible, onCancel, selectedKeys, copyText, t }) => {
// Handle copy with name and key format
@@ -18,7 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Modal } from '@douyinfe/semi-ui';
import { Modal } from '@/components/ui';
const DeleteTokensModal = ({
visible,
@@ -0,0 +1,299 @@
/*
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, { useEffect, useMemo, useState } from 'react';
import { Button, Collapse, DatePicker, Divider, Drawer, Spin } from 'antd';
import dayjs from 'dayjs';
import { Form } from '@/components/ui';
import { FormQuotaInput } from '../../../common/ui/QuotaInput';
import {
getModelCategories,
renderGroupOption,
selectFilter,
} from '../../../../helpers';
// 过期时间快捷项:参数与原 setExpiredTime(month, day, hour, minute) 一致。
const EXPIRE_PRESETS = [
{ key: 'never', label: '永不过期', args: [0, 0, 0, 0] },
{ key: 'month', label: '一个月', args: [1, 0, 0, 0] },
{ key: 'week', label: '一周', args: [0, 7, 0, 0] },
{ key: 'day', label: '一天', args: [0, 1, 0, 0] },
];
/**
* 密钥管理页的创建/编辑抽屉视图(密钥管理页面.zip:创建密钥1/2、编辑密钥1/2、模型限制、过期时间)。
* 只负责呈现:表单字段名、校验规则、formApi、submit、过期时间状态与加载状态全部由 EditTokenModal 传入,
* 与弹窗形态共用同一份请求与载荷逻辑。
*/
const EditTokenDrawer = ({
open,
isEdit,
isMobile,
loading,
t,
groups,
models,
skillOptions,
neverExpire,
setNeverExpire,
expireDate,
setExpireDate,
setExpiredTime,
advancedOpen,
setAdvancedOpen,
initValues,
formApiRef,
onSubmit,
onCancel,
}) => {
// 仅用于高亮当前快捷项的视图状态;“永不过期”由 neverExpire 推导。
const [preset, setPreset] = useState('custom');
useEffect(() => {
if (open) setPreset('custom');
}, [open]);
const activePreset = neverExpire ? 'never' : preset;
// 模型限制下拉按厂商分组(设计图:DeepSeek / 智谱 等分组标题),选项值与原列表一致。
const modelOptions = useMemo(() => {
const categories = getModelCategories(t);
const grouped = new Map();
models.forEach(({ value }) => {
let label = t('其他');
for (const [key, category] of Object.entries(categories)) {
if (key !== 'all' && category.filter?.({ model_name: value })) {
label = category.label;
break;
}
}
if (!grouped.has(label)) grouped.set(label, []);
grouped.get(label).push({ label: value, value });
});
return [...grouped].map(([label, options]) => ({
label,
title: label,
options,
}));
}, [models, t]);
return (
<Drawer
open={open}
onClose={onCancel}
title={isEdit ? t('编辑令牌') : t('创建令牌')}
width={isMobile ? '100%' : 560}
maskClosable={false}
forceRender
rootClassName='km-edit-drawer'
footer={
<div className='km-drawer-footer'>
<Button onClick={onCancel}>{t('取消')}</Button>
<Button
type='primary'
loading={loading}
onClick={() => formApiRef.current?.submitForm()}
>
{isEdit ? t('保存') : t('创建令牌')}
</Button>
</div>
}
>
<Spin spinning={loading}>
<Form
key={isEdit ? 'edit' : 'new'}
initValues={initValues}
getFormApi={(api) => (formApiRef.current = api)}
onSubmit={onSubmit}
requiredMark={false}
>
{({ values }) => (
<>
<Form.Input
field='name'
label={t('名称')}
placeholder={t('请输入令牌名称')}
rules={[{ required: true, message: t('请输入名称') }]}
/>
{groups.length > 0 ? (
<Form.Select
field='group'
label={t('令牌分组')}
placeholder={t('选择分组,默认为用户分组')}
optionList={groups}
renderOptionItem={renderGroupOption}
showClear
style={{ width: '100%' }}
/>
) : (
<Form.Select
field='group'
label={t('令牌分组')}
placeholder={t('管理员未设置用户可选分组')}
disabled
style={{ width: '100%' }}
/>
)}
<Form.Slot label={t('过期时间')}>
<div className='km-expire-presets'>
{EXPIRE_PRESETS.map((item) => (
<Button
key={item.key}
color={activePreset === item.key ? 'primary' : 'default'}
variant='outlined'
autoInsertSpace={false}
aria-pressed={activePreset === item.key}
onClick={() => {
setPreset(item.key);
setExpiredTime(...item.args);
}}
>
{t(item.label)}
</Button>
))}
{/* 设计图:“自定义”选中时仅文字为主色,描边保持中性。 */}
<Button
className='km-preset-custom'
color={activePreset === 'custom' ? 'primary' : 'default'}
variant='outlined'
autoInsertSpace={false}
aria-pressed={activePreset === 'custom'}
onClick={() => {
setPreset('custom');
setNeverExpire(false);
}}
>
{t('自定义')}
</Button>
</div>
{!neverExpire && (
<DatePicker
className='km-expire-picker'
showTime
value={expireDate ? dayjs(expireDate) : null}
placeholder={t('请选择过期时间')}
onChange={(date) => {
setPreset('custom');
setExpireDate(date ? date.toDate() : null);
}}
disabledDate={(date) =>
date && date.isBefore(dayjs().startOf('day'))
}
/>
)}
</Form.Slot>
{!isEdit && (
<Form.InputNumber
field='tokenCount'
label={t('新建数量')}
min={1}
max={100}
rules={[{ required: true, message: t('请输入新建数量') }]}
extraText={t('批量创建时会在名称后自动添加随机后缀')}
style={{ width: '100%' }}
/>
)}
<Collapse
activeKey={advancedOpen ? ['advanced'] : []}
onChange={(keys) => setAdvancedOpen(keys.length > 0)}
items={[
{
key: 'advanced',
label: t('高级设置'),
forceRender: true,
children: (
<>
<h3 className='km-section-title'>{t('额度设置')}</h3>
<Form.Switch
field='unlimited_quota'
label={t('无限额度')}
checkedText={t('开启')}
uncheckedText={t('关闭')}
/>
{!values.unlimited_quota && (
<FormQuotaInput
field='remain_quota'
label={t('额度上限')}
rules={[
{ required: true, message: t('请输入额度') },
]}
style={{ width: '100%' }}
/>
)}
<Divider />
<h3 className='km-section-title'>{t('访问限制')}</h3>
<Form.Select
field='model_limits'
label={t('模型限制')}
placeholder={t('留空则支持所有模型')}
multiple
optionList={modelOptions}
filter={selectFilter}
autoClearSearchValue={false}
showClear
style={{ width: '100%' }}
/>
<Form.TextArea
field='allow_ips'
label={t('IP 白名单')}
placeholder={t('允许的 IP,一行一个;不填则不限制')}
rows={3}
showClear
/>
<Form.Switch
field='skill_injection_enabled'
label={t('技能注入')}
checkedText={t('开启')}
uncheckedText={t('关闭')}
extraText={t(
'开启后,用该密钥调用对话类接口时会自动前置技能约束。注入文本按正常 prompt token 计费,归属本密钥所属方。',
)}
/>
{/* 关闭注入时只隐藏视图,字段仍注册,载荷与原实现一致。 */}
<Form.Select
field='skill_ids'
label={t('绑定技能')}
placeholder={t('留空则跟随「我的技能」')}
multiple
optionList={skillOptions}
extraText={t(
'最多同时生效 5 个。注意:前置注入会改变 system 前缀,已使用 prompt 缓存的高频调用可能缓存失效、成本上升。',
)}
filter={selectFilter}
autoClearSearchValue={false}
showClear
className={
values.skill_injection_enabled
? undefined
: 'km-hidden-field'
}
style={{ width: '100%' }}
/>
</>
),
},
]}
/>
</>
)}
</Form>
</Spin>
</Drawer>
);
};
export default EditTokenDrawer;
@@ -35,8 +35,8 @@ import {
Form,
Collapsible,
DatePicker,
} from '@douyinfe/semi-ui';
import { IconChevronDown } from '@douyinfe/semi-icons';
} from '@/components/ui';
import { IconChevronDown } from '@/components/ui/icons';
import {
Key,
CreditCard,
@@ -51,6 +51,7 @@ import {
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { StatusContext } from '../../../../context/Status';
import EditTokenDrawer from './EditTokenDrawer';
const EditTokenModal = (props) => {
const { t: originalT } = useTranslation();
@@ -412,6 +413,33 @@ const EditTokenModal = (props) => {
</div>
);
// 密钥管理页使用抽屉形态(密钥管理页面.zip);状态、请求与载荷仍由本组件统一提供。
if (props.presentation === 'drawer') {
return (
<EditTokenDrawer
open={props.visiable}
isEdit={isEdit}
isMobile={isMobile}
loading={loading}
t={t}
groups={groups}
models={models}
skillOptions={skillOptions}
neverExpire={neverExpire}
setNeverExpire={setNeverExpire}
expireDate={expireDate}
setExpireDate={setExpireDate}
setExpiredTime={setExpiredTime}
advancedOpen={advancedOpen}
setAdvancedOpen={setAdvancedOpen}
initValues={getInitValues()}
formApiRef={formApiRef}
onSubmit={submit}
onCancel={handleCancel}
/>
);
}
return (
<Modal
title={null}