更新代码
This commit is contained in:
16
http/http.js
16
http/http.js
@@ -14,7 +14,7 @@ function getHeader() {
|
||||
}
|
||||
|
||||
// 通用处理逻辑
|
||||
function commonsProcess(showLoading, httpReqCallback) {
|
||||
function commonsProcess(showLoading, httpReqCallback,isreturm) {
|
||||
// 判断是否请求完成(用作 是否loading )
|
||||
// 包括: 'ing', 'ingLoading', 'finish'
|
||||
let reqState = "ing";
|
||||
@@ -41,11 +41,15 @@ function commonsProcess(showLoading, httpReqCallback) {
|
||||
|
||||
return httpReqCallback()
|
||||
.then((httpData) => {
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
|
||||
let { statusCode, data } = httpData;
|
||||
// 避免混淆重新命名
|
||||
let bodyData = data;
|
||||
if(isreturm){
|
||||
return Promise.resolve(bodyData.data || bodyData.page|| bodyData);
|
||||
}
|
||||
if (statusCode == 500) {
|
||||
isShowErrorToast = true;
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
@@ -81,11 +85,12 @@ function commonsProcess(showLoading, httpReqCallback) {
|
||||
code: bodyData.code,
|
||||
});
|
||||
}
|
||||
|
||||
// 构造请求成功的响应数据
|
||||
return Promise.resolve(bodyData.data || bodyData.page|| bodyData);
|
||||
})
|
||||
.catch((res) => {
|
||||
console.log(res);
|
||||
|
||||
if (res.status == 404) {
|
||||
infoBox.showErrorToast("接口404").then(() => {});
|
||||
reject();
|
||||
@@ -147,7 +152,8 @@ function request(args) {
|
||||
params,
|
||||
method = "GET",
|
||||
showLoading = true,
|
||||
extParams = {}
|
||||
extParams = {},
|
||||
isreturm=false
|
||||
} = args
|
||||
if (params) {
|
||||
let result = ''
|
||||
@@ -170,7 +176,7 @@ function request(args) {
|
||||
}, extParams)
|
||||
|
||||
)
|
||||
})
|
||||
},isreturm)
|
||||
}
|
||||
// 处理/
|
||||
function slash(baseUrl, url) {
|
||||
|
||||
Reference in New Issue
Block a user