Files
xiaozhi-user-uniappx/types/HttpClientType.uts
T

76 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.
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<T> {
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()
}
}