| | |
| | | const install = (Vue, vm) => { |
| | | // 请求拦截器 |
| | | uni.$u.http.interceptors.request.use((config) => { |
| | | const Headtoken = vm.$store.state.token |
| | | uni.showLoading({ title: '加载中' }); |
| | | let Headtoken = vm.$store.state.token || '' |
| | | let shopHeadtoken= vm.$store.state.shopToken || '' |
| | | // 判断有无token,有则加入请求头中 |
| | | if (Headtoken) { |
| | | config.header['token'] = Headtoken; |
| | | } |
| | | if (shopHeadtoken) { |
| | | config.header['shopToken'] = shopHeadtoken; |
| | | } |
| | | return config; |
| | | }, config => { |
| | |
| | | // 响应拦截器 |
| | | uni.$u.http.interceptors.response.use((response) => { |
| | | uni.hideLoading(); |
| | | if (response.data.code === 5113) { |
| | | if (response.data.code === 5113 || response.data.code === 5112) { |
| | | uni.clearStorageSync("userInfo") |
| | | uni.clearStorageSync("token") |
| | | uni.switchTab({ |
| | | url: '/pages/index/index' |
| | | }); |
| | | return |
| | | } |
| | | if (response.data.code === 51131|| response.data.code === 51121) { |
| | | uni.clearStorageSync("shopInfo") |
| | | uni.clearStorageSync("shopToken") |
| | | uni.navigateTo({ |
| | | url: '/shop/pages/login/login' |
| | | }); |
| | | return |
| | | } |
| | | if (response.data.code !== 200) { |
| | | uni.showToast({ |
| | | title: response.data.message, |