Browse Source

feat: 登录流程梳理

John-Hong 2 years ago
parent
commit
eb58ecf7f2
2 changed files with 12 additions and 5 deletions
  1. 5 3
      src/App.vue
  2. 7 2
      src/pages/login/openWx.vue

+ 5 - 3
src/App.vue

@@ -73,18 +73,19 @@ export default {
           })
           return
         }
+        // 初始化微信
         initWxJsSdkConfig(['chooseWXPay']);
         this.$store.commit('SET_GROUP_ID', query.groupId);
         this.$store.commit('SET_MALL_ID', query.mallid);
         // 如果用户不选择登录,则不走登录逻辑
         const passLogin = uni.getStorageSync('passLogin');
-        if(passLogin) {
+        this.isInit = true
+        if(!passLogin) {
           this.$router.replace({
             path: '/login',
             query: query
           })  
         }
-        this.isInit = true
         return
       }
       // 如果用已经登录
@@ -97,10 +98,11 @@ export default {
         return
       }
       // 当前页面是否是在微信公众号运行:end
+
+      /* 微信小程序 webview 配置 */
       if (!query?.pageId?.length || !query?.token?.length) {
         return;
       }
-    
       window.token = query?.token
       // this.getTicket()
       this.wss(() => {

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

@@ -1,7 +1,7 @@
 <template>
   <div>
     <!-- 微信页面授权回调:用户首次进入时判断当前用户所在环境:微信公众号和微信小程序 -->
-    微信页面授权回调:用户首次进入时判断当前用户所在环境:微信公众号和微信小程序
+    <!-- 微信页面授权回调:用户首次进入时判断当前用户所在环境:微信公众号和微信小程序 -->
   </div>
 </template>
 <script>
@@ -45,7 +45,12 @@ export default {
         code,
         grant_type: 'authorization_code',
       });
-      console.log(4848484848, res);
+      if ( res?.expires_in && res?.openid ) {
+        this.$store.commit('SET_OPENID', res.openid)
+        this.$router.replace({
+          path: '/'
+        })
+      }
       //   this.$http
       //     .post('/api/user/wechat/login', { code: code })
       //     .then((res) => {