feat: 大部分注册登录功能

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-24 18:02:42 +08:00
parent 5ab74ad9dd
commit 5294528148
23 changed files with 858 additions and 167 deletions
+16 -16
View File
@@ -1,16 +1,16 @@
import type { ApiResponse } from "#shared/types";
import type { ICommonResponse } from "#shared/types";
/**
* 构造统一成功响应
* 构造统一成功响应
*
* @param data 要返回给前端的数据,没有数据时传 null(默认)
* @param msg 提示信息,默认 "请求成功"
* @returns 符合 ApiResponse 格式的对象,code 固定为 0
* @param data 要返回给前端的数据,没有数据时传 null
* @param msg 提示信息,默认请求成功
* @returns 符合 ICommonResponse 格式的对象,code 固定为 0
*/
export const createSuccessResponse = <T>(
data: T | null = null,
msg: string = "请求成功"
): ApiResponse<T> => {
): ICommonResponse<T> => {
return {
code: 0,
data,
@@ -19,18 +19,18 @@ export const createSuccessResponse = <T>(
};
/**
* 构造统一错误响应
* 构造统一错误响应
*
* @param code 错误码,默认 400(请求参数错误);上游错误时传上游状态码
* @param msg 错误描述,展示给前端的提示文
* @param data 附带的错误详情,通常是上游返回的原始响应体,默认 null
* @returns 符合 ApiResponse 格式的对象,data 固定为 null 或错误详情
* @param code 错误码,默认 400;上游错误时传上游状态码
* @param msg 错误描述,展示给前端的提示文
* @param data 附带的错误详情,通常是上游返回的原始响应体
* @returns 符合 ICommonResponse 格式的错误响应
*/
export const createErrorResponse = (
code: number = 400,
msg: string = "请求失败",
data: any = null
): ApiResponse => {
data: unknown = null
): ICommonResponse => {
return {
code,
data,
@@ -39,16 +39,16 @@ export const createErrorResponse = (
};
/**
* 将上游请求错误转换为统一响应
* 将上游请求错误转换为统一响应
*
* @param error ofetch 抛出的错误对象
* @param fallbackMessage 当上游没有提供可用错误信息时的兜底提示
* @returns 符合 ApiResponse 格式的错误响应
* @returns 符合 ICommonResponse 格式的错误响应
*/
export const createUpstreamErrorResponse = (
error: unknown,
fallbackMessage: string = "请求失败"
): ApiResponse => {
): ICommonResponse => {
const fetchError = error as {
data?: unknown;
message?: string;