From 55d2e56bbd2492423194f81ca1a794c13147ed69 Mon Sep 17 00:00:00 2001 From: xiaozhi <1822691309@qq.com> Date: Sun, 7 Jun 2026 11:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83=E5=8C=96=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E7=BB=9F=E4=B8=80=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=92=8C=E5=93=8D=E5=BA=94=E7=9A=84=E6=95=B0=E6=8D=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enum/HttpMethod.uts | 9 +++++ types/HttpClientType.uts | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 enum/HttpMethod.uts create mode 100644 types/HttpClientType.uts 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