Authored by htoooth

Merge branch 'hotfix/async-header' into release/5.1

... ... @@ -15,6 +15,14 @@ const _ = require('lodash');
* 找回密码主页面
*/
const index = (req, res, next) => {
// 清除cookie
res.clearCookie('_UID', {
domain: 'yohobuy.com'
});
res.clearCookie('_TOKEN', {
domain: 'yohobuy.com'
});
service.indexPageDataAsync()
.then(result => {
res.render('back/index', Object.assign({
... ...
... ... @@ -6,6 +6,11 @@ const aes = require('./aes-pwd');
const cache = global.yoho.cache;
const sign = global.yoho.sign;
const api = global.yoho.API;
const cookie = global.yoho.cookie;
const Promise = require('bluebird');
const cartService = require('./cart-service');
const Auth = {
signin(type, area, profile, password, shoppingKey) {
... ... @@ -137,12 +142,11 @@ const Auth = {
return api.get('', param);
},
syncUserSession(uid, req, res) {
return Auth.profile(uid).then((userInfo) => {
return Promise.all([Auth.profile(uid), cartService.goodsCount(uid)]).spread((userInfo, count) => {
let token = sign.makeToken(uid);
let data = userInfo.data;
let encryptionUid = aes.encryptionUid(data.uid);
if (data) {
let uidCookie = `${data.profile_name}::${encryptionUid}::${data.vip_info.title}::${token}`;
let isStudent = data.vip_info.is_student || 0;
... ... @@ -156,6 +160,16 @@ const Auth = {
res.cookie('isStudent', isStudent, {
domain: 'yohobuy.com'
});
// 购物车中商品的数量
res.cookie('_g', JSON.stringify({
_k: cookie.getShoppingKey(req),
_nac: count,
_ac: 0,
_c: 1
}), {
domain: 'yohobuy.com'
});
}
req.session._TOKEN = token; // esline-disable-line
req.session._LOGIN_UID = uid; // esline-disable-line
... ...
/**
* Created by TaoHuang on 2016/9/28.
*/
'use strict';
const api = global.yoho.API;
const goodsCount = (uid, shoppingKey) => {
let params = {
method: 'app.Shopping.count'
};
if (uid) {
params.uid = uid;
}
if (shoppingKey) {
params.shopping_key = shoppingKey;
}
return api.get('', params);
};
module.exports = {
goodsCount
};
\ No newline at end of file
... ...
/**
* Created by TaoHuang on 2016/9/28.
*/
'use strict';
const api = require('./cart-api');
const _ = require('lodash');
const goodsCount = (uid, shoppingKey) => {
return api.goodsCount(uid, shoppingKey).then(result => _.get(result, 'data.cart_goods_count', 0));
};
module.exports = {
goodsCount
};
... ...
... ... @@ -74,6 +74,16 @@ function getUid() {
return user[1];
}
function getProfileName() {
var user = getUser();
if (user === 0) {
return 0;
}
return user[0];
}
function getShoppingKey() {
var c = cookie('_g');
... ... @@ -174,6 +184,8 @@ window.getUser = getUser;
window.getUid = getUid;
window.getProfileName = getProfileName;
window.getShoppingKey = getShoppingKey;
window.queryString = queryString;
... ...
... ... @@ -15,11 +15,14 @@ var $head = $('.head-wrapper'),
$logotrans = $head.find('.main-logo'),
$searchSug = $head.find('.search-suggest'),
$goCart = $head.find('.go-cart'),
$myYohoBox = $('#myYohoBox'),
$goodsNum = $goCart.find('.goods-num-tip'),
$miniCart = $head.find('.mini-cart-wrapper');
var $subNav = $('.sub-nav-list .contain-third');
var fetchUserInfoEvent = $.Callbacks('once'); // eslint-disable-line
var thirdLineNum = 9,
delayer,
centerFn,
... ... @@ -111,16 +114,16 @@ function setTopBanner(data) {
} else {
topbanner = '<div class="yoho-notice">' +
'<div class="notice-container center-content">' +
'<h1 class="notice-title">关于系统升级的公告</h1>' +
'<div class="notice-content">' +
'<p class="tips">尊敬的顾客:</p>' +
'<p class="detail">您好!为了向您提供更优质的服务,目前系统正在升级,请耐心等待。</p>' +
'<p class="detail">系统升级期间,部分地区用户体验会有暂时中断,如遇紧急事宜,欢迎垂询客服热线:' +
'400-889-9646 09:00-22:30(周一至周日)。稍后系统将恢复正常' +
'使用,欢迎您继续光顾YOHO!BUY有货!带来不便之处深表歉意,请您谅解!</p>' +
'</div>' +
'<h1 class="notice-title">关于系统升级的公告</h1>' +
'<div class="notice-content">' +
'<p class="tips">尊敬的顾客:</p>' +
'<p class="detail">您好!为了向您提供更优质的服务,目前系统正在升级,请耐心等待。</p>' +
'<p class="detail">系统升级期间,部分地区用户体验会有暂时中断,如遇紧急事宜,欢迎垂询客服热线:' +
'400-889-9646 09:00-22:30(周一至周日)。稍后系统将恢复正常' +
'使用,欢迎您继续光顾YOHO!BUY有货!带来不便之处深表歉意,请您谅解!</p>' +
'</div>' +
'</div>' +
'</div>';
'</div>';
}
$('body').prepend(topbanner);
}
... ... @@ -260,7 +263,7 @@ function syncLoginInfo() {
method: 'open.passport.get'
};
$.getJSON('//www.yohobuy.com/common/passport/?callback=?', param, function(jsonData) {
return $.getJSON('//www.yohobuy.com/common/passport/?callback=?', param, function(jsonData) {
if (jsonData && jsonData.data && jsonData.data.result !== -1) {
updateLoginInfo(jsonData.data);
} else {
... ... @@ -491,10 +494,44 @@ if (isSupportCss3Animation()) {
window.setTimeout(fadeAnimate, 3000);
}
getBannerAndNotice(); // 获取头部banner
syncLoginInfo(); // 同步登陆信息
formatThirdMenu(); // 格式化三级菜单
setInterval(syncCratInfo, 2000); // 定时同步购物车数量
// 获取头部登陆信息
(function() {
var uid = getUid(), //eslint-disable-line
profileName = getProfileName(); // eslint-disable-line
var info = {
usercenter: '//www.yohobuy.com/home?t=' + new Date().getTime(),
nickname: profileName,
signout: '//www.yohobuy.com/logout.html'
};
if (uid === 0) {
return;
}
$loginBox.html(loginFn(info));
$loginBox.show();
}());
fetchUserInfoEvent.add(syncLoginInfo);
$myYohoBox.hover(function() {
var uid = getUid(); // eslint-disable-line
$myYohoBox.addClass('myyoho-hover');
if (uid === 0) {
return;
}
fetchUserInfoEvent.fire();
}, function() {
$myYohoBox.removeClass('myyoho-hover');
});
$yohoGroup.hover(function() {
var data = $(this).data();
... ...
... ... @@ -2,6 +2,8 @@ var $ = require('yoho-jquery');
var $apiDom = $('#api-domain');
require('./common');
// var apiDomain = $apiDom.val(); // 获取数据的地址
$apiDom.remove(); // 删除API信息
... ... @@ -70,12 +72,12 @@ function setLoginStatus(data) {
if (data.result !== -1) {
name = formatUsernName(info.profileName);
loginHtml = '<span>Hi~</span>' +
'<a href="//www.yohobuy.com/home?t=' + info.random + '">' + name + '</a>&nbsp;' +
'<a href="//www.yohobuy.com/logout.html">[退出]</a>';
'<a href="//www.yohobuy.com/home?t=' + info.random + '">' + name + '</a>&nbsp;' +
'<a href="//www.yohobuy.com/logout.html">[退出]</a>';
} else {
loginHtml = '<span>Hi~</span>&nbsp;' +
'<a href="//www.yohobuy.com/signin.html">[请登录]</a>&nbsp;' +
'<a href="//www.yohobuy.com/reg.html">[免费注册]</a>';
'<a href="//www.yohobuy.com/signin.html">[请登录]</a>&nbsp;' +
'<a href="//www.yohobuy.com/reg.html">[免费注册]</a>';
}
$('.header-tool li').eq(0).html(loginHtml);
}
... ... @@ -96,5 +98,16 @@ function actionLoginInfo() {
});
}
actionLoginInfo(); // 获取登录信息
// 获取头部登陆信息
(function() {
var uid = getUid(), //eslint-disable-line
profileName = getProfileName(); // eslint-disable-line
if (uid === 0) {
return;
}
setLoginStatus({random: $.now(), profileName: profileName});
}());
... ...
... ... @@ -214,7 +214,7 @@
}
}
.myyoho:hover {
.myyoho-hover {
background-color: #dcdcdc;
.simple-user-center {
... ...
... ... @@ -10,6 +10,7 @@ module.exports = (list) => {
const formatData = [];
list = list || [];
// TODO:
list = camelCase(list);
... ...