chao il y a 4 ans
Parent
commit
1b02c8c8ab

+ 18 - 26
src/main/resources/static/js/account/login.js

@@ -74,7 +74,6 @@ var loginPage = new Vue({
                 }else {
                     clearTimeout(timer); //清理定时任务
                     if(response.code == 0){
-                        var _userIdentity = response.data.userIdentity;
                         _self.userData = {
                             account: response.data.account,
                             email: response.data.email,
@@ -91,18 +90,15 @@ var loginPage = new Vue({
                         };
                         _self.setStorages( _self.userData);
                         // 登录成功页面跳转
-                        var forwardUrl = document.referrer;
-                        var getHrefUrl = $("#spiServer").val();
-                        if (forwardUrl && forwardUrl!=getHrefUrl){
-                            window.location.href = forwardUrl;
-                        }else{
-                            if(_userIdentity == 4 || _userIdentity ==2){
-                                window.location.href = '/user/dashboard.html';
-                            }else if(_userIdentity == 3){
-                                window.location.href = '/supplier/dashboard.html';
-                            }else{
-                                window.location.href="/index.html";
-                            }
+                        var loginBeforePath = getCookie("loginBeforePath");
+                        if (loginBeforePath) {
+                            window.location.href = loginBeforePath;
+                        } else if (_self.userData.userIdentity*1 === 3) {
+                            location.href = '/supplier/dashboard.html';
+                        } else if (_self.userData.userIdentity*1 === 2 || _self.userData.userIdentity*1 === 4) {
+                            location.href = '/user/dashboard.html';
+                        } else {
+                            location.href="/index.html";
                         }
                     }else if(response.code == -4){
                         window.location.href = '/bind.html';
@@ -139,7 +135,6 @@ var loginPage = new Vue({
                 UserApi.PostLoginAccount(params,function(response){
                     _self.loginLoading = false;
                     if(response.code === 0){
-                        var _userIdentity = response.data.userIdentity;
                         _self.userData = {
                             account: response.data.account,
                             email: response.data.email,
@@ -156,18 +151,15 @@ var loginPage = new Vue({
                         };
                         _self.setStorages( _self.userData);
                         // 登录成功页面跳转
-                        var forwardUrl = document.referrer;
-                        var getHrefUrl = $("#spiServer").val();
-                        if (forwardUrl && forwardUrl!=getHrefUrl){
-                            window.location.href = forwardUrl;
-                        }else{
-                            if(_userIdentity == 4 || _userIdentity ==2){
-                                window.location.href = '/user/dashboard.html';
-                            }else if(_userIdentity == 3){
-                                window.location.href = '/supplier/dashboard.html';
-                            }else{
-                                window.location.href="/index.html";
-                            }
+                        var loginBeforePath = getCookie("loginBeforePath");
+                        if (loginBeforePath) {
+                            window.location.href = loginBeforePath;
+                        } else if (_self.userData.userIdentity*1 === 3) {
+                            location.href = '/supplier/dashboard.html';
+                        } else if (_self.userData.userIdentity*1 === 2 || _self.userData.userIdentity*1 === 4) {
+                            location.href = '/user/dashboard.html';
+                        } else {
+                            location.href="/index.html";
                         }
                     } else {// 登录失败
                         CAIMEI.Alert(response.msg,'确定',false);

+ 37 - 14
src/main/resources/static/js/base.js

@@ -12,16 +12,19 @@ if(localStorage.getItem('userInfo')){
     GLOBAL_USER_IDENTITY = globalUserData.identity ? globalUserData.identity : globalUserData.userIdentity;
     GLOBAL_SHOP_ID = globalUserData.shopId;
 } else {
-    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?redirectUri='+urlForWeChat, function(r){
-            if(r.code===0 && r.data){
-                localStorage.setItem("loginBeforePath", window.location.href);
-                window.location.href = r.data;
-            }
-        });
+    if(!getCookie("weChatAutoLogin")){
+        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?redirectUri='+urlForWeChat, function(r){
+                if(r.code===0 && r.data){
+                    setCookie("loginBeforePath", window.location.href);
+                    setCookie("weChatAutoLogin", 1);
+                    window.location.href = r.data;
+                }
+            });
+        }
     }
 }
 // 头部
@@ -191,7 +194,7 @@ $(function(){
                     text: btnTxt,
                     btnClass: 'btn-confirm-login',
                     action: function(){
-                        localStorage.setItem("loginBeforePath", window.location.href);
+                        setCookie("loginBeforePath", window.location.href);
                         window.location.href = '/login.html';
                     }
                 },
@@ -205,7 +208,7 @@ $(function(){
     // 去登录弹窗
     $('body').on("click", '.toLogin',function () {
         //loginAert('<span>你还未登录</span><span>请登录后再进行购买</span>', '去登录');
-        localStorage.setItem("loginBeforePath", window.location.href);
+        setCookie("loginBeforePath", window.location.href);
         window.location.href = '/login.html';
     });
     // 退出登录
@@ -319,6 +322,25 @@ $(function(){
 
 });
 // 公共方法
+function setCookie(cname,cvalue,exdays){
+    if (exdays) {
+        var d = new Date();
+        d.setTime(d.getTime()+(exdays*24*60*60*1000));
+        var expires = "expires="+d.toGMTString();
+        document.cookie = cname+"="+cvalue+"; path=/; "+expires;
+    } else {
+        document.cookie = cname+"="+cvalue+"; path=/";
+    }
+}
+function getCookie(cname){
+    var name = cname + "=";
+    var ca = document.cookie.split(';');
+    for(var i=0; i<ca.length; i++) {
+        var c = ca[i].trim();
+        if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
+    }
+    return "";
+}
 function getDateStr(dd, addCount) {
     dd.setDate(dd.getDate() + addCount);//获取addCount天后的日期
     var y = dd.getFullYear();
@@ -533,14 +555,15 @@ function setProductPrice(productList, productIds, userId, callback){
 }
 // 登录后返回登录前页面
 function toBeforePath(){
-    var beforePath = localStorage.getItem("loginBeforePath");
+    var beforePath = getCookie("loginBeforePath");
     if (!beforePath) {
         beforePath = '/index.html';
     }
     window.location.href = beforePath;
 }
 function toLogin() {//去登录
-    window.location.href ='/login.html';
+    setCookie("loginBeforePath", window.location.href);
+    window.location.href = '/login.html';
 }
 function  upgrade () { //升级会员
     window.location.href='';

+ 2 - 1
src/main/resources/static/js/product/detail.js

@@ -153,7 +153,8 @@ var productDetail = new Vue({
             }
         },
         toLogin: function() {
-            location.href ='/login.html';
+            setCookie("loginBeforePath", window.location.href);
+            window.location.href = '/login.html';
         },
 		addShopCart: function(){ //加入购物车
 		    var _self = this;

+ 1 - 1
src/main/resources/templates/we_chat/redirect_uri.html

@@ -29,7 +29,7 @@
                 token: r.data.token
             };
             localStorage.setItem('userInfo',JSON.stringify(userData));
-            var loginBeforePath = sessionStorage.getItem("loginBeforePath");
+            var loginBeforePath = getCookie("loginBeforePath");
             if (loginBeforePath) {
                 window.location.href = loginBeforePath;
             } else if (userData.userIdentity*1 === 3) {