function req(obj) {
|
return new Promise((resolve, reject) => {
|
// const HOST = uni.getStorageSync('isUrl')// 线上地址
|
// const HOST = 'http://192.168.0.189:8001' // 线上地址
|
const HOST = 'http://192.168.0.191:8001' // 正式生产线上地址
|
//const HOST = 'http://120.53.244.200:5578' // 线上地址
|
//const HOST = 'http://10.10.40.78:8111' // 线上地址
|
// const HOST = 'http://localhost:8001' // 本地地址
|
//const HOST = 'http://10.10.40.183:8001'
|
var method = obj.method || "GET";
|
var url = HOST + obj.url || "";
|
if (obj.url.indexOf('http') != -1) {
|
url = obj.url;
|
}
|
var data = obj.data || {};
|
var header = obj.header || {
|
'Content-Type': obj.contentType || 'application/json',
|
'token': uni.getStorageSync('token'),
|
'appType': 'OPEN'
|
};
|
var success = obj.success; // 成功回调函数
|
var fail = obj.fail; //表示失败后,要执行的回调函数
|
uni.showLoading({
|
title: '加载中...',
|
mask: true
|
});
|
console.log('xxxxx',obj)
|
uni.request({
|
url: url,
|
data: data,
|
method: method,
|
header: header,
|
success: ((res) => {
|
console.log('success',res)
|
uni.hideLoading();
|
if (res.statusCode == 403 || res.statusCode == 401) {
|
// 错误处理,返回登录页
|
uni.reLaunch({
|
url: '/pages/Login/index'
|
})
|
} else if (res.data.message == '用户未登录,请先登录程序') {
|
uni.showToast({
|
title: '用户登陆状态失效',
|
icon: 'none',
|
duration: 2000,
|
success: function(res) {
|
setTimeout(() => {
|
uni.reLaunch({
|
url: '/pages/login/index'
|
})
|
}, 1000)
|
}
|
});
|
} else if (res.statusCode == 200) {
|
resolve(res)
|
uni.hideLoading();
|
} else {
|
let msg = res.errMsg || `接口调用出错:${res.statusCode}`
|
uni.showModal({
|
title:'系统提示',
|
content:msg,
|
showCancel:false
|
})
|
reject(res)
|
uni.hideLoading();
|
}
|
}),
|
fail: ((err) => {
|
console.log('fail',err)
|
uni.hideLoading();
|
reject(err)
|
}),
|
complete: (e) => {
|
console.log('complete')
|
uni.hideLoading();
|
}
|
})
|
})
|
}
|
export default req
|