实现登录功能

Signed-off-by: luorijun <luorijun@outlook.com>
This commit is contained in:
2025-12-29 14:09:13 +08:00
parent f9a8df0fe5
commit bb8aec8ce5
19 changed files with 1079 additions and 110 deletions

45
src/lib/api.ts Normal file
View File

@@ -0,0 +1,45 @@
// 定义后端服务URL和OAuth2配置
const API_BASE_URL = process.env.API_BASE_URL
const CLIENT_ID = process.env.CLIENT_ID
const CLIENT_SECRET = process.env.CLIENT_SECRET
// 统一的API响应类型
type ApiResponse<T = undefined> =
| {
success: false
status: number
message: string
}
| {
success: true
data: T
}
type PageRecord<T = unknown> = {
total: number
page: number
size: number
list: T[]
}
type ExtraReq<T extends (...args: never) => unknown> = T extends (
...args: infer P
) => unknown
? P[0]
: never
type ExtraResp<T extends (...args: never) => unknown> =
Awaited<ReturnType<T>> extends ApiResponse<infer D> ? D : never
// 预定义错误
const UnauthorizedError = new Error("未授权访问")
export {
API_BASE_URL,
CLIENT_ID,
CLIENT_SECRET,
type ApiResponse,
type PageRecord,
type ExtraReq,
type ExtraResp,
UnauthorizedError,
}

6
src/lib/utils.ts Normal file
View File

@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}