2026-02-28 17:51:15 +08:00
|
|
|
import { http } from './index';
|
|
|
|
|
|
|
|
|
|
export interface LoginParams {
|
|
|
|
|
account: string;
|
|
|
|
|
password: string;
|
|
|
|
|
role: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 14:24:59 +08:00
|
|
|
// Java 后端返回的平铺结构
|
2026-02-28 17:51:15 +08:00
|
|
|
export interface LoginResponse {
|
|
|
|
|
token: string;
|
2026-03-03 14:24:59 +08:00
|
|
|
userId: number;
|
|
|
|
|
username: string;
|
|
|
|
|
name: string;
|
|
|
|
|
role: 'admin' | 'school' | 'teacher' | 'parent';
|
|
|
|
|
tenantId?: number;
|
2026-02-28 17:51:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UserProfile {
|
|
|
|
|
id: number;
|
|
|
|
|
name: string;
|
|
|
|
|
role: 'admin' | 'school' | 'teacher';
|
|
|
|
|
tenantId?: number;
|
|
|
|
|
tenantName?: string;
|
|
|
|
|
email?: string;
|
|
|
|
|
phone?: string;
|
|
|
|
|
avatar?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登录
|
|
|
|
|
export function login(params: LoginParams): Promise<LoginResponse> {
|
2026-03-09 19:09:53 +08:00
|
|
|
return http.post('/auth/login', params).then((res: any) => res.data);
|
2026-02-28 17:51:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登出
|
|
|
|
|
export function logout(): Promise<void> {
|
|
|
|
|
return http.post('/auth/logout');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 刷新Token
|
|
|
|
|
export function refreshToken(): Promise<{ token: string }> {
|
|
|
|
|
return http.post('/auth/refresh');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前用户信息
|
|
|
|
|
export function getProfile(): Promise<UserProfile> {
|
|
|
|
|
return http.get('/auth/profile');
|
|
|
|
|
}
|