chao 4 gadi atpakaļ
vecāks
revīzija
c834e892af

+ 5 - 4
src/main/resources/static/js/account/login.js

@@ -113,14 +113,15 @@ var loginPage = new Vue({
             if (this.isWeChat) {
                 // 微信浏览器自动授权登录
                 var urlForWeChat = 'https://www.caimei365.com/we_chat/redirect_uri.html';
-                $.get(spiServer+'/user/authorizationLink?redirectUri='+urlForWeChat, function(r){
+                $.get(spiServer+'/user/authorizationLink?mode=2&redirectUri='+urlForWeChat, function(r){
                     if(r.code===0 && r.data){
+                        setBaseCookie("weChatAutoLogin", 2);
                         window.location.href = r.data;
                     }
                 });
             }
         },
-        weChatAutoLogin: function(){
+        /*weChatAutoLogin: function(){
             if (this.isWeChat && Number(getBaseCookie("weChatAutoLogin"))!==1) {
                 // 微信浏览器自动授权登录
                 var urlForWeChat = 'https://www.caimei365.com/we_chat/redirect_uri.html';
@@ -131,7 +132,7 @@ var loginPage = new Vue({
                     }
                 });
             }
-        },
+        },*/
         toNormalLogin: function(){
             this.qrCodeLogin = false;
         },
@@ -201,7 +202,7 @@ var loginPage = new Vue({
     created: function () {
         var userAgent = navigator.userAgent.toLowerCase();
         this.isWeChat = userAgent.match(/MicroMessenger/i);
-        this.weChatAutoLogin();
+        // this.weChatAutoLogin();
     },
     mounted: function () {
         var _self = this;

+ 15 - 0
src/main/resources/static/js/base.js

@@ -11,6 +11,21 @@ if(localStorage.getItem('userInfo')){
     GLOBAL_USER_ID = globalUserData.userId*1;
     GLOBAL_USER_IDENTITY = globalUserData.userIdentity*1;
     GLOBAL_SHOP_ID = globalUserData.shopId*1;
+} else {
+    if(Number(getBaseCookie("weChatAutoLogin"))!==1){
+        var userAgent = navigator.userAgent.toLowerCase();
+        if (userAgent.match(/MicroMessenger/i)) {
+            // 微信浏览器自动授权登录
+            var urlForWeChat = 'https://www.caimei365.com/we_chat/redirect_uri.html';
+            $.get(spiServer+'/user/authorizationLink?mode=1&redirectUri='+urlForWeChat, function(r){
+                if(r.code===0 && r.data){
+                    setBaseCookie("loginBeforePath", window.location.href);
+                    setBaseCookie("weChatAutoLogin", 1);
+                    window.location.href = r.data;
+                }
+            });
+        }
+    }
 }
 // 头部
 var globalHead = new Vue({

+ 24 - 15
src/main/resources/templates/we_chat/redirect_uri.html

@@ -11,9 +11,10 @@
 <template th:replace="components/foot-link"></template>
 <script charset="utf-8" type="text/javascript">
     // 如果用户同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE
+    var wx_mode = Number(getBaseCookie("weChatAutoLogin"))===1 ? 1 : 2;
     var wx_code = getUrlParam('code');
     var wx_state = getUrlParam('state');
-    $.get(spiServer+'/user/authorizationLogin?code='+wx_code+'&state='+wx_state, function(r){
+    $.get(spiServer+'/user/authorizationLogin?code='+wx_code+'&state='+wx_state+'&mode='+wx_mode, function(r){
         if(r.code===0){
             console.log(r.data);
             var userData = {
@@ -31,23 +32,31 @@
                 token: r.data.token
             };
             localStorage.setItem('userInfo',JSON.stringify(userData));
-            var loginBeforePath = getBaseCookie("loginBeforePath");
-            if (loginBeforePath && loginBeforePath!='undefined' && loginBeforePath.indexOf('.html')>0) {
-                delBaseCookie("loginBeforePath");
-                window.location.href = loginBeforePath;
-            } else if (userData.userIdentity*1 === 3) {
-                location.href = '/supplier/dashboard.html';
-            } else if (userData.userIdentity*1 === 2 || userData.userIdentity*1 === 4) {
-                location.href = '/user/dashboard.html';
-            } else {
-                location.href="/index.html";
-            }
+            toPage();
         }else{
-            CAIMEI.Alert(r.msg,'确定',true, function(){
-                location.href="/index.html";
-            });
+            if (wx_mode===2 && r.code===-4){
+                //微信绑定页面
+                window.location.href = '/bind.html';
+            }else{
+                CAIMEI.Alert(r.msg,'确定',true, function(){
+                    toPage();
+                });
+            }
         }
     });
+    function toPage(){
+        var loginBeforePath = getBaseCookie("loginBeforePath");
+        if (loginBeforePath && loginBeforePath!='undefined' && loginBeforePath.indexOf('.html')>0) {
+            delBaseCookie("loginBeforePath");
+            window.location.href = loginBeforePath;
+        } else if (userData.userIdentity*1 === 3) {
+            location.href = '/supplier/dashboard.html';
+        } else if (userData.userIdentity*1 === 2 || userData.userIdentity*1 === 4) {
+            location.href = '/user/dashboard.html';
+        } else {
+            location.href="/index.html";
+        }
+    }
 </script>
 </body>
 </html>