Files
akmon/uni_modules/ak-req/interface.uts
2026-01-20 08:04:15 +08:00

49 lines
1.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ak-req 类型定义
export type AkReqOptions = {
url: string;
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' |'HEAD';
data?: UTSJSONObject | Array<UTSJSONObject>;
headers?: UTSJSONObject;
timeout?: number;
contentType?: string; // 新增,支持顶级 contentType
// 可选:重试设置(仅网络错误/超时触发)。默认重试 0 次
retryCount?: number; // 最大重试次数,默认 0
retryDelayMs?: number; // 首次重试延迟,默认 300ms指数退避
};
// 上传参数类型定义
export type AkReqUploadOptions = {
url: string,
filePath: string,
name: string,
formData?: UTSJSONObject,
headers?: UTSJSONObject,
apikey?: string,
timeout?: number,
// 进度回调0-100注意H5/APP 平台支持不同)
onProgress?: (progress: number, transferredBytes?: number, totalBytes?: number) => void,
// 可选:重试设置(仅网络错误/超时触发)。默认 0
retryCount?: number,
retryDelayMs?: number
};
export type AkReqResponse<T = any> = {
status: number;
data: T | Array<T> | null; // 支持 null
headers: UTSJSONObject;
error: UniError | null;
total:number |null;
page: number |null;
limit: number |null;
hasmore:boolean |null;
origin: any | null;
};
export class AkReqError extends Error {
code: number;
constructor(message: string, code: number = 0) {
super(message);
this.code = code;
this.name = 'AkReqError';
}
}