1
0

refactor: 迁移 UI 组件库从 Ant Design 至 TDesign

- 替换 antd 为 tdesign-react 作为主要 UI 组件库
- 引入 Recharts 替代 @ant-design/charts 实现图表功能
- 移除主题系统相关代码(ThemeContext、themes 目录)
- 更新所有组件以适配 TDesign 组件 API
- 更新测试用例以匹配新的组件实现
- 新增 TDesign 和 Recharts 集成规范文档
This commit is contained in:
2026-04-17 18:22:13 +08:00
parent 6eeb38c15e
commit 2b1c5e96c3
55 changed files with 1622 additions and 2541 deletions

View File

@@ -1,6 +1,7 @@
import { useEffect } from 'react';
import { Modal, Form, Input, Switch } from 'antd';
import { Dialog, Form, Input, Switch } from 'tdesign-react';
import type { Provider } from '@/types';
import type { SubmitContext } from 'tdesign-react/es/form/type';
interface ProviderFormValues {
id: string;
@@ -25,12 +26,14 @@ export function ProviderForm({
onCancel,
loading,
}: ProviderFormProps) {
const [form] = Form.useForm<ProviderFormValues>();
const [form] = Form.useForm();
const isEdit = !!provider;
// 当弹窗打开或provider变化时设置表单值
useEffect(() => {
if (open) {
if (open && form) {
if (provider) {
// 编辑模式:设置现有值
form.setFieldsValue({
id: provider.id,
name: provider.name,
@@ -39,54 +42,63 @@ export function ProviderForm({
enabled: provider.enabled,
});
} else {
form.resetFields();
// 新增模式:重置表单
form.reset();
form.setFieldsValue({ enabled: true });
}
}
}, [open, provider, form]);
}, [open, provider]); // 移除form依赖避免循环
const handleSubmit = (context: SubmitContext) => {
if (context.validateResult === true && form) {
const values = form.getFieldsValue(true) as ProviderFormValues;
onSave(values);
}
};
return (
<Modal
title={isEdit ? '编辑供应商' : '添加供应商'}
open={open}
onOk={() => form.submit()}
onCancel={onCancel}
<Dialog
header={isEdit ? '编辑供应商' : '添加供应商'}
visible={open}
onConfirm={() => { form?.submit(); return false; }}
onClose={onCancel}
confirmLoading={loading}
okText="保存"
cancelText="取消"
destroyOnHidden
confirmBtn="保存"
cancelBtn="取消"
destroyOnClose
>
<Form form={form} layout="vertical" onFinish={onSave} initialValues={{ enabled: true }}>
<Form.Item label="ID" name="id" rules={[{ required: true, message: '请输入供应商 ID' }]}>
<Form form={form} layout="vertical" onSubmit={handleSubmit}>
<Form.FormItem label="ID" name="id" rules={[{ required: true, message: '请输入供应商 ID' }]}>
<Input disabled={isEdit} placeholder="例如: openai" />
</Form.Item>
</Form.FormItem>
<Form.Item label="名称" name="name" rules={[{ required: true, message: '请输入名称' }]}>
<Form.FormItem label="名称" name="name" rules={[{ required: true, message: '请输入名称' }]}>
<Input placeholder="例如: OpenAI" />
</Form.Item>
</Form.FormItem>
<Form.Item
<Form.FormItem
label={isEdit ? 'API Key留空则不修改' : 'API Key'}
name="apiKey"
rules={isEdit ? [] : [{ required: true, message: '请输入 API Key' }]}
>
<Input.Password placeholder="sk-..." />
</Form.Item>
<Input type="password" placeholder="sk-..." autocomplete="current-password" />
</Form.FormItem>
<Form.Item
<Form.FormItem
label="Base URL"
name="baseUrl"
rules={[
{ required: true, message: '请输入 Base URL' },
{ type: 'url', message: '请输入有效的 URL' },
{ url: true, message: '请输入有效的 URL' },
]}
>
<Input placeholder="例如: https://api.openai.com/v1" />
</Form.Item>
</Form.FormItem>
<Form.Item label="启用" name="enabled" valuePropName="checked">
<Form.FormItem label="启用" name="enabled">
<Switch />
</Form.Item>
</Form.FormItem>
</Form>
</Modal>
</Dialog>
);
}