Explorar o código

微信小程序登录逻辑梳理_v11

John-Hong %!s(int64=2) %!d(string=hai) anos
pai
achega
61bd1ba60d
Modificáronse 2 ficheiros con 25 adicións e 2 borrados
  1. 1 0
      src/App.vue
  2. 24 2
      src/pages/login/openWx.vue

+ 1 - 0
src/App.vue

@@ -79,6 +79,7 @@ export default {
       const query = getUrlParams();
       // console.log('h5登录时的参数', query);
       const platform = getPlatform();
+      // 设置 member、groupId 和 mallId
       if (
         (query.groupId && query.groupId !== 'undefined') ||
         uni.getStorageSync('mallId')

+ 24 - 2
src/pages/login/openWx.vue

@@ -15,6 +15,28 @@ export default {
   },
   mounted() {
     console.log(17171717171717);
+    const kipAccessToken = uni.getStorageSync('kipAccessToken');
+    if (!kipAccessToken) {
+      /* if (!openid) {
+            // 当进入其他页面时,需要先打开路由展示
+            this.isInit = true;
+            // 前往授权页面
+            this.$router.replace({
+              path: '/openWx',
+              query: query,
+            });
+            return;
+          } */
+      // 初始化微信
+      initWxJsSdkConfig(['chooseWXPay', 'scanQRCode', 'checkJsApi']);
+      // 如果用户不选择登录,则不走登录逻辑
+      this.isInit = true;
+      this.$router.replace({
+        path: '/login',
+        query: query,
+      });
+      return;
+    }
   },
   methods: {
     getCode() {
@@ -22,13 +44,13 @@ export default {
       const local = window.location.origin;
       // return
       if (code == null || code === '') {
-        const componentAppid = 'wxd830fe4d1e04988e'
+        // const componentAppid = 'wxd830fe4d1e04988e'
         window.location.href =
           'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
           //   window.APPID +
           `wx907c27f16841a919` +
           '&redirect_uri=' +
-          encodeURIComponent('https://dev-tparking.kerryonvip.com') +
+          encodeURIComponent(local) +
           `&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect`;
       } else {
         this.getOpenId(code); //把code传给后台获取用户信息