| | |
| | | uni.$u.http.interceptors.response.use((response) => { |
| | | uni.hideLoading(); |
| | | // 登录过期 |
| | | if (response.data.code === 401) { |
| | | if (response.data.code === 401 && vm.$store.state.cookies) { |
| | | if (!isRefreshing) { // 是否已经执行刷新 |
| | | isRefreshing = true |
| | | uni.login({ |
| | |
| | | isRefreshing = false |
| | | if (res.data.data) { |
| | | vm.$store.commit('setCookies', res.data.data) |
| | | vm.$u.api.getUserInfo() |
| | | .then(user => { |
| | | vm.$store.commit('setUserInfo', user.data) |
| | | }) |
| | | // 已经刷新了token,将所有队列中的请求进行重试 |
| | | requests.forEach(item => item(res.data.data)) |
| | | requests = [] |
| | |
| | | resolve(uni.$u.http.request(response.config)); |
| | | }) |
| | | }) |
| | | } else if (response.data.code === 401 && !vm.$store.state.cookies) { |
| | | uni.navigateTo({ |
| | | url: '/pages/login/login' |
| | | }) |
| | | } |
| | | if (response.data.code !== 200) { |
| | | uni.showToast({ |