修改接口请求格式

启动报错
master
liaoanqi 3 years ago
parent 3b60481203
commit c5f2366461

@ -4,5 +4,4 @@ var mpAppId = 'wx42bbe857570c5b40'
var domain = "http://127.0.0.1:8086"; //统一接口域名,测试环境 var domain = "http://127.0.0.1:8086"; //统一接口域名,测试环境
exports.domain = domain; exports.domain = domain;
exports.wsDomain = wsDomain;
exports.mpAppId = mpAppId; exports.mpAppId = mpAppId;

@ -37,25 +37,18 @@ function request(params, isGetTonken) {
dataType: 'json', dataType: 'json',
responseType: params.responseType == undefined ? 'text' : params.responseType, responseType: params.responseType == undefined ? 'text' : params.responseType,
success: function (res) { success: function (res) {
if (res.statusCode == 200) { const responseData = res.data
//如果有定义了params.callBack则调用 params.callBack(res.data)
// 00000 请求成功
if (responseData.code === '00000') {
if (params.callBack) { if (params.callBack) {
params.callBack(res.data); params.callBack(responseData.data);
}
return
} }
} else if (res.statusCode == 500) {
uni.showToast({
title: "服务器出了点小差",
icon: "none"
});
} else if (res.statusCode == 401) {
// 添加到请求队列
// globalData.requestQueue.push(params); // 是否正在登陆
// if (!globalData.isLanding) {
// globalData.isLanding = true; //重新获取token,再次请求接口
// getToken(); // A00004 未授权
// } if (responseData.code === 'A00004') {
uni.removeStorageSync('loginResult'); uni.removeStorageSync('loginResult');
uni.removeStorageSync('token'); uni.removeStorageSync('token');
// #ifdef H5 // #ifdef H5
@ -136,24 +129,52 @@ function request(params, isGetTonken) {
// // #endif // // #endif
} }
} }
} else if (res.statusCode == 400 && !params.errCallBack) { return
uni.hideLoading(); }
// A00005 服务器出了点小差
if (responseData.code === 'A00005') {
console.error('============== 请求异常 ==============')
console.log('接口: ', params.url)
console.log('异常信息: ', responseData)
console.error('============== 请求异常 ==============')
if (params.errCallBack) {
params.errCallBack(responseData)
return
}
uni.showToast({ uni.showToast({
title: res.data, title: '服务器出了点小差~',
icon: "none" icon: 'none'
}); })
} else { }
//如果有定义了params.errCallBack则调用 params.errCallBack(res.data)
// A00001 用于直接显示提示用户的错误,内容由输入内容决定
if (responseData.code === 'A00001') {
if (params.errCallBack) { if (params.errCallBack) {
params.errCallBack(responseData)
return
}
uni.showToast({
title: responseData.msg || 'Error',
icon: 'none'
})
return
}
params.errCallBack(res); // 其他异常
if (responseData.code !== '00000') {
// console.log('params', params)
if (params.errCallBack) {
params.errCallBack(responseData)
} else {
console.log(`接口: ${params.url}`)
console.log(`返回信息: `, res)
} }
uni.hideLoading();
} }
// if (!globalData.isLanding) { if (!globalData.isLanding) {
// uni.hideLoading(); wx.hideLoading();
// } }
}, },
fail: function (err) { fail: function (err) {
uni.hideLoading(); uni.hideLoading();
@ -168,10 +189,6 @@ function request(params, isGetTonken) {
icon: "none" icon: "none"
}); });
}, 1); }, 1);
// uni.showToast({
// title: "服务器出了点小差",
// icon: "none"
// });
} }
}); });
} //通过code获取token,并保存到缓存 } //通过code获取token,并保存到缓存

Loading…
Cancel
Save