Authored by htoooth

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

@@ -15,6 +15,14 @@ const _ = require('lodash'); @@ -15,6 +15,14 @@ const _ = require('lodash');
15 * 找回密码主页面 15 * 找回密码主页面
16 */ 16 */
17 const index = (req, res, next) => { 17 const index = (req, res, next) => {
  18 + // 清除cookie
  19 + res.clearCookie('_UID', {
  20 + domain: 'yohobuy.com'
  21 + });
  22 + res.clearCookie('_TOKEN', {
  23 + domain: 'yohobuy.com'
  24 + });
  25 +
18 service.indexPageDataAsync() 26 service.indexPageDataAsync()
19 .then(result => { 27 .then(result => {
20 res.render('back/index', Object.assign({ 28 res.render('back/index', Object.assign({
@@ -6,6 +6,11 @@ const aes = require('./aes-pwd'); @@ -6,6 +6,11 @@ const aes = require('./aes-pwd');
6 const cache = global.yoho.cache; 6 const cache = global.yoho.cache;
7 const sign = global.yoho.sign; 7 const sign = global.yoho.sign;
8 const api = global.yoho.API; 8 const api = global.yoho.API;
  9 +const cookie = global.yoho.cookie;
  10 +
  11 +const Promise = require('bluebird');
  12 +
  13 +const cartService = require('./cart-service');
9 14
10 const Auth = { 15 const Auth = {
11 signin(type, area, profile, password, shoppingKey) { 16 signin(type, area, profile, password, shoppingKey) {
@@ -137,12 +142,11 @@ const Auth = { @@ -137,12 +142,11 @@ const Auth = {
137 return api.get('', param); 142 return api.get('', param);
138 }, 143 },
139 syncUserSession(uid, req, res) { 144 syncUserSession(uid, req, res) {
140 - return Auth.profile(uid).then((userInfo) => { 145 + return Promise.all([Auth.profile(uid), cartService.goodsCount(uid)]).spread((userInfo, count) => {
141 let token = sign.makeToken(uid); 146 let token = sign.makeToken(uid);
142 let data = userInfo.data; 147 let data = userInfo.data;
143 let encryptionUid = aes.encryptionUid(data.uid); 148 let encryptionUid = aes.encryptionUid(data.uid);
144 149
145 -  
146 if (data) { 150 if (data) {
147 let uidCookie = `${data.profile_name}::${encryptionUid}::${data.vip_info.title}::${token}`; 151 let uidCookie = `${data.profile_name}::${encryptionUid}::${data.vip_info.title}::${token}`;
148 let isStudent = data.vip_info.is_student || 0; 152 let isStudent = data.vip_info.is_student || 0;
@@ -156,6 +160,16 @@ const Auth = { @@ -156,6 +160,16 @@ const Auth = {
156 res.cookie('isStudent', isStudent, { 160 res.cookie('isStudent', isStudent, {
157 domain: 'yohobuy.com' 161 domain: 'yohobuy.com'
158 }); 162 });
  163 +
  164 + // 购物车中商品的数量
  165 + res.cookie('_g', JSON.stringify({
  166 + _k: cookie.getShoppingKey(req),
  167 + _nac: count,
  168 + _ac: 0,
  169 + _c: 1
  170 + }), {
  171 + domain: 'yohobuy.com'
  172 + });
159 } 173 }
160 req.session._TOKEN = token; // esline-disable-line 174 req.session._TOKEN = token; // esline-disable-line
161 req.session._LOGIN_UID = uid; // esline-disable-line 175 req.session._LOGIN_UID = uid; // esline-disable-line
  1 +/**
  2 + * Created by TaoHuang on 2016/9/28.
  3 + */
  4 +
  5 +'use strict';
  6 +
  7 +const api = global.yoho.API;
  8 +
  9 +const goodsCount = (uid, shoppingKey) => {
  10 + let params = {
  11 + method: 'app.Shopping.count'
  12 + };
  13 +
  14 + if (uid) {
  15 + params.uid = uid;
  16 + }
  17 +
  18 + if (shoppingKey) {
  19 + params.shopping_key = shoppingKey;
  20 + }
  21 +
  22 + return api.get('', params);
  23 +};
  24 +
  25 +module.exports = {
  26 + goodsCount
  27 +};
  1 +/**
  2 + * Created by TaoHuang on 2016/9/28.
  3 + */
  4 +
  5 +'use strict';
  6 +
  7 +
  8 +const api = require('./cart-api');
  9 +
  10 +const _ = require('lodash');
  11 +
  12 +const goodsCount = (uid, shoppingKey) => {
  13 + return api.goodsCount(uid, shoppingKey).then(result => _.get(result, 'data.cart_goods_count', 0));
  14 +};
  15 +
  16 +module.exports = {
  17 + goodsCount
  18 +};
  19 +
@@ -74,6 +74,16 @@ function getUid() { @@ -74,6 +74,16 @@ function getUid() {
74 return user[1]; 74 return user[1];
75 } 75 }
76 76
  77 +function getProfileName() {
  78 + var user = getUser();
  79 +
  80 + if (user === 0) {
  81 + return 0;
  82 + }
  83 +
  84 + return user[0];
  85 +}
  86 +
77 function getShoppingKey() { 87 function getShoppingKey() {
78 var c = cookie('_g'); 88 var c = cookie('_g');
79 89
@@ -174,6 +184,8 @@ window.getUser = getUser; @@ -174,6 +184,8 @@ window.getUser = getUser;
174 184
175 window.getUid = getUid; 185 window.getUid = getUid;
176 186
  187 +window.getProfileName = getProfileName;
  188 +
177 window.getShoppingKey = getShoppingKey; 189 window.getShoppingKey = getShoppingKey;
178 190
179 window.queryString = queryString; 191 window.queryString = queryString;
@@ -15,11 +15,14 @@ var $head = $('.head-wrapper'), @@ -15,11 +15,14 @@ var $head = $('.head-wrapper'),
15 $logotrans = $head.find('.main-logo'), 15 $logotrans = $head.find('.main-logo'),
16 $searchSug = $head.find('.search-suggest'), 16 $searchSug = $head.find('.search-suggest'),
17 $goCart = $head.find('.go-cart'), 17 $goCart = $head.find('.go-cart'),
  18 + $myYohoBox = $('#myYohoBox'),
18 $goodsNum = $goCart.find('.goods-num-tip'), 19 $goodsNum = $goCart.find('.goods-num-tip'),
19 $miniCart = $head.find('.mini-cart-wrapper'); 20 $miniCart = $head.find('.mini-cart-wrapper');
20 21
21 var $subNav = $('.sub-nav-list .contain-third'); 22 var $subNav = $('.sub-nav-list .contain-third');
22 23
  24 +var fetchUserInfoEvent = $.Callbacks('once'); // eslint-disable-line
  25 +
23 var thirdLineNum = 9, 26 var thirdLineNum = 9,
24 delayer, 27 delayer,
25 centerFn, 28 centerFn,
@@ -260,7 +263,7 @@ function syncLoginInfo() { @@ -260,7 +263,7 @@ function syncLoginInfo() {
260 method: 'open.passport.get' 263 method: 'open.passport.get'
261 }; 264 };
262 265
263 - $.getJSON('//www.yohobuy.com/common/passport/?callback=?', param, function(jsonData) { 266 + return $.getJSON('//www.yohobuy.com/common/passport/?callback=?', param, function(jsonData) {
264 if (jsonData && jsonData.data && jsonData.data.result !== -1) { 267 if (jsonData && jsonData.data && jsonData.data.result !== -1) {
265 updateLoginInfo(jsonData.data); 268 updateLoginInfo(jsonData.data);
266 } else { 269 } else {
@@ -491,10 +494,44 @@ if (isSupportCss3Animation()) { @@ -491,10 +494,44 @@ if (isSupportCss3Animation()) {
491 window.setTimeout(fadeAnimate, 3000); 494 window.setTimeout(fadeAnimate, 3000);
492 } 495 }
493 getBannerAndNotice(); // 获取头部banner 496 getBannerAndNotice(); // 获取头部banner
494 -syncLoginInfo(); // 同步登陆信息  
495 formatThirdMenu(); // 格式化三级菜单 497 formatThirdMenu(); // 格式化三级菜单
496 setInterval(syncCratInfo, 2000); // 定时同步购物车数量 498 setInterval(syncCratInfo, 2000); // 定时同步购物车数量
497 499
  500 +// 获取头部登陆信息
  501 +(function() {
  502 + var uid = getUid(), //eslint-disable-line
  503 + profileName = getProfileName(); // eslint-disable-line
  504 +
  505 + var info = {
  506 + usercenter: '//www.yohobuy.com/home?t=' + new Date().getTime(),
  507 + nickname: profileName,
  508 + signout: '//www.yohobuy.com/logout.html'
  509 + };
  510 +
  511 + if (uid === 0) {
  512 + return;
  513 + }
  514 +
  515 + $loginBox.html(loginFn(info));
  516 + $loginBox.show();
  517 +}());
  518 +
  519 +fetchUserInfoEvent.add(syncLoginInfo);
  520 +
  521 +$myYohoBox.hover(function() {
  522 + var uid = getUid(); // eslint-disable-line
  523 +
  524 + $myYohoBox.addClass('myyoho-hover');
  525 +
  526 + if (uid === 0) {
  527 + return;
  528 + }
  529 +
  530 + fetchUserInfoEvent.fire();
  531 +}, function() {
  532 + $myYohoBox.removeClass('myyoho-hover');
  533 +});
  534 +
498 $yohoGroup.hover(function() { 535 $yohoGroup.hover(function() {
499 var data = $(this).data(); 536 var data = $(this).data();
500 537
@@ -2,6 +2,8 @@ var $ = require('yoho-jquery'); @@ -2,6 +2,8 @@ var $ = require('yoho-jquery');
2 2
3 var $apiDom = $('#api-domain'); 3 var $apiDom = $('#api-domain');
4 4
  5 +require('./common');
  6 +
5 // var apiDomain = $apiDom.val(); // 获取数据的地址 7 // var apiDomain = $apiDom.val(); // 获取数据的地址
6 8
7 $apiDom.remove(); // 删除API信息 9 $apiDom.remove(); // 删除API信息
@@ -96,5 +98,16 @@ function actionLoginInfo() { @@ -96,5 +98,16 @@ function actionLoginInfo() {
96 }); 98 });
97 } 99 }
98 100
99 -actionLoginInfo(); // 获取登录信息 101 +// 获取头部登陆信息
  102 +(function() {
  103 + var uid = getUid(), //eslint-disable-line
  104 + profileName = getProfileName(); // eslint-disable-line
  105 +
  106 + if (uid === 0) {
  107 + return;
  108 + }
  109 +
  110 + setLoginStatus({random: $.now(), profileName: profileName});
  111 +
  112 +}());
100 113
@@ -214,7 +214,7 @@ @@ -214,7 +214,7 @@
214 } 214 }
215 } 215 }
216 216
217 - .myyoho:hover { 217 + .myyoho-hover {
218 background-color: #dcdcdc; 218 background-color: #dcdcdc;
219 219
220 .simple-user-center { 220 .simple-user-center {
@@ -10,6 +10,7 @@ module.exports = (list) => { @@ -10,6 +10,7 @@ module.exports = (list) => {
10 const formatData = []; 10 const formatData = [];
11 11
12 list = list || []; 12 list = list || [];
  13 +
13 // TODO: 14 // TODO:
14 list = camelCase(list); 15 list = camelCase(list);
15 16