|
@@ -58,51 +58,51 @@ const request = config => {
|
|
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
if (code === 401) {
|
|
|
//token无效或已过期
|
|
|
- if (!isRefreshing) {
|
|
|
- // 是否已经执行刷新
|
|
|
- isRefreshing = true
|
|
|
- let token = getAccessToken(); // 获取到过期的token
|
|
|
- try {
|
|
|
- refreshToken({
|
|
|
- refreshToken: getRefreshToken() // 刷新token的令牌存在token的对象里面,需要传给后端
|
|
|
- }).then(reshRespore => {
|
|
|
- // console.log(reshRespore,
|
|
|
- // 'reshResporereshResporereshRespore');
|
|
|
- // 请求成功把新的token存到本地
|
|
|
- setToken(reshRespore.data);
|
|
|
- // 已经刷新了token,将所有队列中的请求进行重试
|
|
|
- requests.forEach((item) => item(reshRespore.data
|
|
|
- .accessToken))
|
|
|
- // requests = []
|
|
|
- // // 每个接口请求都要存入队列,等刷新完以后都需要执行
|
|
|
- // return new Promise((resolve) => {
|
|
|
- // // 将resolve放进队列,用一个函数形式来保存,等token刷新后直接执行
|
|
|
- // requests.push((token) => {
|
|
|
- // //这一步一定要有,刷新token,因为存入的信息是旧的token
|
|
|
- // response.config.header[
|
|
|
- // 'Authorization'] =
|
|
|
- // 'Bearer ' + token;
|
|
|
- // resolve(uni.$u.http.request(response
|
|
|
- // .config)) //执行请求
|
|
|
+ // if (!isRefreshing) {
|
|
|
+ // // 是否已经执行刷新
|
|
|
+ // isRefreshing = true
|
|
|
+ // let token = getAccessToken(); // 获取到过期的token
|
|
|
+ // try {
|
|
|
+ // refreshToken({
|
|
|
+ // refreshToken: getRefreshToken() // 刷新token的令牌存在token的对象里面,需要传给后端
|
|
|
+ // }).then(reshRespore => {
|
|
|
+ // // console.log(reshRespore,
|
|
|
+ // // 'reshResporereshResporereshRespore');
|
|
|
+ // // 请求成功把新的token存到本地
|
|
|
+ // setToken(reshRespore.data);
|
|
|
+ // // 已经刷新了token,将所有队列中的请求进行重试
|
|
|
+ // requests.forEach((item) => item(reshRespore.data
|
|
|
+ // .accessToken))
|
|
|
+ // // requests = []
|
|
|
+ // // // 每个接口请求都要存入队列,等刷新完以后都需要执行
|
|
|
+ // // return new Promise((resolve) => {
|
|
|
+ // // // 将resolve放进队列,用一个函数形式来保存,等token刷新后直接执行
|
|
|
+ // // requests.push((token) => {
|
|
|
+ // // //这一步一定要有,刷新token,因为存入的信息是旧的token
|
|
|
+ // // response.config.header[
|
|
|
+ // // 'Authorization'] =
|
|
|
+ // // 'Bearer ' + token;
|
|
|
+ // // resolve(uni.$u.http.request(response
|
|
|
+ // // .config)) //执行请求
|
|
|
|
|
|
- // })
|
|
|
- // that.$forceUpdate()
|
|
|
- // })
|
|
|
- requests = []
|
|
|
- // 刷新完token后重新调用上一次的接口
|
|
|
- resolve(uni.$u.http.request(config)) // 执行请求
|
|
|
- if (reshRespore.code == 400) {
|
|
|
- showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
|
|
|
- if (res.confirm) {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/login'
|
|
|
- })
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
+ // // })
|
|
|
+ // // that.$forceUpdate()
|
|
|
+ // // })
|
|
|
+ // requests = []
|
|
|
+ // // 刷新完token后重新调用上一次的接口
|
|
|
+ // resolve(uni.$u.http.request(config)) // 执行请求
|
|
|
+ // if (reshRespore.code == 400) {
|
|
|
+ // showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
|
|
|
+ // if (res.confirm) {
|
|
|
+ // uni.navigateTo({
|
|
|
+ // url: '/pages/login'
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // })
|
|
|
|
|
|
- } catch {
|
|
|
+ // } catch {
|
|
|
// uni.$u.toast('未知错误')
|
|
|
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
|
|
|
if (res.confirm) {
|
|
@@ -111,17 +111,17 @@ const request = config => {
|
|
|
})
|
|
|
}
|
|
|
});
|
|
|
- } finally {
|
|
|
- // 请求成功,开启刷新标识
|
|
|
- isRefreshing = false
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 添加到请求队列中
|
|
|
- requests.push(token => {
|
|
|
- config.header['Authorization'] = 'Bearer ' + token;
|
|
|
- resolve(uni.$u.http.request(config)) // 执行请求
|
|
|
- })
|
|
|
- }
|
|
|
+ // } finally {
|
|
|
+ // // 请求成功,开启刷新标识
|
|
|
+ // isRefreshing = false
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // // 添加到请求队列中
|
|
|
+ // requests.push(token => {
|
|
|
+ // config.header['Authorization'] = 'Bearer ' + token;
|
|
|
+ // resolve(uni.$u.http.request(config)) // 执行请求
|
|
|
+ // })
|
|
|
+ // }
|
|
|
} else if (code === 500) {
|
|
|
toast(msg)
|
|
|
reject('500')
|