import React, { useState } from 'react'; import { Card, Row, Col, Form, Input, Button, Select, Switch, InputNumber, Alert, Divider, Tabs } from 'antd'; import { DatabaseOutlined, KeyOutlined, SettingOutlined, SaveOutlined, ToolOutlined } from '@ant-design/icons'; import './AdminConfig.css'; const { Option } = Select; const { Item } = Form; const { TabPane } = Tabs; const AdminConfig = () => { const [form] = Form.useForm(); // 数据库配置 const databaseConfig = { // MongoDB配置 mongoDB: { host: 'localhost', port: 27017, database: 'alpha-futures', username: '', password: '', authSource: 'admin', ssl: false, enabled: true }, // PostgreSQL配置 postgreSQL: { host: 'localhost', port: 5432, database: 'alpha-futures', username: 'postgres', password: 'password', ssl: false, enabled: true }, // Redis配置 redis: { host: 'localhost', port: 6379, password: '', db: 0, enabled: true }, // InfluxDB配置 influxDB: { host: 'localhost', port: 8086, database: 'alpha-futures', username: '', password: '', ssl: false, enabled: true } }; // 服务器配置 const serverConfig = { port: 3005, host: '0.0.0.0', environment: 'development', debug: true, timeout: 30000, maxBodySize: '10mb' }; // 安全配置 const securityConfig = { jwtSecret: 'your-secret-key', jwtExpiresIn: '7d', rateLimit: { windowMs: 60000, max: 120 }, cors: { origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowedHeaders: ['Content-Type', 'Authorization'] } }; const [config, setConfig] = useState({ database: databaseConfig, server: serverConfig, security: securityConfig }); // 处理配置变更 const handleConfigChange = (section, key, value) => { setConfig(prev => ({ ...prev, [section]: { ...prev[section], [key]: value } })); }; // 处理数据库配置变更 const handleDatabaseConfigChange = (dbType, key, value) => { setConfig(prev => ({ ...prev, database: { ...prev.database, [dbType]: { ...prev.database[dbType], [key]: value } } })); }; // 处理表单提交 const handleSubmit = (values) => { console.log('配置保存:', values); // 模拟保存操作 Alert.success('配置已保存'); }; // 测试数据库连接 const testDatabaseConnection = (dbType) => { console.log(`测试${dbType}连接`); // 模拟测试操作 setTimeout(() => { Alert.success(`${dbType}连接测试成功`); }, 1000); }; return (

管理配置

{/* 数据库配置 */} 数据库配置} key="database"> {/* MongoDB配置 */} handleDatabaseConfigChange('mongoDB', 'host', e.target.value)} /> handleDatabaseConfigChange('mongoDB', 'port', value)} /> handleDatabaseConfigChange('mongoDB', 'database', e.target.value)} /> handleDatabaseConfigChange('mongoDB', 'authSource', e.target.value)} /> handleDatabaseConfigChange('mongoDB', 'username', e.target.value)} /> handleDatabaseConfigChange('mongoDB', 'password', e.target.value)} /> handleDatabaseConfigChange('mongoDB', 'ssl', checked)} /> handleDatabaseConfigChange('mongoDB', 'enabled', checked)} />
{/* PostgreSQL配置 */} handleDatabaseConfigChange('postgreSQL', 'host', e.target.value)} /> handleDatabaseConfigChange('postgreSQL', 'port', value)} /> handleDatabaseConfigChange('postgreSQL', 'database', e.target.value)} /> handleDatabaseConfigChange('postgreSQL', 'username', e.target.value)} /> handleDatabaseConfigChange('postgreSQL', 'password', e.target.value)} /> handleDatabaseConfigChange('postgreSQL', 'ssl', checked)} /> handleDatabaseConfigChange('postgreSQL', 'enabled', checked)} />
{/* Redis配置 */} handleDatabaseConfigChange('redis', 'host', e.target.value)} /> handleDatabaseConfigChange('redis', 'port', value)} /> handleDatabaseConfigChange('redis', 'password', e.target.value)} /> handleDatabaseConfigChange('redis', 'db', value)} /> handleDatabaseConfigChange('redis', 'enabled', checked)} />
{/* InfluxDB配置 */} handleDatabaseConfigChange('influxDB', 'host', e.target.value)} /> handleDatabaseConfigChange('influxDB', 'port', value)} /> handleDatabaseConfigChange('influxDB', 'database', e.target.value)} /> handleDatabaseConfigChange('influxDB', 'username', e.target.value)} /> handleDatabaseConfigChange('influxDB', 'password', e.target.value)} /> handleDatabaseConfigChange('influxDB', 'ssl', checked)} /> handleDatabaseConfigChange('influxDB', 'enabled', checked)} />
{/* 服务器配置 */} 服务器配置} key="server"> handleConfigChange('server', 'port', value)} /> handleConfigChange('server', 'host', e.target.value)} /> handleConfigChange('server', 'debug', checked)} /> handleConfigChange('server', 'timeout', value)} /> handleConfigChange('server', 'maxBodySize', e.target.value)} /> {/* 安全配置 */} 安全配置} key="security"> {/* JWT配置 */} handleConfigChange('security', 'jwtSecret', e.target.value)} /> handleConfigChange('security', 'jwtExpiresIn', e.target.value)} /> {/* 速率限制配置 */} handleConfigChange('security', 'rateLimit', { ...config.security.rateLimit, windowMs: value })} /> handleConfigChange('security', 'rateLimit', { ...config.security.rateLimit, max: value })} /> {/* CORS配置 */} handleConfigChange('security', 'cors', { ...config.security.cors, origin: e.target.value })} /> handleConfigChange('security', 'cors', { ...config.security.cors, methods: e.target.value.split(', ').map(m => m.trim()) })} /> handleConfigChange('security', 'cors', { ...config.security.cors, allowedHeaders: e.target.value.split(', ').map(h => h.trim()) })} />
); }; export default AdminConfig;