Files
2024-09-27 01:32:49 +08:00

337 lines
7.1 KiB
JavaScript

import {Config} from './config'
export const http_use = function(params,data) { // 实际使用的 请求方法
// uni.showLoading({
// title: '加载中',
// mask: true
// })
return new Promise((resolve, reject) => {
uni.request({
url: Config.baseUrl + params, // 仅为示例,并非真实的接口地址
method: 'get',
data: data,
header: {
'content-type': 'application/x-www-form-urlencoded', // 默认值
// 'Authorization': Config.Authorization,
'authentication':uni.getStorageSync('isAuthentication') //加密后签名
},
success: function(res) {
// uni.hideLoading()
if(res.data.code == 40000){
uni.showToast({
title: '请先登录',
duration: 2000
});
uni.removeStorageSync('isAuthentication');
setTimeout(function(){
uni.reLaunch({
url: '/pages/my/x_login'
})
}, 1000);
// uni.showModal({
// title: '提示',
// content: '请先登录',
// success: function (res) {
// if (res.confirm) {
// uni.removeStorageSync('isAuthentication');
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// } else if (res.cancel) {
// // console.log('用户点击取消');
// }
// }
// });
}
if(res.data.errcode == 5000) {
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
return
}
if(res.data.code == 500) {
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
return
}
if(res.data.code == 40000){
// uni.showToast({
// title: res.data.message,
// duration: 2000,
// icon:"none"
// });
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
}
if(res.data.code == 200) {
resolve(res.data)
}else{
}
},
fail: function(res) {
// uni.hideLoading()
reject(res)
},
complete: function() {
}
})
})
}
export const http_post = function(params,data,loading = true) { // 实际使用的 请求方法
if(loading){
// uni.showLoading({
// title: '加载中',
// mask: true
// })
}
return new Promise((resolve, reject) => {
uni.request({
url: Config.baseUrl + params, // 仅为示例,并非真实的接口地址
method: 'post',
data: data,
header: {
'content-type': 'application/x-www-form-urlencoded', // 默认值
// 'Authorization': Config.Authorization,
'authentication':uni.getStorageSync('isAuthentication') //加密后签名
},
success: function(res) {
// uni.hideLoading()
if(res.data.code == 40000){
uni.showToast({
title: '请先登录',
duration: 2000
});
uni.removeStorageSync('isAuthentication');
setTimeout(function(){
uni.reLaunch({
url: '/pages/my/x_login'
})
}, 1000);
// uni.showModal({
// title: '提示',
// content: '请登录',
// success: function (res) {
// if (res.confirm) {
// uni.removeStorageSync('isAuthentication');
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// } else if (res.cancel) {
// //console.log('用户点击取消');
// }
// }
// });
}
if(res.data.errcode){
uni.getStorage({
key: 'isAuthentication',
success: function (res) {
}
});
// uni.navigateTo({
// url:'/pages/my/x_login.vue'
// })
}
if(res.code == 5000){
uni.showToast({
title: res.msg,
duration: 2000,
icon:"none"
});
}
if(res.data.code == 40001) {
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
return
}
if(res.data.code == 401) {
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
return
}
if(res.data.errcode == 40001) {
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
return
}
if(res.data.code == 500) {
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
return
}
if(res.data.code == 200) {
resolve(res.data)
}else{
if(res.data.code == 40002) {
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
return
}
// resolve(res.data)
if(res.data.errcode == 5000) {
// uni.showToast({
// title: res.message,
// duration: 2000,
// icon:"none"
// });
uni.showToast({
title: res.msg,
duration: 2000,
icon:"none"
});
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
return
}
if(res.data.errcode == 40002) {
uni.showToast({
title: res.message,
duration: 2000,
icon:"none"
});
return
}
if(res.data.code == 40000){
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
return
}
// if(res.data.message){
// uni.showToast({
// title: res.data.message,
// duration: 2000,
// icon:"none"
// });
// }
if(res.data.msg){
uni.showToast({
title: res.data.msg,
duration: 2000,
icon:"none"
});
}
if(res.msg){
uni.showToast({
title: res.msg,
duration: 2000,
icon:"none"
});
}
return
}
if(res.message == 40000){
uni.showToast({
title: res.message,
duration: 2000,
icon:"none"
});
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
}
if(res.data.code == 40000){
uni.showToast({
title: res.data.message,
duration: 2000,
icon:"none"
});
// setTimeout(function(){
// uni.reLaunch({
// url: '/pages/my/x_login'
// })
// }, 2000);
}
if(res.data.message){
// uni.showToast({
// title: res.data.message,
// duration: 2000,
// icon:"none"
// });
}
},
fail: function(res) {
// uni.hideLoading()
reject(res)
},
complete: function() {
}
})
})
}