first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
import config from "@/common/config";
export default class Http {
static http;
static singleton () {
if (this.http instanceof this) {
return this.http;
} else {
this.http = new this;
return this.http;
}
}
get(url = "", data = {}, header = {}) {
this.loading();
return new Promise((succ, error) => {
uni.request({
url: config.BaseUrl + url,
data: data,
method: 'GET',
header: Object.assign(
header,
{
token: localStorage.getItem("token")
}
),
success: (res) => {
succ(this.StateProcessing(res.data))
},
fail: (err) => {
throw new Error(err)
}
});
})
}
post(url = "", data = {}, header = {}) {
this.loading();
return new Promise((succ, error) => {
uni.request({
url: config.BaseUrl + url,
data: data,
method: 'POST',
header: Object.assign(
header,
{
token: localStorage.getItem("token")
}
),
success: (res) => {
succ(this.StateProcessing(res.data))
},
fail: (err) => {
throw new Error(err)
}
});
})
}
/**
* 加载进度条
*/
loading() {
uni.showLoading({
title: '加载中...'
});
}
/**
* 状态码处理
*/
StateProcessing(data) {
uni.hideLoading();
switch (data.status) {
case 200:
return data.result;
break;
case 404:
uni.showToast({
title: data.msg,
icon: 'none',
duration: 2000
});
throw new Error(data.msg);
break;
}
}
}