Authored by yyq

page cache updata header by cookie

... ... @@ -52,10 +52,13 @@ const getNavBar = (data, type) => {
let obj = {};
let lowEn = _.camelCase(item.sort_name_en).toLowerCase();
obj.link = item.sort_url;
obj.cn = item.sort_name;
obj.en = item.sort_name_en;
obj.isNewPage = item.is_new_page === 'Y' ? true : false;
Object.assign(obj, {
type: lowEn,
link: item.sort_url,
cn: item.sort_name,
en: item.sort_name_en,
isNewPage: item.is_new_page === 'Y'
});
if (type === lowEn) {
obj.active = true;
... ... @@ -135,11 +138,12 @@ const getThirdNav = (data) => {
* @param {String} type 频道类型
* @return {array} 子菜单数组
*/
const getSubNav = (data, type) => {
let subNav = [];
const getSubNavGroup = (data, type) => {
let subNavGroup = [];
_.forEach(data, it => {
if (type === _.camelCase(it.sort_name_en).toLowerCase()) {
let subNav = [];
_.forEach(it.sub, item => {
let obj = {};
... ... @@ -155,10 +159,17 @@ const getSubNav = (data, type) => {
subNav.push(obj);
});
}
let lowEn = _.camelCase(it.sort_name_en).toLowerCase();
subNavGroup.push({
subType: lowEn,
subNav: subNav,
active: lowEn === type
});
});
return subNav;
return subNavGroup;
};
... ... @@ -174,7 +185,7 @@ const setHeaderData = (resData, type) => (
headType: type,
yohoGroup: getMenuData(),
navbars: resData ? getNavBar(resData, type) : [],
subNav: resData ? getSubNav(resData, type) : []
subNavGroup: resData ? getSubNavGroup(resData, type) : []
}
);
... ...
{{# headerData}}
<div class="yoho-header {{headType}}">
<div id="yoho-header" class="yoho-header {{headType}}" data-type="{{headType}}">
<div class="tool-wrapper clearfix">
<div class="center-content">
<div class="yoho-group-map left">
... ... @@ -66,7 +66,7 @@
<div class="main-logo"><a href="//www.yohobuy.com/" class="main-link"></a></div>
<ul class="main-nav-list">
{{# navbars}}
<li {{#if active}} class="cure"{{/if}}{{#if ico}} style="background: url({{image ico 54 32}}) no-repeat center center"{{/if}}>
<li class="{{type}}{{#if active}} cure{{/if}}" {{#if ico}} style="background: url({{image ico 54 32}}) no-repeat center center"{{/if}}>
{{#if ico}}
<a href="{{link}}"{{#if isNewPage}} target="_blank"{{/if}} class="menu-ico"></a>
{{^}}
... ... @@ -108,7 +108,8 @@
</div>
<div class="nav-wrapper clearfix">
<div class="center-content">
<ul class="sub-nav-list">
{{# subNavGroup}}
<ul class="sub-nav-list {{subType}}{{#if active}} cure{{/if}}">
{{# subNav}}
<li {{#if thirdNav}}class="contain-third"{{/if}}>
<a href="{{link}}">{{name}}
... ... @@ -141,6 +142,7 @@
</li>
{{/ subNav}}
</ul>
{{/ subNavGroup}}
</div>
</div>
</div>
... ...
... ... @@ -18,7 +18,7 @@ var $head = $('.head-wrapper'),
$goodsNum = $goCart.find('.goods-num-tip'),
$miniCart = $head.find('.mini-cart-wrapper');
var $subNav = $('.sub-nav-list .contain-third');
var $subNav = $('.sub-nav-list.cure .contain-third');
var thirdLineNum = 9,
delayer,
... ... @@ -481,7 +481,38 @@ function isSupportCss3Animation() {
return false;
}
}
}
// 处理pageCache频道显示异常问题
function syncPageChannel() {
var $header = $('#yoho-header'),
$navs;
var channel = window.cookie('_Channel') || 'girls',
type;
// 过滤频道页
if ($('.home-page').length) {
return;
}
if ($header && $header.length) {
$navs = $header.find('.' + channel);
type = $header.data('type');
if (channel === type || !$navs.length) {
return;
}
// 更新频道菜单选中状态
$navs.siblings('.cure').removeClass('cure');
$navs.addClass('cure');
// 更新频道颜色
$header.attr('class', 'yoho-header ' + channel);
// 更新三级菜单jq对象
$subNav = $('.sub-nav-list.cure .contain-third');
}
}
if (isSupportCss3Animation()) {
... ... @@ -490,6 +521,7 @@ if (isSupportCss3Animation()) {
} else {
window.setTimeout(fadeAnimate, 3000);
}
syncPageChannel();
getBannerAndNotice(); // 获取头部banner
syncLoginInfo(); // 同步登陆信息
formatThirdMenu(); // 格式化三级菜单
... ...
... ... @@ -90,12 +90,12 @@
a {
color: #8e8e8e;
}
span {
a > span {
color: #d0021b;
}
}
}
.nick-name {
color: #000;
... ... @@ -602,6 +602,12 @@
position: relative;
.sub-nav-list {
display: none;
&.cure {
display: block;
}
li {
line-height: 40px;
padding-right: 46px;
... ...