Browse Source

feat: 添加页面劫持

linwenxin 1 year ago
parent
commit
98cd951a19

+ 94 - 82
package-lock.json

@@ -3054,44 +3054,6 @@
           "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
           "dev": true
         },
-        "ansi-styles": {
-          "version": "4.3.0",
-          "resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz",
-          "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
-          "dev": true,
-          "optional": true,
-          "requires": {
-            "color-convert": "^2.0.1"
-          }
-        },
-        "chalk": {
-          "version": "4.1.2",
-          "resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz",
-          "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
-          "dev": true,
-          "optional": true,
-          "requires": {
-            "ansi-styles": "^4.1.0",
-            "supports-color": "^7.1.0"
-          }
-        },
-        "color-convert": {
-          "version": "2.0.1",
-          "resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz",
-          "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
-          "dev": true,
-          "optional": true,
-          "requires": {
-            "color-name": "~1.1.4"
-          }
-        },
-        "color-name": {
-          "version": "1.1.4",
-          "resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz",
-          "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
-          "dev": true,
-          "optional": true
-        },
         "css-loader": {
           "version": "3.6.0",
           "resolved": "https://registry.npmmirror.com/css-loader/-/css-loader-3.6.0.tgz",
@@ -3149,13 +3111,6 @@
             "pump": "^3.0.0"
           }
         },
-        "has-flag": {
-          "version": "4.0.0",
-          "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz",
-          "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
-          "dev": true,
-          "optional": true
-        },
         "hash-sum": {
           "version": "2.0.0",
           "resolved": "https://registry.npmmirror.com/hash-sum/-/hash-sum-2.0.0.tgz",
@@ -3258,42 +3213,6 @@
           "requires": {
             "minipass": "^3.1.1"
           }
-        },
-        "supports-color": {
-          "version": "7.2.0",
-          "resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz",
-          "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
-          "dev": true,
-          "optional": true,
-          "requires": {
-            "has-flag": "^4.0.0"
-          }
-        },
-        "vue-loader-v16": {
-          "version": "npm:vue-loader@16.8.3",
-          "resolved": "https://registry.npmmirror.com/vue-loader/-/vue-loader-16.8.3.tgz",
-          "integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
-          "dev": true,
-          "optional": true,
-          "requires": {
-            "chalk": "^4.1.0",
-            "hash-sum": "^2.0.0",
-            "loader-utils": "^2.0.0"
-          },
-          "dependencies": {
-            "loader-utils": {
-              "version": "2.0.4",
-              "resolved": "https://registry.npmmirror.com/loader-utils/-/loader-utils-2.0.4.tgz",
-              "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
-              "dev": true,
-              "optional": true,
-              "requires": {
-                "big.js": "^5.2.2",
-                "emojis-list": "^3.0.0",
-                "json5": "^2.1.2"
-              }
-            }
-          }
         }
       }
     },
@@ -10514,6 +10433,11 @@
       "integrity": "sha512-efJLHhLjIyKRewNS9EGZ4UpI8NguuL6fKkhRxVuMmrGV2xN/0APGdQYwLFky5w9naebSZ0OwAGp0G6/2Cg90rA==",
       "dev": true
     },
+    "js-perform-lock": {
+      "version": "1.0.5",
+      "resolved": "http://121.41.110.30:4873/js-perform-lock/-/js-perform-lock-1.0.5.tgz",
+      "integrity": "sha512-aDp38fxLnur2YMsJhw1Ab23PdwceXMU5Pkcb4R5MSaRfySiDwbDR2L/ysnB4X7/1XERkLC56r32qwtNlitBSGg=="
+    },
     "js-tokens": {
       "version": "4.0.0",
       "resolved": "https://registry.npmmirror.com/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -16235,6 +16159,94 @@
         "vue-style-loader": "^4.1.0"
       }
     },
