feat: 新增api接口

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-24 15:36:44 +08:00
parent 278f1aab85
commit 5ab74ad9dd
13 changed files with 537 additions and 59 deletions
+20
View File
@@ -0,0 +1,20 @@
/**
* 所有服务端接口的统一响应结构
* 前端调用 /api/* 时收到的永远是这个格式
*/
export interface ApiResponse<T = any> {
/** 业务状态码:0 = 成功,其他值为对应错误码 */
code: number;
/** 响应数据:成功时为实际数据,无数据或失败时为 null */
data: T | null;
/** 提示信息:成功时默认 "请求成功",失败时为错误原因描述 */
msg: string;
}
/** 语义化的成功响应类型,code 固定为字面量 0,便于类型收窄 */
export type SuccessResponse<T = any> = ApiResponse<T> & { code: 0 };
/** 语义化的错误响应类型,data 固定为 null */
export type ErrorResponse = ApiResponse<null> & { code: number };
export * from "./user";
+47
View File
@@ -0,0 +1,47 @@
/**
* 用户注册请求体
* 对应 NewAPI POST /api/user/register 接口
* 所有字段均为可选,上游接口本身不强制任何字段
*/
export interface UserRegisterRequest {
/** 用户名 */
username?: string;
/** 登录密码 */
password?: string;
/** 邮箱地址 */
email?: string;
/** 邮箱验证码(注册时若开启邮箱验证则需要填写) */
verification_code?: string;
/** 推广码 / 邀请码 */
aff_code?: string;
}
/**
* 注册成功时上游接口返回的数据类型
* NewAPI 注册接口成功时直接返回字符串 "成功"
*/
export type UserRegisterResult = string;
/**
* 用户登录请求体
* 对应 NewAPI POST /api/user/login 接口
* 所有字段均为可选,上游接口本身不强制任何字段
*/
export interface UserLoginRequest {
/** 用户名 */
username?: string;
/** 登录密码 */
password?: string;
}
/**
* 登录成功时上游接口返回的数据类型
* NewAPI 登录接口成功时响应体为空,此处用 null 表示
*/
export type UserLoginResult = null;
/**
* 登出成功时上游接口返回的数据类型
* NewAPI 登出接口通常无业务数据返回,此处用 null 表示
*/
export type UserLogoutResult = null;