1. Add 登陆功能

2. 调整字体大小
3. 新增部分功能
This commit is contained in:
2026-06-05 18:00:31 +08:00
parent 06e0967128
commit 9fea9c6a53
58 changed files with 5028 additions and 322 deletions

43
frontend/src/api/auth.ts Normal file
View File

@@ -0,0 +1,43 @@
const AUTH_API_BASE = '/api/v1';
export interface TokenResponse {
access_token: string;
token_type: string;
expires_in: number;
}
export interface MeResponse {
user_id: string;
username: string;
role: string;
}
export async function loginRequest(
username: string,
password: string,
): Promise<TokenResponse> {
const body = new URLSearchParams();
body.set('username', username);
body.set('password', password);
const res = await fetch(`${AUTH_API_BASE}/auth/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: body.toString(),
});
if (!res.ok) {
const payload = await res.json().catch(() => ({})) as { detail?: string };
throw new Error(payload.detail ?? `Login failed (${res.status})`);
}
return res.json() as Promise<TokenResponse>;
}
export async function getMeRequest(token: string): Promise<MeResponse> {
const res = await fetch(`${AUTH_API_BASE}/auth/me`, {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(`Unauthorised (${res.status})`);
return res.json() as Promise<MeResponse>;
}