Files
ai-learning-platform/frontend/src/app/admin/login/page.tsx
T
yuzhiran-dev 23edb74bce feat: 支付闭环 + 运营助手 Tool Calling + 管理后台完善
- 支付系统:微信支付 mock 自动完成、NATIVE 扫码支付、JSAPI 集成
- 运营助手:Tool Calling 架构,19 个可执行工具,AI 驱动操作
- 角色管理:表格布局 + Dialog 表单 + 权限勾选
- 配置统一:config.ts 单一数据源
- API 审计:补齐 status toggle / comments 端点
- 暗黑模式硬件编码颜色全部替换为 CSS 变量
2026-05-20 18:29:00 +08:00

79 lines
2.9 KiB
TypeScript

'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';
import { API_BASE } from '@/lib/config';
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);
localStorage.setItem('adminInfo', JSON.stringify({ username: data.username, role: data.role }));
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>
);
}