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,
... ... @@ -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信息
... ... @@ -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);
... ...