/** * API 类型定义文件 */ import type { AxiosResponse, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'; // API客户端接口定义 export interface ApiClient { request(config: AxiosRequestConfig): Promise; get(url: string, config?: AxiosRequestConfig): Promise; post(url: string, data?: unknown, config?: AxiosRequestConfig): Promise; put(url: string, data?: unknown, config?: AxiosRequestConfig): Promise; delete(url: string, config?: AxiosRequestConfig): Promise; patch(url: string, data?: unknown, config?: AxiosRequestConfig): Promise; setDefaults(config: Partial): void; setBaseURL(baseURL: string): void; createInstance(config?: Partial): ApiClient; addRequestInterceptor( onFulfilled?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise, onRejected?: (error: unknown) => unknown ): number; addResponseInterceptor( onFulfilled?: (response: AxiosResponse) => AxiosResponse | Promise, onRejected?: (error: unknown) => unknown ): number; removeRequestInterceptor(handler: number): void; removeResponseInterceptor(handler: number): void; } // API响应接口 export interface ApiResponse { success: boolean; data: T; message?: string; code?: number; } // 分页响应接口 export interface PaginatedResponse { items: T[]; total: number; page: number; pageSize: number; totalPages: number; } // 错误响应接口 export interface ErrorResponse { success: false; message: string; code?: number; details?: unknown; } // API端点常量 export const API_ENDPOINTS = { // 用户相关 USER_LOGIN: '/auth/login', USER_REGISTER: '/auth/register', USER_LOGOUT: '/auth/logout', USER_PROFILE: '/user/profile', USER_CURRENT: '/auth/me', // 聊天相关 CHAT_LIST: '/chat/list', CHAT_CREATE: '/chat/create', CHAT_DETAIL: '/chat/detail', CHAT_DELETE: '/chat/delete', CHAT_MESSAGE: '/chat/message', // 模型相关 MODEL_LIST: '/model/list', MODEL_DETAIL: '/model/detail', // 帖子相关 POST_LIST: '/post/list', POST_DETAIL: '/post/detail', POST_CREATE: '/post/create', POST_UPDATE: '/post/update', POST_DELETE: '/post/delete' } as const; // API状态码 export const ApiStatusCode = { OK: 200, CREATED: 201, NO_CONTENT: 204, BAD_REQUEST: 400, UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404, INTERNAL_SERVER_ERROR: 500 } as const; // API错误类型 export const ApiErrorType = { NETWORK_ERROR: 'NETWORK_ERROR', VALIDATION_ERROR: 'VALIDATION_ERROR', AUTHENTICATION_ERROR: 'AUTHENTICATION_ERROR', AUTHORIZATION_ERROR: 'AUTHORIZATION_ERROR', NOT_FOUND_ERROR: 'NOT_FOUND_ERROR', SERVER_ERROR: 'SERVER_ERROR', UNKNOWN_ERROR: 'UNKNOWN_ERROR' } as const; // 默认请求配置 export const DEFAULT_REQUEST_CONFIG = { timeout: 10000, headers: { 'Content-Type': 'application/json' }, withCredentials: true } as const; // 默认分页配置 export const DEFAULT_PAGINATION_CONFIG = { page: 1, pageSize: 20 } as const;