提交代码
This commit is contained in:
1 parent
d9f760fe1c
commit
01588bf87d
484 files changed
+7228
-104711
No files matched your search
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
// request.js 的 TypeScript 声明文件
|
||||
|
||||
export interface ApiResponse<T = any> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
rows?: T[]
|
||||
total?: number
|
||||
}
|
||||
|
||||
export interface RequestOptions {
|
||||
url: string
|
||||
method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
||||
data?: any
|
||||
header?: Record<string, any>
|
||||
timeout?: number
|
||||
clientId?: string
|
||||
}
|
||||
|
||||
export interface LoginData {
|
||||
username: string
|
||||
password: string
|
||||
tenantId?: string
|
||||
clientId?: string
|
||||
grantType?: string
|
||||
}
|
||||
|
||||
export interface UploadResponse {
|
||||
code: number
|
||||
msg: string
|
||||
data: {
|
||||
url: string
|
||||
ossId: string
|
||||
fileName: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface DownloadResponse {
|
||||
statusCode: number
|
||||
tempFilePath: string
|
||||
errMsg: string
|
||||
}
|
||||
|
||||
// 主要导出函数
|
||||
export function request(options: RequestOptions): Promise<ApiResponse>
|
||||
|
||||
// 便捷请求方法
|
||||
export function get<T = any>(url: string, data?: any, header?: Record<string, any>): Promise<ApiResponse<T>>
|
||||
export function post<T = any>(url: string, data?: any, header?: Record<string, any>): Promise<ApiResponse<T>>
|
||||
export function put<T = any>(url: string, data?: any, header?: Record<string, any>): Promise<ApiResponse<T>>
|
||||
export function del<T = any>(url: string, data?: any, header?: Record<string, any>): Promise<ApiResponse<T>>
|
||||
|
||||
// 文件操作方法
|
||||
export function uploadFile(url: string, filePath: string, formData?: Record<string, any>): Promise<UploadResponse>
|
||||
export function downloadFile(url: string): Promise<DownloadResponse>
|
||||
export function download(url: string, params: any, fileName: string): Promise<any>
|
||||
|
||||
// API对象
|
||||
export const api: {
|
||||
login: (data: LoginData) => Promise<ApiResponse>
|
||||
getUserInfo: () => Promise<ApiResponse>
|
||||
getTenantList: (isToken?: boolean) => Promise<ApiResponse>
|
||||
logout: () => Promise<ApiResponse>
|
||||
}
|
||||
Reference in new issue
Block a user