|
@@ -9,19 +9,22 @@ if(localStorage.getItem('userInfo')){
|
|
|
globalUserData = JSON.parse(localStorage.getItem('userInfo'));
|
|
|
GLOBAL_TOKEN = globalUserData.token;
|
|
|
GLOBAL_USER_ID = globalUserData.userId;
|
|
|
- GLOBAL_USER_IDENTITY = globalUserData.identity ? globalUserData.identity : globalUserData.userIdentity;
|
|
|
+ GLOBAL_USER_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;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
// 头部
|
|
@@ -75,6 +78,8 @@ var globalHead = new Vue({
|
|
|
if (r.code === 0 && r.data) {
|
|
|
_self.headCart.cartList = r.data;
|
|
|
_self.headCart.cartCount = r.data.length;
|
|
|
+ _self.headCart.productCount = 0;
|
|
|
+ _self.headCart.priceTotal = 0;
|
|
|
r.data.map(function(item){
|
|
|
_self.headCart.productCount += item.number;
|
|
|
_self.headCart.priceTotal += item.number*item.price;
|
|
@@ -191,7 +196,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 +210,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 +324,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 +557,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='';
|