diff --git a/enum/HttpMethod.uts b/enum/HttpMethod.uts new file mode 100644 index 0000000..ca86914 --- /dev/null +++ b/enum/HttpMethod.uts @@ -0,0 +1,9 @@ +export enum HttpMethod { + GET = "GET", + POST = "POST", + PUT = "PUT", + PATCH = "PATCH", + DELETE = "DELETE", + HEAD ="HEAD", + OPTIONS="OPTIONS" +} \ No newline at end of file diff --git a/types/HttpClientType.uts b/types/HttpClientType.uts new file mode 100644 index 0000000..422da4e --- /dev/null +++ b/types/HttpClientType.uts @@ -0,0 +1,76 @@ +import { HttpMethod } from "@/enum/HttpMethod" + +export class RequestHeaders { + isToken : boolean = false + isEncrypt : boolean = false + repeatSubmit : boolean = false + constructor() { } +} + +export class RequestConfig { + // 请求地址(API URL) + url : string = "" + // HTTP 请求方法 + method ?: HttpMethod = HttpMethod.GET + // 请求参数 + data ?: any = null + // 请求头 + headers ?: RequestHeaders = new RequestHeaders() + // Query参数(GET) + params ?: any = null + // 请求超时时间(毫秒) + timeout ?: number = 15000 + // 是否显示加载提示 + loading ?: boolean = true + // 请求失败时是否显示错误提示 + showError ?: boolean = true + constructor() { } +} + +export class ApiResponse { + code : number = 0 + msg : string = "" + data : T | null = null + constructor() { } +} + +export class HttpException { + code : number + message : string + constructor( + code : number, + message : string + ) { + this.code = code + this.message = message + } +} + +export class LoadingManager { + private static count : number = 0 + static show() { + this.count++ + if (this.count == 1) { + uni.showLoading({ + title: "加载中", + mask: true + }) + } + } + static hide() { + if (this.count <= 0) { + return + } + this.count-- + if (this.count == 0) { + uni.hideLoading() + } + } + static getCount() : number { + return this.count + } + static reset() { + this.count = 0 + uni.hideLoading() + } +} \ No newline at end of file