Browse Source

登录逻辑调整

zaijin 2 years ago
parent
commit
1fca9f763e
3 changed files with 24 additions and 16 deletions
  1. 21 14
      App.vue
  2. 2 1
      common/config.js
  3. 1 1
      common/http.interceptor.js

+ 21 - 14
App.vue

@@ -22,26 +22,21 @@ export default {
       });
       });
       console.log('其他浏览器');
       console.log('其他浏览器');
     }
     }
-    // 获取参数免费时长
-    this.$u.api
-      .getParamsApi({
-        key: 'park.lock.freetime'
-      })
-      .then((res) => {
-        if (res.code === 200) {
-          this.$u.vuex('free_time', res.msg);
-        }
-      });
-  },
-  onShow: function () {
-    // console.log('App Show')
+    // 判断从什么入口进入 车位锁等页面无需调用
     const backUrl = location.href,
     const backUrl = location.href,
-      openidPage = ['/pages/parkingLock/parkingLock'], // 只需要穿openid的页面集合
+      openidPage = this.config.onlyWxLogin, // 只需要穿openid的页面集合
       needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
       needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
     const { openId } = this.vuex_wxinfo;
     const { openId } = this.vuex_wxinfo;
+    console.log('openId', openId);
+    console.log('needValidPage', needValidPage);
     if (openId && needValidPage.length === 0) {
     if (openId && needValidPage.length === 0) {
       this.getUserInfo(openId);
       this.getUserInfo(openId);
     }
     }
+    // 获取参数
+    this.getFreeTime();
+  },
+  onShow: function () {
+    console.log('App Show');
   },
   },
   onHide: function () {
   onHide: function () {
     // console.log('App Hide')
     // console.log('App Hide')
@@ -77,6 +72,18 @@ export default {
           type: 'error'
           type: 'error'
         });
         });
       }
       }
+    },
+    /**
+     * @description: 获取参数免费时长
+     * @return {*}
+     */
+    async getFreeTime() {
+      try {
+        const { msg } = await this.$u.api.getParamsApi({ key: 'park.lock.freetime' });
+        this.$u.vuex('free_time', msg);
+      } catch (error) {
+        console.log(error);
+      }
     }
     }
   }
   }
 };
 };

+ 2 - 1
common/config.js

@@ -12,5 +12,6 @@ if (node_dev) {
 }
 }
 export const config = {
 export const config = {
   wxAppid,
   wxAppid,
-  baseUrl
+  baseUrl,
+  onlyWxLogin: ['pages/parkingLock/parkingLock', 'pages/wechatLogin/wechatLogin'] // 只需要微信登录的页面路径
 };
 };

+ 1 - 1
common/http.interceptor.js

@@ -20,7 +20,7 @@ const install = (Vue, vm) => {
       return res;
       return res;
     } else if (res.code == 401 || res.code == 400) {
     } else if (res.code == 401 || res.code == 400) {
       const backUrl = location.href,
       const backUrl = location.href,
-        openidPage = ['/pages/parkingLock/parkingLock'], // 只需要穿openid的页面集合
+        openidPage = vm.config.onlyWxLogin, // 只需要传openid的页面集合
         needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
         needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
       // 判断浏览器
       // 判断浏览器
       const ua = window.navigator.userAgent.toLowerCase();
       const ua = window.navigator.userAgent.toLowerCase();