"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Alert, Button, Card, CloseButton, Input, Label, TextField } from "@heroui/react"; import { Thunderbolt } from "@gravity-ui/icons"; const CSMS_URL = process.env.NEXT_PUBLIC_CSMS_URL ?? "http://localhost:3001"; export default function SetupPage() { const router = useRouter(); const [form, setForm] = useState({ name: "", email: "", username: "", password: "", confirmPassword: "", }); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const handleChange = (field: keyof typeof form) => (e: React.ChangeEvent) => { setForm((prev) => ({ ...prev, [field]: e.target.value })); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); if (form.password !== form.confirmPassword) { setError("两次输入的密码不一致"); return; } if (form.password.length < 8) { setError("密码长度至少 8 位"); return; } setLoading(true); try { const res = await fetch(`${CSMS_URL}/api/setup`, { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify({ name: form.name, email: form.email, username: form.username, password: form.password, }), }); if (!res.ok) { const data = await res.json().catch(() => ({})); setError((data as { error?: string }).error ?? "初始化失败,请重试"); return; } // 初始化成功,跳转登录页 router.push("/login?setup=1"); } catch { setError("网络错误,请稍后重试"); } finally { setLoading(false); } }; return (
{/* Brand */}

Helios EVCS

首次启动 · 创建根管理员账号

{error && ( 初始化失败 {error} setError("")} /> )}

此页面仅在首次启动时可访问

); }