Files
aivideo/frontend-admin/src/app/admin/login/page.tsx

80 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { startTransition, useState } from "react";
import { useRouter } from "next/navigation";
import { api, ApiError } from "@/lib/api";
export default function AdminLoginPage() {
const router = useRouter();
const [form, setForm] = useState({
username: "admin",
password: "Admin@123456",
});
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setLoading(true);
setError("");
try {
await api.post("/api/v1/admin/auth/login", form);
startTransition(() => router.replace("/admin/dashboard"));
} catch (err) {
setError(err instanceof ApiError ? err.message : "登录失败");
} finally {
setLoading(false);
}
}
return (
<div className="login-grid">
<section style={{ padding: 48, display: "flex", flexDirection: "column", justifyContent: "space-between" }}>
<div>
<div className="brand-kicker">Ops Console</div>
<h1 style={{ fontSize: 64, lineHeight: 0.95, margin: "12px 0", fontFamily: "var(--font-display)" }}>
</h1>
<p className="muted" style={{ maxWidth: 580 }}>
MVP
</p>
</div>
</section>
<section className="fullscreen-shell">
<form className="auth-card" onSubmit={handleSubmit}>
<div className="brand-kicker">AIVideo Admin</div>
<h3></h3>
<div className="form-stack">
<label className="field-label">
<input
value={form.username}
onChange={(event) =>
setForm((previous) => ({ ...previous, username: event.target.value }))
}
/>
</label>
<label className="field-label">
<input
type="password"
value={form.password}
onChange={(event) =>
setForm((previous) => ({ ...previous, password: event.target.value }))
}
/>
</label>
{error ? <div className="muted" style={{ color: "var(--danger)" }}>{error}</div> : null}
<button className="primary-button" type="submit">
{loading ? "登录中..." : "进入后台"}
</button>
</div>
</form>
</section>
</div>
);
}