feat: add file copying functionality to dataset directory and update base path configuration

This commit is contained in:
Dallas98
2025-11-14 18:05:40 +08:00
committed by GitHub
parent d9e163c163
commit 5638bdcf1c
9 changed files with 248 additions and 185 deletions

View File

@@ -53,7 +53,7 @@ interface ProviderI {
isEnabled: boolean;
}
export default function EnvironmentAccess() {
export default function ModelAccess() {
const [form] = Form.useForm();
const [showModelDialog, setShowModelDialog] = useState(false);
const [isEditMode, setIsEditMode] = useState(false);

View File

@@ -27,16 +27,16 @@ export default function SettingsPage() {
icon: <Component className="w-4 h-4" />,
label: "模型接入",
},
// {
// key: "system-config",
// icon: <SettingOutlined />,
// label: "参数配置",
// },
// {
// key: "webhook-config",
// icon: <ApiOutlined />,
// label: "Webhook",
// },
{
key: "system-config",
icon: <SettingOutlined />,
label: "参数配置",
},
{
key: "webhook-config",
icon: <ApiOutlined />,
label: "Webhook",
},
]}
selectedKeys={[activeTab]}
onClick={({ key }) => {

View File

@@ -1,107 +1,205 @@
import { Divider, Input, Select, Switch, Button, Form, App, Table } from "antd";
import { PlusOutlined } from "@ant-design/icons";
import { useState } from "react";
import { Divider, Input, Select, Switch, Button, Table, Spin } from "antd";
import { useEffect, useState } from "react";
import { getSysParamList, updateSysParamValue } from './settings.apis';
interface SystemParam {
id: string;
paramKey: string;
paramValue: string;
description: string;
isEnabled: boolean;
paramType?: string;
optionList?: string;
isBuiltIn?: boolean;
canModify?: boolean;
}
export default function SystemConfig() {
const { message } = App.useApp();
// System Settings State
const [systemConfig, setSystemConfig] = useState({
siteName: "DataMate",
maxFileSize: "100",
autoBackup: true,
logLevel: "info",
sessionTimeout: "30",
enableNotifications: true,
});
const configData = [
{
key: "1",
parameter: "站点名称",
value: systemConfig.siteName,
description: "系统的显示名称",
},
{
key: "2",
parameter: "最大文件大小 (MB)",
value: systemConfig.maxFileSize,
description: "允许上传的最大文件大小",
},
{
key: "3",
parameter: "自动备份",
value: systemConfig.autoBackup ? "启用" : "禁用",
description: "定期自动备份系统数据",
},
{
key: "4",
parameter: "日志级别",
value: systemConfig.logLevel,
description: "系统日志的详细程度",
},
{
key: "5",
parameter: "会话超时 (分钟)",
value: systemConfig.sessionTimeout,
description: "用户会话的超时时间",
},
];
const [sysParams, setSysParams] = useState<SystemParam[]>([]);
const [loading, setLoading] = useState(true);
const [editingParams, setEditingParams] = useState<Record<string, string>>({});
const [tempEditingValues, setTempEditingValues] = useState<Record<string, string>>({});
const logLevelOptions = [
{ value: "debug", label: "Debug" },
{ value: "info", label: "Info" },
{ value: "warn", label: "Warning" },
{ value: "error", label: "Error" },
];
const handleSaveSystemSettings = () => {
// Save system settings logic
console.log("Saving system settings:", systemConfig);
message.success("系统设置已保存");
// 获取系统参数列表
const fetchSysParams = async () => {
try {
setLoading(true);
const response = await getSysParamList();
setSysParams(response.data || []);
// 初始化编辑状态
const initialEditState: Record<string, string> = {};
response.data?.forEach((param: SystemParam) => {
initialEditState[param.id] = param.paramValue;
});
setEditingParams(initialEditState);
} catch (error) {
console.error('获取系统参数失败:', error);
} finally {
setLoading(false);
}
};
// 组件加载时获取数据
useEffect(() => {
fetchSysParams();
}, []);
// 处理参数值更新 - 立即更新(用于开关和下拉框)
const handleImmediateUpdate = async (param: SystemParam, newValue: string | boolean) => {
try {
const stringValue = typeof newValue === 'boolean' ? newValue.toString() : newValue;
// 更新本地临时状态
setTempEditingValues(prev => ({ ...prev, [param.id]: stringValue }));
setEditingParams(prev => ({ ...prev, [param.id]: stringValue }));
// 调用后端更新接口 - 修改为适应新的接口格式
await updateSysParamValue({
id: param.id,
paramValue: stringValue
});
// 更新本地状态
setSysParams(prev => prev.map(p =>
p.id === param.id ? { ...p, paramValue: stringValue } : p
));
} catch (error) {
console.error('更新参数失败:', error);
// 恢复原始值
setEditingParams(prev => ({ ...prev, [param.id]: param.paramValue }));
setTempEditingValues(prev => ({ ...prev, [param.id]: param.paramValue }));
}
};
// 处理输入框值变化 - 仅更新临时状态
const handleInputChange = (param: SystemParam, newValue: string) => {
setTempEditingValues(prev => ({ ...prev, [param.id]: newValue }));
};
// 处理输入框失焦 - 发起后端请求
const handleInputBlur = async (param: SystemParam) => {
const newValue = tempEditingValues[param.id];
if (newValue !== undefined && newValue !== param.paramValue) {
try {
// 调用后端更新接口
await updateSysParamValue({
id: param.id,
paramValue: newValue
});
// 更新本地状态
setSysParams(prev => prev.map(p =>
p.id === param.id ? { ...p, paramValue: newValue } : p
));
setEditingParams(prev => ({ ...prev, [param.id]: newValue }));
} catch (error) {
console.error('更新参数失败:', error);
// 恢复原始值
setTempEditingValues(prev => ({ ...prev, [param.id]: param.paramValue }));
setEditingParams(prev => ({ ...prev, [param.id]: param.paramValue }));
}
}
};
// 获取选项列表 - 解析逗号分隔的字符串
const getOptionList = (optionListStr?: string) => {
if (!optionListStr) return [];
try {
// 按逗号分割字符串并去除首尾空格
return optionListStr.split(',').map(option => ({
value: option.trim(),
label: option.trim()
}));
} catch (error) {
console.error('解析选项列表失败:', error);
return [];
}
};
// 表格列定义
const columns = [
{
title: "参数",
dataIndex: "parameter",
key: "parameter",
title: "参数",
dataIndex: "paramKey",
key: "paramKey",
width: 180,
},
{
title: "值",
dataIndex: "value",
key: "value",
title: "参数值",
dataIndex: "paramValue",
key: "paramValue",
width: 200,
render: (value: string, record: SystemParam) => {
// 使用临时编辑值或当前值
const displayValue = tempEditingValues[record.id] ?? editingParams[record.id] ?? value;
// 对于boolean类型,使用开关按钮
if (record.paramType === 'boolean') {
const isChecked = displayValue.toLowerCase() === 'true';
return (
<Switch
checked={isChecked}
onChange={(checked) => handleImmediateUpdate(record, checked)}
disabled={!record.canModify}
/>
);
}
// 对于有选项列表的参数,强制使用下拉框
if (record.optionList && record.optionList.trim()) {
const options = getOptionList(record.optionList);
return (
<Select
value={displayValue}
onChange={(newValue) => handleImmediateUpdate(record, newValue)}
options={options}
disabled={!record.canModify}
style={{ width: '150px' }}
placeholder="请选择值"
/>
);
}
// 对于数字类型
if (record.paramType === 'integer' || record.paramType === 'number') {
return (
<Input
type="number"
value={displayValue}
onChange={(e) => handleInputChange(record, e.target.value)}
onBlur={() => handleInputBlur(record)}
disabled={!record.canModify}
style={{ width: '150px' }}
/>
);
}
// 默认为文本输入
return (
<Input
value={displayValue}
onChange={(e) => handleInputChange(record, e.target.value)}
onBlur={() => handleInputBlur(record)}
disabled={!record.canModify}
style={{ width: '150px' }}
/>
);
},
},
{
title: "描述",
dataIndex: "description",
key: "description",
width: 300,
},
{
title: "是否启用",
dataIndex: "enabled",
key: "enabled",
render: (_: any, record: any) => (
<Switch
checked={
record.key === "3"
? systemConfig.autoBackup
: record.key === "5"
? systemConfig.enableNotifications
: false
}
onChange={(checked) => {
if (record.key === "3") {
setSystemConfig((prevConfig) => ({
...prevConfig,
autoBackup: checked,
}));
} else if (record.key === "5") {
setSystemConfig((prevConfig) => ({
...prevConfig,
enableNotifications: checked,
}));
}
}}
/>
dataIndex: "isEnabled",
key: "isEnabled",
width: 100,
render: (isEnabled: boolean) => (
<Switch checked={isEnabled} disabled={true} />
),
}
];
@@ -109,82 +207,24 @@ export default function SystemConfig() {
return (
<div className="h-full flex flex-col">
<div className="flex items-top justify-between">
<h2 className="text-lg font-medium mb-4"></h2>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => {
setIsEditMode(false);
form.resetFields();
setNewModel({
name: "",
provider: "",
model: "",
apiKey: "",
endpoint: "",
});
setShowModelDialog(true);
}}
>
</Button>
<h2 className="text-lg font-medium mb-4"></h2>
<Button onClick={fetchSysParams}></Button>
</div>
<div className="flex-1 border-card overflow-auto p-6">
<Table columns={columns} data={configData} />
<Form
onValuesChange={(changedValues) => {
setSystemConfig((prevConfig) => ({
...prevConfig,
...changedValues,
}));
}}
layout="vertical"
>
<div className="grid grid-cols-2 gap-6 mt-6">
<Form.Item name="siteName" label="站点名称">
<Input />
</Form.Item>
<Form.Item name="maxFileSize" label="最大文件大小 (MB)">
<Input type="number" />
</Form.Item>
<Form.Item name="logLevel" label="日志级别">
<Select options={logLevelOptions}></Select>
</Form.Item>
<Form.Item name="sessionTimeout" label="会话超时 (分钟)">
<Input type="number" />
</Form.Item>
{loading ? (
<div className="flex justify-center items-center h-64">
<Spin size="large" />
</div>
<Divider />
<div className="space-y-4">
<h4 className="font-medium"></h4>
<div className="space-y-3">
<div className="flex items-center justify-between">
<div>
<span></span>
<p className="text-sm text-gray-500"></p>
</div>
<Form.Item name="autoBackup" valuePropName="checked">
<Switch />
</Form.Item>
</div>
<div className="flex items-center justify-between">
<div>
<span></span>
<p className="text-sm text-gray-500"></p>
</div>
<Form.Item name="enableNotifications" valuePropName="checked">
<Switch />
</Form.Item>
</div>
</div>
</div>
<div className="flex justify-end mt-6">
<Button type="primary" onClick={handleSaveSystemSettings}>
</Button>
</div>
</Form>
) : (
<Table
columns={columns}
dataSource={sysParams}
pagination={false}
size="middle"
rowKey="id"
/>
)}
</div>
</div>
);
}
}

View File

@@ -28,3 +28,13 @@ export function deleteModelByIdUsingDelete(id: string | number) {
return del(`/api/models/${id}`);
}
// 获取系统参数列表
export function getSysParamList() {
return get('/api/sys-param/list');
}
// 更新系统参数值
export const updateSysParamValue = async (params: { id: string; paramValue: string }) => {
return put(`/api/sys-param/${params.id}`, params);
};