feat: Phase 1-3 全部完成 — 沙盒增强、学情分析、学习路径

This commit is contained in:
yuzhiran-dev
2026-05-18 09:48:51 +08:00
commit 11bb86854c
277 changed files with 37755 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
'use client';
import { useState, FormEvent } from 'react';
import { useRouter } from 'next/navigation';
import { toast } from 'sonner';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000/api/v1';
export default function AdminLoginPage() {
const router = useRouter();
const [form, setForm] = useState({ username: '', password: '' });
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
async function handleSubmit(e: FormEvent) {
e.preventDefault();
setError('');
if (!form.username || !form.password) { setError('请填写账号和密码'); return; }
setLoading(true);
try {
const res = await fetch(`${API_BASE}/admin/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(form),
});
const data = await res.json();
if (!res.ok) throw new Error(data.message || '管理员登录失败');
localStorage.setItem('adminToken', data.token);
toast.success('管理员登录成功');
router.push('/admin');
} catch (err: any) {
setError(err.message);
}
setLoading(false);
}
return (
<div className="min-h-[calc(100vh-4rem)] flex items-center justify-center px-4 py-12">
<Card className="w-full max-w-sm">
<CardHeader className="text-center pb-2">
<div className="mx-auto mb-3 w-12 h-12 bg-gradient-to-br from-brand-500 to-brand-700 rounded-2xl flex items-center justify-center">
<span className="text-white font-bold text-lg">A</span>
</div>
<CardTitle className="text-xl"></CardTitle>
<CardDescription> AI </CardDescription>
</CardHeader>
<CardContent>
{error && (
<div className="mb-4 p-3 bg-destructive/10 border border-destructive/20 rounded-lg text-sm text-destructive">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<Input
type="text"
placeholder="管理员账号"
value={form.username}
onChange={(e) => setForm(f => ({ ...f, username: e.target.value }))}
autoFocus
/>
<Input
type="password"
placeholder="密码"
value={form.password}
onChange={(e) => setForm(f => ({ ...f, password: e.target.value }))}
/>
<Button type="submit" disabled={loading} className="w-full">
{loading ? '登录中...' : '登录'}
</Button>
</form>
</CardContent>
</Card>
</div>
);
}