export type UserRole = "stu" | "teacher"; export interface User { id: string; username: string; role: UserRole; name: string; avatar: string; } export interface AuthResponse { token: string; user: User; } const AUTH_USERS: Record = { stu: { id: "231250001", username: "stu", role: "stu", name: "李子涵", avatar: "/images/profile-avatar.png", }, teacher: { id: "tea_001", username: "teacher", role: "teacher", name: "刘钦", avatar: "/images/profile-avatar.png", }, }; const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); export const authApi = { login: async (username: string, password: string): Promise => { await delay(300); if (password !== "passwd") { throw new Error("密码错误"); } const user = AUTH_USERS[username]; if (!user) { throw new Error("用户不存在"); } return { token: `local_auth_${user.username}_${user.id}_${Date.now()}`, user, }; }, verifySession: async (token: string | null): Promise => { await delay(120); if (!token) { return null; } return Object.values(AUTH_USERS).find((user) => token.includes(user.id)) ?? null; }, };