Files
web/src/lib/api.ts

36 lines
632 B
TypeScript
Raw Normal View History

2025-03-19 15:49:18 +08:00
// API工具函数
// 定义后端服务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> = {
2025-03-19 15:49:18 +08:00
success: false
status: number
message: string
} | {
success: true
data: T
}
type PageRecord<T = unknown> = {
total: number
page: number
size: number
list: T[]
}
// 预定义错误
const UnauthorizedError = new Error('未授权访问')
export {
API_BASE_URL,
CLIENT_ID,
CLIENT_SECRET,
type ApiResponse,
type PageRecord,
UnauthorizedError,
}