|
@@ -8,6 +8,9 @@ const request = config => {
|
|
if (getToken()) {
|
|
if (getToken()) {
|
|
config.header['Authorization'] = 'Bearer ' + getToken()
|
|
config.header['Authorization'] = 'Bearer ' + getToken()
|
|
}
|
|
}
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ title:'请求中...'
|
|
|
|
+ })
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
uni.request({
|
|
uni.request({
|
|
@@ -18,14 +21,9 @@ const request = config => {
|
|
url: config.baseUrl || BASE_URL + config.url,
|
|
url: config.baseUrl || BASE_URL + config.url,
|
|
data: config.data,
|
|
data: config.data,
|
|
}).then((response) => {
|
|
}).then((response) => {
|
|
- let [error, res] = response
|
|
|
|
- if (error) {
|
|
|
|
- toast('后端接口连接异常')
|
|
|
|
- reject('后端接口连接异常')
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- const code = res.data.code || 200
|
|
|
|
- const msg = res.data.msg || '未知错误,请反馈给管理员'
|
|
|
|
|
|
+ let { data, statusCode } = response
|
|
|
|
+ const code = statusCode || 200
|
|
|
|
+ const msg = data.msg || '未知错误,请反馈给管理员'
|
|
|
|
|
|
if (code === 401) {
|
|
if (code === 401) {
|
|
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录').then(res => {
|
|
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录').then(res => {
|
|
@@ -39,7 +37,8 @@ const request = config => {
|
|
reject(code)
|
|
reject(code)
|
|
}
|
|
}
|
|
|
|
|
|
- resolve(res.data)
|
|
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ resolve(data)
|
|
}).catch(error => {
|
|
}).catch(error => {
|
|
let { message } = error
|
|
let { message } = error
|
|
if (message === 'Network Error') {
|
|
if (message === 'Network Error') {
|
|
@@ -49,10 +48,98 @@ const request = config => {
|
|
} else if (message.includes('Request failed with status code')) {
|
|
} else if (message.includes('Request failed with status code')) {
|
|
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
|
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ uni.hideLoading()
|
|
toast(message)
|
|
toast(message)
|
|
reject(error)
|
|
reject(error)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+// function request(req) {
|
|
|
|
+
|
|
|
|
+// let data = req.data
|
|
|
|
+// const method = req.method
|
|
|
|
+// const url = req.url
|
|
|
|
+// let loading = false
|
|
|
|
+// if (req.data.loading) {
|
|
|
|
+// loading = data.loading
|
|
|
|
+// delete data.loading
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// let header = {
|
|
|
|
+// 'Content-Type': 'application/json',
|
|
|
|
+// 'timestamp': Date.parse(new Date()),
|
|
|
|
+// // 'token': uni.getStorageSync('user').access_token,
|
|
|
|
+// 'Authorization': 'Bearer ' + uni.getStorageSync('user').access_token
|
|
|
|
+// }
|
|
|
|
+// if (loading) {
|
|
|
|
+// uni.hideLoading()
|
|
|
|
+// uni.showLoading({
|
|
|
|
+// title: '请求中',
|
|
|
|
+// mask: true
|
|
|
|
+// })
|
|
|
|
+// }
|
|
|
|
+// return new Promise((resolve, reject) => {
|
|
|
|
+// console.log('REQ ==>', url)
|
|
|
|
+// console.log(data)
|
|
|
|
+// uni.request({
|
|
|
|
+// url: BASE_URL + url,
|
|
|
|
+// data: data,
|
|
|
|
+// header: header,
|
|
|
|
+// method: method.toUpperCase(),
|
|
|
|
+// timeout: 1000 * 60 * 3, //超时三分钟
|
|
|
|
+// success: async (res) => {
|
|
|
|
+// uni.hideLoading()
|
|
|
|
+// console.log("RES <==", url)
|
|
|
|
+// console.log(res)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// if (res.statusCode == 200 && res.data.code == 200) {
|
|
|
|
+// resolve(res.data.data)
|
|
|
|
+// } else if (res.statusCode == 401) {
|
|
|
|
+// //处理token验证出错
|
|
|
|
+// console.log('Token过期')
|
|
|
|
+// if (!uni.getStorageSync('user')) {
|
|
|
|
+// //其他设备登录了
|
|
|
|
+// uni.reLaunch({
|
|
|
|
+// url: '/pages/login/login'
|
|
|
|
+// });
|
|
|
|
+// } else {
|
|
|
|
+// //token续租
|
|
|
|
+// let r = await login(uni.getStorageSync('user').login)
|
|
|
|
+// let result = await request(req)
|
|
|
|
+// }
|
|
|
|
+// } else {
|
|
|
|
+// console.error(res.data.msg)
|
|
|
|
+// if (res.data.msg == '登录状态已过期') {
|
|
|
|
+// uni.reLaunch({
|
|
|
|
+// url: '/pages/login/pages/login'
|
|
|
|
+// })
|
|
|
|
+// }
|
|
|
|
+// uni.showToast({
|
|
|
|
+// title: res.data.msg,
|
|
|
|
+// icon: "none",
|
|
|
|
+// position: "bottom",
|
|
|
|
+// duration: 3000
|
|
|
|
+// })
|
|
|
|
+// reject(false)
|
|
|
|
+// }
|
|
|
|
+// },
|
|
|
|
+// fail: (err) => {
|
|
|
|
+// uni.hideLoading()
|
|
|
|
+// uni.showToast({
|
|
|
|
+// title: '服务器休息中,请稍后再试',
|
|
|
|
+// icon: "none",
|
|
|
|
+// position: "center",
|
|
|
|
+// duration: 3000
|
|
|
|
+// });
|
|
|
|
+// console.error(url, err)
|
|
|
|
+// reject(err)
|
|
|
|
+// }
|
|
|
|
+// });
|
|
|
|
+// })
|
|
|
|
+// }
|
|
|
|
+
|
|
export default request
|
|
export default request
|