53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
|
|
import { goto } from "./untool";
|
||
|
|
import { showToast } from "./untool"
|
||
|
|
|
||
|
|
// 请求接口
|
||
|
|
function dealRequest(def, url, param) {
|
||
|
|
|
||
|
|
const promise = new Promise(function (resolve, reject) {
|
||
|
|
|
||
|
|
def.then(function (res) {
|
||
|
|
handleResponse(res, resolve, reject, url, param);
|
||
|
|
}, function (res) {
|
||
|
|
console.log('request url==========1', url)
|
||
|
|
console.log('request param==========1', param)
|
||
|
|
console.log('response ===========1', res);
|
||
|
|
showToast(`网络错误`)
|
||
|
|
reject(res)
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
// 统一提示 errmsg
|
||
|
|
promise.then(function (res) {
|
||
|
|
}, function (res) {
|
||
|
|
uni.hideLoading()
|
||
|
|
})
|
||
|
|
return promise;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 处理响应
|
||
|
|
function handleResponse(res, resolve, reject, url, param) {
|
||
|
|
const orgRes = { ...res };
|
||
|
|
if ((res && res.respCode == 1)) {
|
||
|
|
resolve(res.respData)
|
||
|
|
} else {
|
||
|
|
if (res.respCode == '-1') { // 统一判断需要认证, 并作页面跳转
|
||
|
|
showToast(res.respMsg)
|
||
|
|
setTimeout(()=>{
|
||
|
|
goto(`TODO`, 1)
|
||
|
|
}, 3500)
|
||
|
|
return reject({ code: {} });
|
||
|
|
}
|
||
|
|
|
||
|
|
setTimeout(()=> {
|
||
|
|
showToast(`网络错误`)
|
||
|
|
}, 0)
|
||
|
|
reject({code: {}});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export {
|
||
|
|
dealRequest,
|
||
|
|
handleResponse
|
||
|
|
}
|