Преглед на файлове

feat: 登陆失效登陆处理流程优化

xiansin преди 2 години
родител
ревизия
336f85fb47
променени са 3 файла, в които са добавени 15 реда и са изтрити 4 реда
  1. 3 0
      mini/api/user/index.js
  2. 6 1
      mini/pages/episode/play.vue
  3. 6 3
      mini/utils/request/responseInterceptors.js

+ 3 - 0
mini/api/user/index.js

xqd xqd
@@ -11,6 +11,7 @@ import recharge from './recharge'
 import collect from './collect'
 import favorite from './favorite'
 import vip from './vip'
+import Cache from "../../utils/cache";
 
 export async function login() {
   return new Promise((resolve, reject) => {
@@ -37,8 +38,10 @@ export async function login() {
           url,
           { code: loginRes.code, anonymousCode: loginRes.anonymousCode }
         ).then(res => {
+          Cache.set('isLogin', 0)
           resolve(res)
         }).catch(err => {
+          Cache.set('isLogin', 0)
           reject(err)
         })
       },

+ 6 - 1
mini/pages/episode/play.vue

xqd
@@ -407,7 +407,12 @@ export default {
           position: fixed;
           top: 0;
           left: 0;
-          bottom: 0;
+          // #ifdef  MP-KUAISHOU | MP-WEIXIN
+          bottom: 240rpx;
+          // #endif
+          // #ifdef  MP-TOUTIAO
+          bottom: 360rpx;
+          // #endif
           right: 0;
           background: transparent;
           z-index: 999;

+ 6 - 3
mini/utils/request/responseInterceptors.js

xqd xqd 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 => {
@@ -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({
@@ -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'
             })