| | |
| | | uni.$u.http.interceptors.response.use((response) => { |
| | | uni.hideLoading(); |
| | | // 登录过期 |
| | | if (response.data.code === 401) { |
| | | if (!isRefreshing) { // 是否已经执行刷新 |
| | | isRefreshing = true |
| | | uni.login({ |
| | | provider: 'weixin', |
| | | success: async function (loginRes) { |
| | | let { code } = loginRes; |
| | | uni.request({ |
| | | url: vm.$baseUrl + 'mobile/system/login', |
| | | method: "GET", |
| | | data: { code }, |
| | | success: (res) => { |
| | | isRefreshing = false |
| | | vm.$store.commit('setToken', res.data.data) |
| | | // 已经刷新了token,将所有队列中的请求进行重试 |
| | | requests.forEach(item => item(res.data.data)) |
| | | requests = [] |
| | | if (response.data.code === 5112) { |
| | | uni.showToast({ |
| | | title: '登录过期,正在重新跳转授权', |
| | | duration: 2000, |
| | | success() { |
| | | setTimeout(() => { |
| | | let loc_href = encodeURIComponent("https://dmtest.ahapp.net/lianhelihua_web/") |
| | | let corpId = 'wweea8f71b54e3b835'; |
| | | let agentId = '1000095'; |
| | | let wxUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${corpId}&redirect_uri=${loc_href}&response_type=code&scope=snsapi_base&state=#wechat_redirect` |
| | | location.href = wxUrl; |
| | | }, 1500) |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | return new Promise((resolve) => { |
| | | // 将resolve放进队列,用一个函数形式来保存,等token刷新后直接执行 |
| | | requests.push(token => { |
| | | response.config.header['eva-auth-token'] = token |
| | | resolve(uni.$u.http.request(response.config)); |
| | | }) |
| | | }) |
| | | return |
| | | } |
| | | if (response.data.code !== 200) { |
| | | uni.showToast({ |