import React from 'react'; import { Save, Sparkles, Settings as SettingsIcon, Eye, EyeOff, RefreshCw, Database, ChevronDown, Check, LockKeyhole, UserRound, ShieldCheck } from 'lucide-react'; import { DEFAULT_AI_API_URL, LOG_LEVELS } from '../app/features/settings/constants'; import { useSettings } from '../app/features/settings/hooks'; // Settings 展示系统配置、AI 模型和登录凭据编辑页面。 const Settings: React.FC = () => { // featureState 是 Settings Hook 提供的状态与动作集合。 const { settings, loading, loadError, saving, saveError, aiModels, modelsLoading, modelError, modelDropdownOpen, showApiKey, showCaptchaSecret, showCurrentPassword, showNewPassword, credentialsSaving, credentialsMessage, credentials, modelPickerRef, loadSettings, loadAIModels, handleSave, handleCredentialsSave, setSettings, setModelDropdownOpen, setShowApiKey, setShowCaptchaSecret, setShowCurrentPassword, setShowNewPassword, setCredentials, } = useSettings(); if (!settings) { return (
{loadError || (loading ? '加载配置中...' : '暂无配置')} {!loading && loadError && (
)}
); } // currentModel 是当前配置中的模型名称。 const currentModel = settings.ai_model || ''; // visibleAIModels 是模型下拉框当前展示的候选列表。 const visibleAIModels = aiModels; return (
{/* Header */}

系统设置

配置全局自动化规则与系统参数

{saveError && (
{saveError}
)}
{/* Left Column */}
{/* Basic Settings */}

基础设置

等级越低输出越详细,Debug 适合排查问题

JSON 适合接入集中式日志系统,保存后需重启服务生效

setSettings({ ...settings, renewal_log_retention_days: parseInt(e.target.value) || 0 })} className="w-full ios-input px-4 py-3 rounded-xl" min="0" max="365" />

0 表示不自动清理续期日志

{/* AI Configuration */}

AI 智能回复配置

setSettings({...settings, ai_api_url: e.target.value})} className="w-full ios-input px-4 py-3 rounded-xl text-sm" placeholder="https://api.openai.com/v1" />

无需补全 /chat/completions

setSettings({...settings, ai_api_key: e.target.value})} className="w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm" placeholder="sk-..." />
aiModels.length > 0 && setModelDropdownOpen(true)} onChange={/* 当前回调处理用户交互或异步状态变化。 */ e => { setSettings({...settings, ai_model: e.target.value}); if (aiModels.length > 0) setModelDropdownOpen(true); }} onKeyDown={/* 当前回调处理用户交互或异步状态变化。 */ e => { if (e.key === 'Escape') setModelDropdownOpen(false); if (e.key === 'ArrowDown' && aiModels.length > 0) setModelDropdownOpen(true); }} className="w-full ios-input px-4 py-3 pr-10 rounded-xl" placeholder="从接口读取或手动输入模型名" /> {modelDropdownOpen && (
{visibleAIModels.length > 0 ? ( visibleAIModels.map(/* 当前回调处理集合中的单个元素。 */ model => ( )) ) : (
没有匹配的模型
)}
)}
{modelError ? (

{modelError}

) : (

{aiModels.length > 0 ? `已从当前 API 地址读取到 ${aiModels.length} 个模型` : '模型列表从当前 API 地址读取,也可以手动输入模型名'}

)}
常见 AI 服务:
  • 阿里云通义千问: https://dashscope.aliyuncs.com/compatible-mode/v1
  • OpenAI: https://api.openai.com/v1
{/* Right Column */}

远程过滑块配置

setSettings({...settings, 'captcha.remote_service_url': event.target.value})} className="w-full ios-input px-4 py-3 rounded-xl text-sm" placeholder="https://example.com/internal/captcha/solve" />
setSettings({...settings, 'captcha.remote_secret_key': event.target.value})} className="w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm" autoComplete="off" />

配置地址和秘钥后优先调用远程服务;只有网络不可用或超时才回退本机引擎,远程明确返回失败时不会重复触发本机验证。

登录凭据

setCredentials({...credentials, new_username: event.target.value})} className="w-full ios-input pl-11 pr-4 py-3 rounded-xl text-sm" autoComplete="username" />
setCredentials({...credentials, current_password: event.target.value})} className="w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm" placeholder="用于确认当前身份" autoComplete="current-password" />
setCredentials({...credentials, new_password: event.target.value})} className="w-full ios-input px-4 py-3 pr-11 rounded-xl text-sm" placeholder="不修改则留空" autoComplete="new-password" />
setCredentials({...credentials, confirm_password: event.target.value})} className="w-full ios-input px-4 py-3 rounded-xl text-sm" placeholder="再次输入新密码" autoComplete="new-password" />
{credentialsMessage && (
{credentialsMessage.text}
)}
{/* SMTP 配置已移至「通知设置」页面 */}
{/* Save Button */}
); }; export default Settings;