Files
shaguabijia-admin-web/src/app/login/page.tsx
T
marco 125b0e1339 傻瓜比价运营后台前端 (Next.js 15 + Ant Design 5)
admin 后台 P0 + 配置后台化:登录/大盘/用户(360+封号+调金币)/提现(重试+对账)/反馈/管理员/审计/系统配置;对接 shaguabijia-app-server 的 admin API(独立 JWT + RBAC + 审计)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 21:05:29 +08:00

54 lines
1.7 KiB
TypeScript

'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Button, Card, Form, Input, message } from 'antd';
import { api, errMsg } from '@/lib/api';
import { setAuth } from '@/lib/auth';
import type { LoginResponse } from '@/lib/types';
export default function LoginPage() {
const router = useRouter();
const [loading, setLoading] = useState(false);
const onFinish = async (values: { username: string; password: string }) => {
setLoading(true);
try {
const { data } = await api.post<LoginResponse>('/admin/api/auth/login', values);
setAuth(data.access_token, data.admin);
message.success('登录成功');
router.replace('/dashboard');
} catch (e) {
message.error(errMsg(e, '登录失败'));
} finally {
setLoading(false);
}
};
return (
<div
style={{
minHeight: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: '#f0f2f5',
}}
>
<Card title="傻瓜比价 · 运营后台" style={{ width: 360 }}>
<Form onFinish={onFinish} layout="vertical">
<Form.Item name="username" label="用户名" rules={[{ required: true, message: '请输入用户名' }]}>
<Input autoFocus autoComplete="username" />
</Form.Item>
<Form.Item name="password" label="密码" rules={[{ required: true, message: '请输入密码' }]}>
<Input.Password autoComplete="current-password" />
</Form.Item>
<Button type="primary" htmlType="submit" loading={loading} block>
</Button>
</Form>
</Card>
</div>
);
}