18e915bcbb
- 文章管理:计数请求补 page=1 参数,命中分页接口返回正确的 total - 分类管理:编辑模式新增描述输入框,保存时一并提交 description - CSP:img-src 加入 https: 允许加载外部图片 - 关于页:数据存储描述从 JSON 文件更正为 SQLite 数据库 - Footer:添加 ICP 备案号
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useToast, safeFetch } from "@/components/Toast";
|
|
import { ToastProvider } from "@/components/Toast";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
export default function LoginPage() {
|
|
return (
|
|
<ToastProvider>
|
|
<LoginForm />
|
|
</ToastProvider>
|
|
);
|
|
}
|
|
|
|
function LoginForm() {
|
|
const [password, setPassword] = useState("");
|
|
const [loading, setLoading] = useState(false);
|
|
const { toast } = useToast();
|
|
const router = useRouter();
|
|
|
|
async function handleSubmit(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
setLoading(true);
|
|
try {
|
|
await safeFetch("/api/auth", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ password }),
|
|
}, toast);
|
|
router.push("/admin");
|
|
} catch { /* safeFetch 已弹 toast */ }
|
|
setLoading(false);
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background flex items-center justify-center px-4">
|
|
<div className="w-full max-w-sm">
|
|
<div className="text-center mb-10">
|
|
<h1 className="font-display text-3xl font-medium">后台管理</h1>
|
|
<p className="mt-2 font-sans text-sm text-muted-foreground">asui.xyz</p>
|
|
</div>
|
|
<form onSubmit={handleSubmit} className="space-y-5">
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="password">管理密码</Label>
|
|
<Input
|
|
id="password"
|
|
type="password"
|
|
placeholder="输入管理密码"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
autoFocus
|
|
/>
|
|
</div>
|
|
<Button type="submit" disabled={loading} className="w-full">
|
|
{loading ? "验证中..." : "登录"}
|
|
</Button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|