2023-12-20 15:15:23 +08:00
|
|
|
|
class Http{
|
|
|
|
|
|
get(baseUrl='',url,data={},header={}){
|
|
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
|
|
uni.request({
|
|
|
|
|
|
url:baseUrl + url,
|
|
|
|
|
|
data:data,
|
|
|
|
|
|
method:"GET",
|
|
|
|
|
|
dataType:'json',
|
|
|
|
|
|
header:{
|
|
|
|
|
|
'content-type':'application/json',
|
|
|
|
|
|
'Authorization': uni.getStorageSync('token'),
|
|
|
|
|
|
...header
|
|
|
|
|
|
},
|
|
|
|
|
|
// 成功的回调
|
|
|
|
|
|
success(res) {
|
2024-03-21 15:42:08 +08:00
|
|
|
|
if (res.data.code == 401) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'none',
|
2024-04-01 09:11:26 +08:00
|
|
|
|
title: '登录状态过期,请重新登录!',
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-03-21 15:42:08 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resolve(res)
|
|
|
|
|
|
}
|
2023-12-20 15:15:23 +08:00
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
post(baseUrl='',url,data={},header={}){
|
|
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
|
|
uni.request({
|
|
|
|
|
|
url:baseUrl + url,
|
|
|
|
|
|
data:data,
|
|
|
|
|
|
method:"POST",
|
|
|
|
|
|
dataType:'json',
|
|
|
|
|
|
header:{
|
|
|
|
|
|
'content-type':'application/json',
|
|
|
|
|
|
'Authorization': uni.getStorageSync('token'),
|
|
|
|
|
|
...header
|
|
|
|
|
|
},
|
|
|
|
|
|
// 成功的回调
|
|
|
|
|
|
success(res) {
|
2024-04-01 09:11:26 +08:00
|
|
|
|
// console.log(res);
|
2024-03-21 15:42:08 +08:00
|
|
|
|
if (res.data.code == 401) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'none',
|
2024-04-01 09:11:26 +08:00
|
|
|
|
title: '登录状态过期,请重新登录!',
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-03-21 15:42:08 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resolve(res)
|
|
|
|
|
|
}
|
2023-12-20 15:15:23 +08:00
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
2024-04-07 09:39:22 +08:00
|
|
|
|
// console.log(err);
|
2023-12-20 15:15:23 +08:00
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
put(baseUrl='',url,data={},header={}){
|
|
|
|
|
|
return new Promise((resolve,reject) => {
|
|
|
|
|
|
uni.request({
|
|
|
|
|
|
url:baseUrl + url,
|
|
|
|
|
|
data:data,
|
|
|
|
|
|
method:"PUT",
|
|
|
|
|
|
dataType:'json',
|
|
|
|
|
|
header:{
|
|
|
|
|
|
'content-type':'application/json',
|
|
|
|
|
|
'Authorization': uni.getStorageSync('token'),
|
|
|
|
|
|
...header
|
|
|
|
|
|
},
|
|
|
|
|
|
// 成功的回调
|
|
|
|
|
|
success(res) {
|
2024-03-21 15:42:08 +08:00
|
|
|
|
if (res.data.code == 401) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'none',
|
2024-04-01 09:11:26 +08:00
|
|
|
|
title: '登录状态过期,请重新登录!',
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-03-21 15:42:08 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resolve(res)
|
|
|
|
|
|
}
|
2023-12-20 15:15:23 +08:00
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete(baseUrl='',url,data={},header={}){
|
|
|
|
|
|
return new Promise((resolve,reject) => {
|
|
|
|
|
|
uni.request({
|
|
|
|
|
|
url:baseUrl + url,
|
|
|
|
|
|
data:data,
|
|
|
|
|
|
method:"DELETE",
|
|
|
|
|
|
dataType:'json',
|
|
|
|
|
|
header:{
|
|
|
|
|
|
'content-type':'application/json',
|
|
|
|
|
|
'Authorization': uni.getStorageSync('token'),
|
|
|
|
|
|
...header
|
|
|
|
|
|
},
|
|
|
|
|
|
// 成功的回调
|
|
|
|
|
|
success(res) {
|
2024-03-21 15:42:08 +08:00
|
|
|
|
if (res.data.code == 401) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'none',
|
2024-04-01 09:11:26 +08:00
|
|
|
|
title: '登录状态过期,请重新登录!',
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-03-21 15:42:08 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resolve(res)
|
|
|
|
|
|
}
|
2023-12-20 15:15:23 +08:00
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-03-13 17:55:34 +08:00
|
|
|
|
|
|
|
|
|
|
upload(baseUrl='',url,data={},header={}){
|
|
|
|
|
|
return new Promise((resolve,reject) => {
|
|
|
|
|
|
uni.uploadFile({
|
|
|
|
|
|
url:baseUrl + url,
|
|
|
|
|
|
filePath: data,
|
|
|
|
|
|
header:{
|
|
|
|
|
|
'Authorization': uni.getStorageSync('token'),
|
|
|
|
|
|
...header
|
|
|
|
|
|
},
|
|
|
|
|
|
name: 'file',
|
|
|
|
|
|
// 成功的回调
|
|
|
|
|
|
success(res) {
|
2024-03-21 15:42:08 +08:00
|
|
|
|
if (res.data.code == 401) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'none',
|
2024-04-01 09:11:26 +08:00
|
|
|
|
title: '登录状态过期,请重新登录!',
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-03-21 15:42:08 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resolve(res)
|
|
|
|
|
|
}
|
2024-03-13 17:55:34 +08:00
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-12-20 15:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default new Http()
|