后端 FastAPI 六层结构(api/services/repositories/models/schemas/core), 统一响应信封、全局异常、日志脱敏;6 张表经 Alembic 迁移建库,SQL 留存 db/migration;登录鉴权含图形验证码(Redis GETDEL 防重放)、JWT、登录限流、 登出黑名单(TTL=令牌剩余有效期)、登录日志。 前端 Vue3 + TS + Element Plus 骨架,含登录页、路由守卫、请求封装与 Vite 代理。 工程配置:uv 锁定 Python 3.12、ruff 检查与格式化、editorconfig、gitattributes。 测试 184 项(单元 155 / 集成 29)全绿,浏览器端到端 8 项通过。 Co-Authored-By: Claude Code <noreply@anthropic.com>
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { request } from './request'
|
||
|
||
/** 图形验证码 */
|
||
export interface CaptchaResult {
|
||
captcha_id: string
|
||
/** PNG 图片的 base64,**不含** data: 前缀,由前端自行拼接 */
|
||
image_base64: string
|
||
expires_in: number
|
||
}
|
||
|
||
export interface LoginParams {
|
||
username: string
|
||
password: string
|
||
captcha_id: string
|
||
captcha_code: string
|
||
}
|
||
|
||
export interface UserInfo {
|
||
id: number
|
||
username: string
|
||
real_name: string | null
|
||
roles: string[]
|
||
last_login_time?: string | null
|
||
}
|
||
|
||
export interface LoginResult {
|
||
access_token: string
|
||
token_type: string
|
||
expires_in: number
|
||
user: UserInfo
|
||
}
|
||
|
||
/** 获取图形验证码 */
|
||
export function getCaptcha(): Promise<CaptchaResult> {
|
||
return request<CaptchaResult>({ url: '/v1/auth/captcha', method: 'get' })
|
||
}
|
||
|
||
/** 登录 */
|
||
export function login(data: LoginParams): Promise<LoginResult> {
|
||
return request<LoginResult>({ url: '/v1/auth/login', method: 'post', data })
|
||
}
|
||
|
||
/** 登出 */
|
||
export function logout(): Promise<null> {
|
||
return request<null>({ url: '/v1/auth/logout', method: 'post' })
|
||
}
|
||
|
||
/** 获取当前登录用户(刷新页面后用它恢复会话) */
|
||
export function getCurrentUser(): Promise<UserInfo> {
|
||
return request<UserInfo>({ url: '/v1/auth/me', method: 'get' })
|
||
}
|