| | |
| | | import { decryptedData } from '@/utils/decryption.js' |
| | | const install = (Vue, vm) => { |
| | | // 是否正在刷新的标记 |
| | | let isRefreshing = false |
| | |
| | | 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 = [] |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | return new Promise((resolve) => { |
| | | // 将resolve放进队列,用一个函数形式来保存,等token刷新后直接执行 |
| | | requests.push(token => { |
| | | response.config.header['eva-auth-token'] = token |
| | | resolve(uni.$u.http.request(response.config)); |
| | | }) |
| | | if (response.data.code === 5112) { |
| | | uni.showToast({ |
| | | title: '登录过期,正在重新跳转授权', |
| | | icon: 'none', |
| | | 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 |
| | | } |
| | | if (response.data.code !== 200) { |
| | | uni.showToast({ |
| | |
| | | duration: 2000 |
| | | }); |
| | | } |
| | | if (response.data.message) { |
| | | const tm = response.data.message |
| | | const list = tm.split(' ') |
| | | let msg = list[0] |
| | | if (list.length > 1 && response.data.data) { |
| | | msg = decryptedData(list[1], list[0]) |
| | | response.data.data = decryptedData(list[1], response.data.data) |
| | | console.log(response.data.data) |
| | | response.data.message = msg |
| | | } |
| | | } |
| | | return response.data; |
| | | }, (response) => { |
| | | return Promise.reject(response) |