import React from 'react'; import { Tabs, Form, Input, Button, Select, Space, Divider, Typography } from 'antd'; import { ApiOutlined, RocketOutlined, PictureOutlined, SaveOutlined, SafetyCertificateOutlined, LockOutlined, GlobalOutlined, SettingOutlined, CloudServerOutlined, DatabaseOutlined, UploadOutlined} from '@ant-design/icons'; import ConfigFormItem from './ConfigFormItem'; import ConfigSection from './ConfigSection'; import VectorDbConfig from './VectorDbConfig'; const { TabPane } = Tabs; const { Option } = Select; const { Title, Paragraph } = Typography; interface ConfigStructure { [key: string]: { [key: string]: string; }; } interface ConfigTabsProps { configs: ConfigStructure; secretFields: Record; isMobile: boolean; activeKey: string; onTabChange: (key: string) => void; storageType: string; onStorageTypeChange: (type: string) => void; formsMap: Record; allDescriptions: Record>; onSaveSingleConfig: (formInstance: any, groupName: string, key: string) => Promise; onSaveAllForGroup: (formInstance: any, groupName: string, itemKeys: string[]) => Promise; onBaseSaveConfig: (group: string, key: string, value: string) => Promise; setConfigs: React.Dispatch>; storageOptions: Array<{ value: string; label: string; icon: React.ReactNode; }>; imageFormatOptions: Array<{ value: string; label: string; description: string; }>; imageQualityOptions: Array<{ value: string; label: string; description: string; }>; } const ConfigTabs: React.FC = ({ configs, secretFields, isMobile, activeKey, onTabChange, storageType, onStorageTypeChange, formsMap, allDescriptions, onSaveSingleConfig, onSaveAllForGroup, onBaseSaveConfig, setConfigs, storageOptions, imageFormatOptions, imageQualityOptions, }) => { const renderConfigFormItems = (formInstance: any, groupName: string, itemKeys: string[]) => { return itemKeys.map(key => { const isSecret = secretFields[groupName]?.includes(key); const description = allDescriptions[groupName]?.[key] || ''; const currentValue = configs[groupName]?.[key]; return ( ); }); }; const tabItems = [ { key: 'AI', label: 'AI 设置', icon: , children: ( } description="配置AI服务的基本参数,包括API端点、密钥和模型选择" isMobile={isMobile} >
{renderConfigFormItems(formsMap.AI, "AI", ['ApiEndpoint', 'ApiKey', 'Model', 'EmbeddingModel'])}
} description={allDescriptions.AI?.ImageAnalysisPrompt} isMobile={isMobile} > { const newConfigs = { ...configs }; if (!newConfigs.AI) newConfigs.AI = {}; newConfigs.AI.ImageAnalysisPrompt = e.target.value; setConfigs(newConfigs); }} style={{ marginBottom: 16 }} />
} description={allDescriptions.AI?.TagGenerationPrompt} isMobile={isMobile} > { const newConfigs = { ...configs }; if (!newConfigs.AI) newConfigs.AI = {}; newConfigs.AI.TagGenerationPrompt = e.target.value; setConfigs(newConfigs); }} style={{ marginBottom: 16 }} />
} description={allDescriptions.AI?.TagMatchingPrompt} isMobile={isMobile} > { const newConfigs = { ...configs }; if (!newConfigs.AI) newConfigs.AI = {}; newConfigs.AI.TagMatchingPrompt = e.target.value; setConfigs(newConfigs); }} style={{ marginBottom: 16 }} />
) }, { key: 'Authorization', label: '授权配置', icon: , children: ( } description="JSON Web Token (JWT) 的安全设置,用于管理用户身份验证和授权" isMobile={isMobile} >
{renderConfigFormItems(formsMap.Jwt, "Jwt", ['SecretKey', 'Issuer', 'Audience'])}
} description="GitHub OAuth 应用配置,用于实现第三方登录功能" isMobile={isMobile} >
{renderConfigFormItems(formsMap.Authentication, "Authentication", ["GitHubClientId", "GitHubClientSecret", "GitHubCallbackUrl"])}
} description="LinuxDo OAuth 应用配置,用于实现第三方登录功能" isMobile={isMobile} >
{renderConfigFormItems(formsMap.Authentication, "Authentication", ["LinuxDoClientId", "LinuxDoClientSecret", "LinuxDoCallbackUrl"])}
) }, { key: 'AppSettings', label: '应用设置', icon: , children: ( } description="应用程序的基本配置参数" isMobile={isMobile} >
{renderConfigFormItems(formsMap.AppSettings, "AppSettings", ['ServerUrl'])}
) }, { key: 'Storage', label: '存储设置', icon: , children: ( <> } description="配置系统默认使用的文件存储方式" isMobile={isMobile} >
登录用户默认存储
{allDescriptions.Storage?.DefaultStorage}
匿名用户默认存储
{allDescriptions.Storage?.AnonymousDefaultStorage}
} description="配置文件上传处理方式和图片转换参数" isMobile={isMobile} >
默认图片格式
{allDescriptions.Upload?.DefaultImageFormat}
默认压缩质量
{allDescriptions.Upload?.DefaultImageQuality}
} description="配置各种外部存储服务的连接参数" isMobile={isMobile} >
选择要配置的存储服务
选择后将显示对应存储服务的详细配置选项
{storageType === 'Local' && (
本地存储无需额外配置 文件将直接存储在服务器的本地文件系统中
)} {storageType === 'Telegram' && (
{renderConfigFormItems(formsMap.TelegramStorage, "Storage", ["TelegramStorageBotToken", "TelegramStorageChatId", "TelegramProxyAddress", "TelegramProxyPort", "TelegramProxyUsername", "TelegramProxyPassword"])} )} {storageType === 'S3' && (
{renderConfigFormItems(formsMap.S3Storage, "Storage", ["S3StorageAccessKey", "S3StorageSecretKey", "S3StorageBucketName", "S3StorageRegion", "S3StorageEndpoint", "S3StorageCdnUrl", "S3StorageUsePathStyleUrls"])} )} {storageType === 'Cos' && (
{renderConfigFormItems(formsMap.CosStorage, "Storage", ["CosStorageSecretId", "CosStorageSecretKey", "CosStorageToken", "CosStorageBucketName", "CosStorageRegion", "CosStorageCdnUrl"])} )} {storageType === 'WebDAV' && (
{renderConfigFormItems(formsMap.WebDAVStorage, "Storage", ["WebDAVServerUrl", "WebDAVUserName", "WebDAVPassword", "WebDAVBasePath", "WebDAVPublicUrl"])} )}
) }, { key: 'VectorDb', label: '向量数据', icon: , children: ( ) } ]; return ( ({ key: item.key, label: ( {item.icon} {item.label} ), children: item.children }))} /> ); }; export default ConfigTabs;