import { useState } from 'react' interface Props { onInstall: () => void } export default function InstallPage({ onInstall }: Props) { const [step, setStep] = useState(1) const [loading, setLoading] = useState(false) const [error, setError] = useState('') const [config, setConfig] = useState({ database: { type: 'sqlite', host: 'localhost', port: 3306, user: 'root', password: '', database: 'anticaptcha', sqlite: { path: './data/app.db' } }, redis: { enabled: false, host: 'localhost', port: 6379, password: '', db: 0 }, admin: { username: 'admin', password: '' } }) const handleSubmit = async () => { setLoading(true) setError('') try { const res = await fetch('/api/install', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(config) }) const data = await res.json() if (!res.ok) { setError(data.error || '安装失败') return } onInstall() window.location.href = '/' } catch { setError('网络错误') } finally { setLoading(false) } } return (

AntiCaptcha 安装向导

步骤 {step} / 3

{step === 1 && ( <>

数据库配置

{config.database.type === 'sqlite' ? (
setConfig({ ...config, database: { ...config.database, sqlite: { path: e.target.value } } })} />
) : ( <>
setConfig({ ...config, database: { ...config.database, host: e.target.value } })} />
setConfig({ ...config, database: { ...config.database, port: Number(e.target.value) } })} />
setConfig({ ...config, database: { ...config.database, user: e.target.value } })} />
setConfig({ ...config, database: { ...config.database, password: e.target.value } })} />
setConfig({ ...config, database: { ...config.database, database: e.target.value } })} />
)} )} {step === 2 && ( <>

Redis 配置(可选)

{config.redis.enabled && ( <>
setConfig({ ...config, redis: { ...config.redis, host: e.target.value } })} />
setConfig({ ...config, redis: { ...config.redis, port: Number(e.target.value) } })} />
setConfig({ ...config, redis: { ...config.redis, password: e.target.value } })} />
setConfig({ ...config, redis: { ...config.redis, db: Number(e.target.value) } })} />
)}
)} {step === 3 && ( <>

管理员账号

setConfig({ ...config, admin: { ...config.admin, username: e.target.value } })} />
setConfig({ ...config, admin: { ...config.admin, password: e.target.value } })} placeholder="请输入管理员密码" />
{error &&
{error}
}
)}
) }