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 (
步骤 {step} / 3
{step === 1 && ( <>