Selaa lähdekoodia

微信登录2

chao 4 vuotta sitten
vanhempi
commit
b714720a54

+ 12 - 4
src/main/resources/static/js/base.js

@@ -19,8 +19,8 @@ if(localStorage.getItem('userInfo')){
             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);
+                    setBeforeUrl();
                     window.location.href = r.data;
                 }
             });
@@ -197,7 +197,7 @@ $(function(){
                     text: btnTxt,
                     btnClass: 'btn-confirm-login',
                     action: function(){
-                        setBaseCookie("loginBeforePath", window.location.href);
+                        setBeforeUrl();
                         window.location.href = '/login.html';
                     }
                 },
@@ -211,7 +211,7 @@ $(function(){
     // 去登录弹窗
     $('body').on("click", '.toLogin',function () {
         //loginAert('<span>你还未登录</span><span>请登录后再进行购买</span>', '去登录');
-        setBaseCookie("loginBeforePath", window.location.href);
+        setBeforeUrl();
         window.location.href = '/login.html';
     });
     // 退出登录
@@ -325,6 +325,14 @@ $(function(){
     });
 
 });
+
+function setBeforeUrl(){
+    var baseUrl = window.location.href;
+    var flag = baseUrl.indexOf('/login.html')>0 || baseUrl.indexOf('/register.html')>0 || baseUrl.indexOf('/we_chat/redirect_uri.html')>0;
+    if(!flag){
+        setBaseCookie("loginBeforePath", baseUrl);
+    }
+}
 // 公共方法
 function setBaseCookie(cname,cvalue,exdays){
     if (exdays) {
@@ -580,7 +588,7 @@ function toBeforePath(){
     window.location.href = '/index.html';
 }
 function toLogin() {//去登录
-    setBaseCookie("loginBeforePath", window.location.href);
+    setBeforeUrl();
     window.location.href = '/login.html';
 }
 function  upgrade () { //升级会员

+ 10 - 13
src/main/resources/static/js/index.js

@@ -88,19 +88,16 @@ var homeData = new Vue({
                         }
                     },500);
                     // 获取价格
-                    // if(_self.userId && _self.userId>0){
-                        var productIdArr = [];
-                        _self.recommends.map(function (item) {
-                            // 0公开价格 1不公开价格 2仅对会员机构公开
-                            if (item.priceFlag !== 1) {
-                                productIdArr.push(item.id)
-                            }
-                        });
-                        setProductPrice(_self.recommends, productIdArr.join(","), _self.userId, function () {
-                            _self.$forceUpdate();
-                        });
-                        console.log(_self.recommends)
-                    // }
+                    var productIdArr = [];
+                    _self.recommends.map(function (item) {
+                        // 0公开价格 1不公开价格 2仅对会员机构公开
+                        if (item.priceFlag !== 1) {
+                            productIdArr.push(item.id)
+                        }
+                    });
+                    setProductPrice(_self.recommends, productIdArr.join(","), _self.userId, function () {
+                        _self.$forceUpdate();
+                    });
                 }
             });
         },

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

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

+ 4 - 3
src/main/resources/templates/we_chat/redirect_uri.html

@@ -14,10 +14,11 @@
     var wx_mode = Number(getBaseCookie("weChatAutoLogin"))===1 ? 1 : 2;
     var wx_code = getUrlParam('code');
     var wx_state = getUrlParam('state');
+    var userData = '';
     $.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 = {
+            userData = {
                 account: r.data.account,
                 email: r.data.email,
                 phone: r.data.bindMobile,
@@ -49,9 +50,9 @@
         if (loginBeforePath && loginBeforePath!='undefined' && loginBeforePath.indexOf('.html')>0) {
             delBaseCookie("loginBeforePath");
             window.location.href = loginBeforePath;
-        } else if (userData.userIdentity*1 === 3) {
+        } else if (userData && userData.userIdentity*1 === 3) {
             location.href = '/supplier/dashboard.html';
-        } else if (userData.userIdentity*1 === 2 || userData.userIdentity*1 === 4) {
+        } else if (userData && (userData.userIdentity*1 === 2 || userData.userIdentity*1 === 4)) {
             location.href = '/user/dashboard.html';
         } else {
             location.href="/index.html";