@@ -1,20 +1,20 @@
|
||||
/**
|
||||
* 所有服务端接口的统一响应结构
|
||||
* 前端调用 /api/* 时收到的永远是这个格式
|
||||
* 所有服务端接口的统一响应结构。
|
||||
* 前端调用 /api/* 时统一接收这个格式。
|
||||
*/
|
||||
export interface ApiResponse<T = any> {
|
||||
export interface ICommonResponse<T = any> {
|
||||
/** 业务状态码:0 = 成功,其他值为对应错误码 */
|
||||
code: number;
|
||||
/** 响应数据:成功时为实际数据,无数据或失败时为 null */
|
||||
data: T | null;
|
||||
/** 提示信息:成功时默认 "请求成功",失败时为错误原因描述 */
|
||||
/** 提示信息:成功或失败时展示给前端的文案 */
|
||||
msg: string;
|
||||
}
|
||||
|
||||
/** 语义化的成功响应类型,code 固定为字面量 0,便于类型收窄 */
|
||||
export type SuccessResponse<T = any> = ApiResponse<T> & { code: 0 };
|
||||
export type ISuccessResponse<T = any> = ICommonResponse<T> & { code: 0 };
|
||||
|
||||
/** 语义化的错误响应类型,data 固定为 null */
|
||||
export type ErrorResponse = ApiResponse<null> & { code: number };
|
||||
/** 语义化的错误响应类型 */
|
||||
export type IErrorResponse = ICommonResponse<null> & { code: number };
|
||||
|
||||
export * from "./user";
|
||||
|
||||
Reference in New Issue
Block a user