+    "vue-loader-v16": {
+      "version": "npm:vue-loader@16.8.3",
+      "resolved": "http://121.41.110.30:4873/vue-loader/-/vue-loader-16.8.3.tgz",
+      "integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
+      "dev": true,
+      "optional": true,
+      "requires": {
+        "chalk": "^4.1.0",
+        "hash-sum": "^2.0.0",
+        "loader-utils": "^2.0.0"
+      },
+      "dependencies": {
+        "ansi-styles": {
+          "version": "4.3.0",
+          "resolved": "http://121.41.110.30:4873/ansi-styles/-/ansi-styles-4.3.0.tgz",
+          "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
+          "dev": true,
+          "optional": true,
+          "requires": {
+            "color-convert": "^2.0.1"
+          }
+        },
+        "chalk": {
+          "version": "4.1.2",
+          "resolved": "http://121.41.110.30:4873/chalk/-/chalk-4.1.2.tgz",
+          "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
+          "dev": true,
+          "optional": true,
+          "requires": {
+            "ansi-styles": "^4.1.0",
+            "supports-color": "^7.1.0"
+          }
+        },
+        "color-convert": {
+          "version": "2.0.1",
+          "resolved": "http://121.41.110.30:4873/color-convert/-/color-convert-2.0.1.tgz",
+          "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
+          "dev": true,
+          "optional": true,
+          "requires": {
+            "color-name": "~1.1.4"
+          }
+        },
+        "color-name": {
+          "version": "1.1.4",
+          "resolved": "http://121.41.110.30:4873/color-name/-/color-name-1.1.4.tgz",
+          "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
+          "dev": true,
+          "optional": true
+        },
+        "has-flag": {
+          "version": "4.0.0",
+          "resolved": "http://121.41.110.30:4873/has-flag/-/has-flag-4.0.0.tgz",
+          "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
+          "dev": true,
+          "optional": true
+        },
+        "hash-sum": {
+          "version": "2.0.0",
+          "resolved": "http://121.41.110.30:4873/hash-sum/-/hash-sum-2.0.0.tgz",
+          "integrity": "sha512-WdZTbAByD+pHfl/g9QSsBIIwy8IT+EsPiKDs0KNX+zSHhdDLFKdZu0BQHljvO+0QI/BasbMSUa8wYNCZTvhslg==",
+          "dev": true,
+          "optional": true
+        },
+        "loader-utils": {
+          "version": "2.0.4",
+          "resolved": "http://121.41.110.30:4873/loader-utils/-/loader-utils-2.0.4.tgz",
+          "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
+          "dev": true,
+          "optional": true,
+          "requires": {
+            "big.js": "^5.2.2",
+            "emojis-list": "^3.0.0",
+            "json5": "^2.1.2"
+          }
+        },
+        "supports-color": {
+          "version": "7.2.0",
+          "resolved": "http://121.41.110.30:4873/supports-color/-/supports-color-7.2.0.tgz",
+          "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
+          "dev": true,
+          "optional": true,
+          "requires": {
+            "has-flag": "^4.0.0"
+          }
+        }
+      }
+    },
     "vue-pdf": {
       "version": "4.3.0",
       "resolved": "https://registry.npmmirror.com/vue-pdf/-/vue-pdf-4.3.0.tgz",
@@ -16939,7 +16951,7 @@
     },
     "weixin-js-sdk": {
       "version": "1.6.3",
-      "resolved": "https://registry.npmmirror.com/weixin-js-sdk/-/weixin-js-sdk-1.6.3.tgz",
+      "resolved": "http://121.41.110.30:4873/weixin-js-sdk/-/weixin-js-sdk-1.6.3.tgz",
       "integrity": "sha512-5jYNtVcxWmgHNqCLSPoX6vXab9G4RPDZx0klX8IsVwGjDTwx/UDmgfF7fkRMGguRpuFv0O7tk1jb+Oay2QiV1w=="
     },
     "whatwg-encoding": {

+ 1 - 0
package.json

@@ -102,6 +102,7 @@
     "core-js": "^3.6.5",
     "flyio": "^0.6.2",
     "js-base64": "^3.7.2",
+    "js-perform-lock": "^1.0.5",
     "jweixin-module": "^1.6.0",
     "regenerator-runtime": "^0.12.1",
     "uni-read-pages": "^1.0.5",

+ 5 - 8
src/App.vue

@@ -23,20 +23,19 @@
       }
       var token = getQueryVariable("x-token")
       if (token) {
-        this.$store.commit("set_token", token)
+        this.$store.commit("user/set_token", token)
       }
       // #endif
 
       // #ifdef MP-WEIXIN
-      console.log(123)
       // 小程序更新
       const updateManager = uni.getUpdateManager();
       // 请求完新版本信息
