| xqd
@@ -2,6 +2,8 @@
|
|
|
* 响应拦截
|
|
|
* @param {Object} http
|
|
|
*/
|
|
|
+import Cache from '../cache'
|
|
|
+import { removeToken, setToken } from '../auth'
|
|
|
module.exports = vm => {
|
|
|
uni.$u.http.interceptors.response.use(
|
|
|
response => {
|
| xqd
@@ -9,7 +11,7 @@ module.exports = vm => {
|
|
|
// 刷新token
|
|
|
const authorization = response.headers?.authorization
|
|
|
if (authorization) {
|
|
|
- vm.$store.dispatch('user/token', authorization)
|
|
|
+ setToken(authorization)
|
|
|
}
|
|
|
if (data.code !== 0) {
|
|
|
uni.showModal({
|
| xqd
@@ -25,8 +27,9 @@ module.exports = vm => {
|
|
|
// 401 登录超时 402 需要登录
|
|
|
if (typeof error.data.status_code !== 'undefined') {
|
|
|
if (error.data.status_code === 401 || error.data.status_code === 402) {
|
|
|
- if (!getApp().globalData.isLogin) {
|
|
|
- getApp().globalData.isLogin = true
|
|
|
+ if (!Cache.get('isLogin')) {
|
|
|
+ removeToken(null)
|
|
|
+ Cache.set('isLogin', 1)
|
|
|
uni.reLaunch({
|
|
|
url: '/pages/login'
|
|
|
})
|