zaijin 1 year ago
parent
commit
9d73d674bd
3 changed files with 41 additions and 35 deletions
  1. 2 2
      App.vue
  2. 37 32
      common/http.interceptor.js
  3. 2 1
      pages/index/index.vue

+ 2 - 2
App.vue

@@ -34,7 +34,7 @@ export default {
     }
     // 获取参数
     const paramsValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1);
-    if (paramsValidPage.length === 0) {
+    if (paramsValidPage.length === 0 || this.vuex_token) {
       this.getFreeTime();
     }
   },
@@ -85,7 +85,7 @@ export default {
         const { msg } = await this.$u.api.getParamsApi({ key: 'park.lock.freetime' });
         this.$u.vuex('free_time', msg);
       } catch (error) {
-        console.log(error);
+        // console.log(error);
       }
     },
     /**

+ 37 - 32
common/http.interceptor.js

@@ -7,6 +7,7 @@ const install = (Vue, vm) => {
     originalData: true,
     dataType: 'text'
   });
+
   // 请求拦截,配置Token等参数
   Vue.prototype.$u.http.interceptor.request = (config) => {
     if (vm.vuex_token) {
@@ -26,44 +27,15 @@ const install = (Vue, vm) => {
     return config;
   };
   // 响应拦截,判断状态码是否通过
-  Vue.prototype.$u.http.interceptor.response = (res) => {
+  Vue.prototype.$u.http.interceptor.response = res => {
     // 解决出现数据精度缺失问题
     const jsonBigint = require('json-bigint')({ storeAsString: true });
     res = jsonBigint.parse(res.data);
     if (res.code == 200) {
       return res;
     } else if (res.code == 401 || (res.code == 400 && res.msg == '令牌不能为空')) {
-      const backUrl = location.href,
-        openidPage = vm.config.onlyWxLogin, // 只需要传openid的页面集合
-        needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
-      // 判断浏览器
-      const ua = window.navigator.userAgent.toLowerCase();
-      // 微信中打开
-      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
-        // 防止重复跳转
-        if (backUrl.indexOf('backUrl') === -1) {
-          vm.$u.route('pages/wechatLogin/wechatLogin', { backUrl: encodeURIComponent(backUrl), loginType: needValidPage.length ? 2 : 1 });
-        }
-      } else {
-        // 普通浏览器中打开
-        if (backUrl.indexOf('backUrl') === -1) {
-          localStorage.setItem('backUrl', encodeURIComponent(backUrl));
-        }
-        uni.showModal({
-          title: '提示',
-          content: '未查询到登录信息或信息已失效, 请重新登录',
-          showCancel: false,
-          success: function (res) {
-            if (res.confirm) {
-              localStorage.removeItem('lifeData');
-              uni.redirectTo({
-                url: '/pages/center/phoneLogin/phoneLogin'
-              });
-            }
-          }
-        });
-      }
-      return false;
+      login(vm);
+      return false
     } else {
       // 用来判断时候需要使用当前提示框
       const noTipMsg = ['无任何订单'];
@@ -80,6 +52,39 @@ const install = (Vue, vm) => {
   };
 };
 
+const login = (vm) => {
+  const backUrl = location.href,
+    openidPage = vm.config.onlyWxLogin, // 只需要传openid的页面集合
+    needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
+  // 判断浏览器
+  const ua = window.navigator.userAgent.toLowerCase();
+  // 微信中打开
+  if (ua.match(/MicroMessenger/i) == 'micromessenger') {
+    // 防止重复跳转
+    if (backUrl.indexOf('backUrl') === -1) {
+      vm.$u.route('pages/wechatLogin/wechatLogin', { backUrl: encodeURIComponent(backUrl), loginType: needValidPage.length ? 2 : 1 });
+    }
+  } else {
+    // 普通浏览器中打开
+    if (backUrl.indexOf('backUrl') === -1) {
+      localStorage.setItem('backUrl', encodeURIComponent(backUrl));
+    }
+    uni.showModal({
+      title: '提示',
+      content: '未查询到登录信息或信息已失效, 请重新登录',
+      showCancel: false,
+      success: function (res) {
+        if (res.confirm) {
+          localStorage.removeItem('lifeData');
+          uni.redirectTo({
+            url: '/pages/center/phoneLogin/phoneLogin'
+          });
+        }
+      }
+    });
+  }
+};
+
 export default {
   install
 };

+ 2 - 1
pages/index/index.vue

@@ -382,7 +382,8 @@ export default {
         this.jumpMsgModal = false;
       }, 3000);
     }
-    this.getParams();
+
+    // this.getParams();
     this.getLocation();
     this.handleGetIndexData();
   },