-      updateManager.onCheckForUpdate(function(res) {
+      updateManager.onCheckForUpdate((res) => {
         // console.log(res.hasUpdate);
       });
       // 新的版本已经下载好
-      updateManager.onUpdateReady(function(res) {
+      updateManager.onUpdateReady((res) => {
         uni.showModal({
           title: '更新提示',
           content: '新版本已经准备好,是否重启应用?',
@@ -49,9 +48,7 @@
         });
       });
       // 新的版本下载失败
-      updateManager.onUpdateFailed(function(res) {
-        that.$toast('更新失败!');
-      });
+      updateManager.onUpdateFailed((res) => {});
 
       uni.$on('updateUserInfo', () => {
         this.updateUserInfo();
@@ -142,4 +139,4 @@
   @import "uview-ui/index.scss";
 
   @import "styles/iconfont.css";
-</style>
+</style>

+ 2 - 2
src/common/utils/navPag.js

@@ -63,8 +63,8 @@ export const navToPage = (function() {
 
 export function webViewHref(url) {
   if (!!~url.indexOf("?")) {
-    return process.env.VUE_APP_HREF + url + "&x-token=123" + store.getters.token
+    return process.env.VUE_APP_HREF + url + "&x-token=" + store.getters.token
   } else {
-    return process.env.VUE_APP_HREF + url + "?x-token=123" + store.getters.token
+    return process.env.VUE_APP_HREF + url + "?x-token=" + store.getters.token
   }
 }

+ 63 - 17
src/mixins/index.js

@@ -2,12 +2,65 @@ import {
   isWeixin
 } from '@/common/utils/common';
 import {
-  webViewHref
+  webViewHref,
+  navToPage
 } from '@/common/utils/navPag';
+import {
+  firstPerform
+} from "js-perform-lock";
+import store from '@/store/index.js'
+
 // #ifdef H5
 import wx from 'weixin-js-sdk'
 // #endif
 
+// #ifdef MP-WEIXIN
+// 微信小程序页面劫持
+var goLoginPage = (new firstPerform(1000)).refactor(function() {
+  navToPage({
+    url: "/pages/login/indexs"
+  }, "redirectTo")
+});
+var routerBeforeEach = (new firstPerform(200)).refactor(function() {
+  function getrouter() {
+    let routes = getCurrentPages();
+    if (routes.length) {
+      let curRoute = routes[routes.length - 1].route
+      let whitePages = [
+        'pages/login/index',
+        'pages/login/indexs',
+        'pages/index/index',
+      ]
+      if (!store.getters.token && whitePages.indexOf(curRoute) == -1) {
+        goLoginPage()
+      }
+    } else {
+      setTimeout(getrouter, 300)
+    }
+  }
+  getrouter()
+});
+// #endif
+
+var updatePageLay = (new firstPerform(1000)).refactor(function() {
+  // 去除顶部
+  var uni_page_head = document.querySelector("uni-page-head[uni-page-head-type='default']")
+  if (uni_page_head) {
+    uni_page_head.remove()
+  }
+  // 去除底部
+  var uni_tabbar_bottom = document.getElementsByClassName("uni-tabbar-bottom")
+  if (uni_tabbar_bottom.length) {
+    uni_tabbar_bottom[0].remove()
+    var uni_page_wrapper = document.getElementsByTagName("uni-page-wrapper")
+    if (uni_page_wrapper.length) {
+      loadStyleString(
+        "uni-page-wrapper{height: calc(100% - env(safe-area-inset-bottom)) !important} uni-page-wrapper::after{height: env(safe-area-inset-bottom) !important}"
+      );
+    }
+  }
+});
+
 // 插入样式
 function loadStyleString(css) {
   var style = document.createElement("style");
@@ -23,24 +76,17 @@ function loadStyleString(css) {
 
 // 存放页面公用数据、方法...
 export default {
+  onShow() {
+    // #ifdef MP-WEIXIN
+    routerBeforeEach()
+    // #endif
+  },
   mounted() {
+    // #ifdef MP-WEIXIN
+    routerBeforeEach()
+    // #endif
     if (isWeixin()) {
-      // 去除顶部
-      var uni_page_head = document.querySelector("uni-page-head[uni-page-head-type='default']")
-      if (uni_page_head) {
-        uni_page_head.remove()
-      }
-      // 去除底部
-      var uni_tabbar_bottom = document.getElementsByClassName("uni-tabbar-bottom")
-      if (uni_tabbar_bottom.length) {
-        uni_tabbar_bottom[0].remove()
-        var uni_page_wrapper = document.getElementsByTagName("uni-page-wrapper")
-        if (uni_page_wrapper.length) {
-          loadStyleString(
-            "uni-page-wrapper{height: calc(100% - env(safe-area-inset-bottom)) !important} uni-page-wrapper::after{height: env(safe-area-inset-bottom) !important}"
-          );
-        }
-      }
+      updatePageLay()
     }
   },
   methods: {

+ 44 - 40
src/pages.json

@@ -1,12 +1,11 @@
 {
-  "pages": [
-    {
+  "pages": [{
       "path": "pages/index/index",
       "style": {
         "navigationBarTitleText": "二手空调",
-        // "navigationStyle": "custom",
-        "navigationBarTextStyle":"#fff",
-        "navigationBarBackgroundColor":"#01C30B"
+        // "navigationStyle": "custom",
+        "navigationBarTextStyle": "#fff",
+        "navigationBarBackgroundColor": "#01C30B"
       }
     },
 
@@ -18,14 +17,14 @@
     },
     {
       "path": "pages/message/index",
-      "style": {
+      "style": {
         "disableScroll": true,
         "navigationBarTitleText": "消息"
       }
     },
     {
       "path": "pages/message/msgView",
-      "style": {
+      "style": {
         "disableScroll": true,
         "navigationBarTitleText": "消息"
       }
@@ -134,10 +133,15 @@
       }
     },
     {
+      "path": "pages/login/index",
+      "style": {
+        "navigationBarTitleText": ""
+      }
+    },
+    {
       "path": "pages/login/indexs",
       "style": {
-        "navigationBarTitleText": "登录",
-        "navigationStyle": "custom"
+        "navigationBarTitleText": "登录"
       }
     }
   ],
@@ -161,35 +165,35 @@
     "backgroundColor": "#f4f2f2",
     "onReachBottomDistance": 100
   },
-  "tabBar": {
-    "color": "#515151",
-    "selectedColor": "#01C30B",
-    "borderStyle": "black",
-    "backgroundColor": "#ffffff",
-    "list": [{
-        "pagePath": "pages/index/index",
-        "iconPath": "static/tabBar/icon_home01.png",
-        "selectedIconPath": "static/tabBar/icon_home02.png",
-        "text": "首页"
-      },
-      {
-        "pagePath": "pages/issue/index",
-        "iconPath": "static/tabBar/icon_issue01.png",
-        "selectedIconPath": "static/tabBar/icon_issue02.png",
-        "text": "发布"
-      },
-      {
-        "pagePath": "pages/message/index",
-        "iconPath": "static/tabBar/icon_message01.png",
-        "selectedIconPath": "static/tabBar/icon_message02.png",
-        "text": "消息"
-      },
-      {
-        "pagePath": "pages/mine/index",
-        "iconPath": "static/tabBar/icon_mine01.png",
-        "selectedIconPath": "static/tabBar/icon_mine02.png",
-        "text": "我的"
-      }
-    ]
+  "tabBar": {
+    "color": "#515151",
+    "selectedColor": "#01C30B",
+    "borderStyle": "black",
+    "backgroundColor": "#ffffff",
+    "list": [{
+        "pagePath": "pages/index/index",
+        "iconPath": "static/tabBar/icon_home01.png",
+        "selectedIconPath": "static/tabBar/icon_home02.png",
+        "text": "首页"
+      },
+      {
+        "pagePath": "pages/issue/index",
+        "iconPath": "static/tabBar/icon_issue01.png",
+        "selectedIconPath": "static/tabBar/icon_issue02.png",
+        "text": "发布"
+      },
+      {
+        "pagePath": "pages/message/index",
+        "iconPath": "static/tabBar/icon_message01.png",
+        "selectedIconPath": "static/tabBar/icon_message02.png",
+        "text": "消息"
+      },
+      {
+        "pagePath": "pages/mine/index",
+        "iconPath": "static/tabBar/icon_mine01.png",
+        "selectedIconPath": "static/tabBar/icon_mine02.png",
+        "text": "我的"
+      }
+    ]
   }
-}
+}

+ 5 - 55
src/pages/login/index.vue

@@ -11,66 +11,16 @@
 
       }
     },
-
     async onLoad(options) {
-      // let token = window.location.search.split("=")[1]
-      let href = window.location.href;
-      let token = this.getUrlParam(href, 'token');
-      let type = this.getUrlParam(href, 'type');
-      if (!token) {
-        uni.navigateTo({
-          url: '/pages/login/indexs'
-        })
-        return
-      }
-      let params = {
-        token: token,
-        loginflag: type || ''
-        // token: '00d721ced91aa4340fc818bb817db7b7'
-      }
-      console.log(params);
-      try {
-        console.log(params);
-        await this.$store.dispatch('user/autoLogin', params)
-        // await this.$store.dispatch('user/login', params)
-        await this.$store.dispatch('user/getInfo')
-        await this.$Prompt.toast({
-          title: '登陆成功',
-          icon: 'success'
-        })
-        this.$Router.push({
-          name: 'learn'
-        })
-      } catch (e) {
-        this.$Prompt.toast({
-          title: '登陆失败',
-          icon: 'error'
-        })
-
-      }
+      this.$navToPage({
+        url: '/pages/login/indexs'
+      }, "redirectTo")
     },
-
     methods: {
-      getUrlParam(url,name){
-          var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
-          var matcher = pattern.exec(url);
-          var items = null;
-          if(matcher != null){
-              try{
-                  items = decodeURIComponent(decodeURIComponent(matcher[1]));
-              }catch(e){
-                  try{
-                      items = decodeURIComponent(matcher[1]);
-                  }catch(e){
-                      items = matcher[1];
-                  }
-              }
-          }
-          return items;
-      }
+
     }
   }
 </script>
 
 <style>
-</style>
+</style>

+ 8 - 6
src/pages/login/indexs.vue

@@ -107,11 +107,13 @@
               code: loginRes.code,
               phoneCode: e.detail.code,
             }).then(res => {
-              this.$store.commit("set_token", res.data.token)
-              this.$store.commit("set_openId", res.data.openId)
-              this.$store.commit("set_name", res.data.name)
-              this.$store.commit("set_avatar", res.data.avatar)
-              this.$navToPage("/pages/index/index")
+              this.$store.commit("user/set_token", res.data.token)
+              this.$store.commit("user/set_openId", res.data.openId)
+              this.$store.commit("user/set_name", res.data.name)
+              this.$store.commit("user/set_avatar", res.data.avatar)
+              this.$navToPage({
+                url: "/pages/index/index"
+              }, "switchTab")
             })
           }
         });
@@ -215,4 +217,4 @@
     background: linear-gradient(135deg, #7fdaff 0%, #6da7ff 100%);
     border-radius: 50rpx;
   }
-</style>
+</style>

+ 31 - 31
src/router/index.js

@@ -9,8 +9,9 @@ import {
   getQueryVariable
 } from '@/common/utils/common';
 
-function goJianquan(url){
-  const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaddd13c267e81e70&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
+function goJianquan(url) {
+  const href =
+    `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaddd13c267e81e70&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
   window.location.href = href;
 }
 
@@ -43,40 +44,39 @@ router.beforeEach((to, from, next) => {
     '/pages/login/index',
     '/pages/login/indexs',
     '/pages/index/index',
-    '/pages/mine/index',
   ]
 
-  next();
-  // if (whitePages.indexOf(to.path) >= 0) {
-  //   next();
-  // }else{
-  //   if(isWeixin()){
-  //     if (store.getters.token) {
-  //       next();
-  //     }else{
-  //       var code = getQueryVariable('code');
-  //       if (code) {
-  //         // 去登入
-  //       } else if (!uni.getStorageSync('code')) {
-  //         goJianquan(location.href)
-  //       }
-  //     }
-  //   }else{
-  //     if (store.getters.token) {
-  //       next();
-  //     } else {
-  //       next('/pages/login/indexs');
-  //     }
-  //   }
-  // }
+  if (whitePages.indexOf(to.path) >= 0) {
+    next();
+  } else {
+    if (isWeixin()) {
+      if (store.getters.token) {
+        next();
+      } else {
+        next('/pages/login/index');
+        // var code = getQueryVariable('code');
+        // if (code) {
+        //   // 去登入
+        // } else if (!uni.getStorageSync('code')) {
+        //   goJianquan(location.href)
+        // }
+      }
+    } else {
+      if (store.getters.token) {
+        next();
+      } else {
+        next('/pages/login/index');
+      }
+    }
+  }
 });
 
-// 全局路由后置守卫
-router.afterEach((to, from) => {
-  // console.log('跳转结束')
-})
+// // 全局路由后置守卫
+// router.afterEach((to, from) => {
+//   // console.log('跳转结束')
+// })
 
 export {
   router,
   RouterMount
-}
+}

+ 9 - 7
src/store/getters.js

@@ -1,7 +1,9 @@
-const getters = {
-  token: (state) => state.user.token,
-  username: state => state.user.username,
-  usercode: state => state.user.usercode,
   downloadFlag: state => state.user.downloadFlag,
-}
-
-export default getters
+const getters = {
+  token: (state) => state.user.token,
+  openId: state => state.user.openId,
+  name: state => state.user.name,
+  avatar: state => state.user.avatar,
+}
+
+
+export default getters

+ 1 - 1
src/store/index.js

@@ -10,4 +10,4 @@ export default new Vuex.Store({
     user
   },
   getters,
-})
+})

+ 1 - 1
src/store/modules/user/index.js

@@ -12,4 +12,4 @@ export default {
   state,
   mutations,
   actions
-}
+}