Authored by ccbikai

Merge branch 'feature/star' of git.yoho.cn:fe/yohobuywap-node into feature/star

... ... @@ -25,12 +25,12 @@ const headTab = [
}
];
const processPublicData = (req) => {
const processPublicData = (req, title) => {
let channel = req.query.channel || req.cookies._Channel || 'boys';
let headerData = headerModel.setNavHeader('新潮教室', channel);
let headerData = headerModel.setNavHeader(title, channel);
let renderData = {
module: 'guang',
title: '新潮教室',
title: title,
pageHeader: headerData
};
... ... @@ -50,7 +50,7 @@ exports.index = (req, res) => {
pageHeadTab[0].cur = true;
res.render('star/index', _.assign({
page: 'star'
}, processPublicData(req), {
}, processPublicData(req, '星潮教室'), {
content: {
focus: true,
data: result.ads
... ... @@ -76,7 +76,7 @@ exports.special = (req, res) => {
pageHeadTab[1].cur = true;
res.render('star/special', _.assign({
page: 'star'
}, processPublicData(req), {
}, processPublicData(req, '星潮教室'), {
resources: result,
headTab: pageHeadTab
}));
... ... @@ -95,8 +95,9 @@ exports.collocation = (req, res) => {
pageHeadTab[2].cur = true;
res.render('star/collocation', _.assign({
isStarDetailPage: true,
page: 'collocation'
}, processPublicData(req), {
}, processPublicData(req, '星潮教室'), {
headTab: headTab
}));
};
... ... @@ -112,7 +113,7 @@ exports.collocationList = (req, res) => {
let uid = 9239279 || req.user.uid || 0;
starModel.getCollocationListData(params, uid).then((result) => {
res.render('star/collocation-list', _.assign({
res.render('star/list', _.assign({
layout: false,
params: params,
list: result,
... ... @@ -128,5 +129,28 @@ exports.collocationList = (req, res) => {
* @return {[type]}
*/
exports.detail = (req, res) => {
res.render('star/detail');
res.render('star/detail', _.assign({
isStarDetailPage: true,
page: 'detail-list'
}, processPublicData(req, req.query.tag)));
};
/**
* 明星专题文章请求
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.detailList = (req, res) => {
let params = req.query;
starModel.getDetailData(params).then((result) => {
res.render('star/list', _.assign({
layout: false,
params: params,
list: result,
isApp: req.query.app_version || false
}));
});
};
... ...
... ... @@ -85,7 +85,7 @@ const processIndexData = (list) => {
url: data.url,
title: data.title,
articeTxt: data.intro,
articeImg: '',
src: data.src,
publishTime: data.publishTime,
viewsNum: data.viewsNum
}, avatar));
... ... @@ -101,7 +101,6 @@ const processIndexData = (list) => {
});
});
// console.log(formatData);
return formatData;
};
... ... @@ -144,6 +143,30 @@ exports.getIndexData = () => {
};
/**
* 明星专题
*/
exports.getDetailData = (params) => {
return api.get('', sign.apiSign({
method: 'app.starClass.lastTagArticle',
tag: params.tag,
page: params.page || 1,
size: 10
})).then((result) => {
if (result && result.code === 200) {
if (params.page > result.data.totalPage) {
return '';
} else {
return camelCase(result.data.list);
}
} else {
logger.error('明星专题文章数据返回 code 不是 200');
return [];
}
});
};
/**
* 星专题
*/
exports.getSpecialData = () => {
... ...
... ... @@ -14,6 +14,7 @@ const router = express.Router(); // eslint-disable-line
router.get('/star', star.index); // 星潮教室首页
router.get('/star/detail', star.detail); // 明星文章专区
router.get('/star/detailList', star.detailList); // 明星文章专区文章Ajax请求
router.get('/star/special', star.special); // 星潮教室星专题
router.get('/star/collocation', star.collocation); // 星潮教室星搭配
router.get('/star/collocation/list', star.collocationList); // 星潮教室星搭配文章请求
... ...
<div class="star-page yoho-page">
<ul class="detail-list">
<ul class="detail-list" data-name="{{title}}">
{{> star/list}}
</ul>
</div>
\ No newline at end of file
... ...
... ... @@ -13,7 +13,7 @@
<ul class="clearfix swiper-wrapper">
{{# starAvatar}}
<li class="swiper-slide">
<img class="swiper-lazy" data-url="{{url}}" data-src="{{image cover 180 180}}">
<img class="swiper-lazy rank-avatar" data-url="{{url}}" data-src="{{image cover 180 180}}">
<div class="swiper-lazy-preloader"></div>
</li>
{{/ starAvatar}}
... ... @@ -30,9 +30,8 @@
{{#each tags}}
<li class="swiper-slide">
<a href="{{avatarUrl}}">
<img class="swiper-lazy" data-src="{{image cover 100 100}}" />
<img data-avatar="{{image cover 100 100}}" class="rank-avatar" />
<p class="name">{{tagName}}</p>
<div class="swiper-lazy-preloader"></div>
</a>
</li>
{{/each}}
... ... @@ -41,7 +40,7 @@
{{else}}
{{# tags}}
<a href="{{avatarUrl}}">
<img class="lazy" data-original="{{image cover 100 100}}" />
<img data-avatar="{{image cover 100 100}}" class="rank-avatar" />
<p class="name">{{tagName}}</p>
</a>
{{/ tags}}
... ... @@ -53,11 +52,14 @@
<div class="artice-cont">
<a href="{{url}}"><p>{{articeTxt}}</p></a>
<div class="artice-imgs-area">
<ul class="artice-imgs">
<img src="{{image src 266 266}}" />
{{!-- <ul class="artice-imgs">
{{#each articeImg}}
<li><img src="{{image . 640 640}}" /></li>
{{/each}}
</ul>
</ul> --}}
</div>
</div>
<div class="artice-o">
... ...
... ... @@ -13,7 +13,7 @@ module.exports = {
port: 6001,
siteUrl: '//m.yohobuy.com',
domains: {
api: 'http://testapi.yoho.cn:28078/', // http://192.168.102.205:8080/gateway
api: 'http://devapi.yoho.cn:58078/', // http://192.168.102.205:8080/gateway http://testapi.yoho.cn:28078/
service: 'http://testservice.yoho.cn:28077/'
},
useOneapm: false,
... ...
... ... @@ -26,7 +26,7 @@
<link rel="apple-touch-startup-image" sizes="640x920" href="http://static.yohobuy.com/m/v1/img/startup/startup-retina.png" media="screen and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)">
<link rel="apple-touch-startup-image" sizes="320x460" href="http://static.yohobuy.com/m/v1/img/startup/startup.png" media="screen and (max-device-width: 320)">
</head>
<body {{#if isPassportPage}}class=passport-body{{/if}} {{#if isStarIndexPage}} class="star-index-bg"{{/if}}>
<body {{#if isPassportPage}}class=passport-body{{/if}} {{#if isStarIndexPage}} class="star-index-bg"{{/if}} {{#if isStarDetailPage}}class="star-class-body"{{/if}}>
<div class="main-wrap">
{{#if systemUpdate}}
{{> updata}}
... ...
/**
* 页面公共逻辑
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/21
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer');
var $footer = $('#yoho-footer'),
$yohoPage = $('.yoho-page'),
$header = $('.yoho-header');
function cookie(name) {
var cookies = document.cookie,
cookieVal,
offset;
if (document.cookie && document.cookie !== '') {
offset = cookies.indexOf(name + '=');
if (offset > -1) {
offset += name.length + 1;
cookieVal = decodeURIComponent($.trim(cookies.substring(offset, cookies.indexOf(';', offset))));
}
}
return cookieVal;
}
function setCookie(name, value, options) {
var expires = '',
path,
domain,
secure,
date;
if (typeof value !== 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
if (options.expires &&
(typeof options.expires === 'number' || options.expires.toUTCString)) {
if (typeof options.expires === 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
path = options.path ? '; path=' + options.path : '';
domain = options.domain ? '; domain=' + options.domain : '';
secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
}
function isCookiesEnabled() {
var cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (typeof navigator.cookieEnabled === 'undefined' && !cookieEnabled) {
document.cookie = 'testcookie';
cookieEnabled = (document.cookie.indexOf('testcookie') !== -1) ? true : false;
}
return (cookieEnabled);
}
function getUser() {
var c = cookie('_UID'),
user;
if (typeof c === 'undefined') {
return 0;
}
user = c.split('::');
if (typeof user === 'undefined' || user.length < 4) {
return 0;
}
return user;
}
function getUid() {
var user = getUser();
if (user === 0) {
return 0;
}
return user[1];
}
function getShoppingKey() {
var c = cookie('_g');
if (typeof c === 'undefined') {
return '';
}
return JSON.parse(c).k;
}
// 根据页面内容重新设置通用底部的显示
function rePosFooter() {
var winH;
if ($footer.length === 0) {
return;
}
winH = Math.min($(window).height(), window.screen.availHeight);
if ($('body').height() <= winH - parseInt($footer.css('height'), 0)) {
$footer.addClass('bottom');
} else {
$footer.removeClass('bottom');
}
}
/**
*
* add extra margin-bottom for footer to show yoho copyright when there is fixed bottom element on page
* @param {String} The jquery selecor of the fixed bottom element
* @return undefined
*/
function reMarginFooter(fixedElement) {
var fixedElH = $(fixedElement).outerHeight();
if (fixedElement) {
$footer.css('margin-bottom', fixedElH + 'px');
}
}
// 页面通用底部位置及status设置
(function() {
var $op = $footer.children('.op-row'),
$backToTop = $('.back-to-top');
var user = getUser();
var backToTopHammer;
rePosFooter(); // 计算底部位置
if (user === 0) {
// 未登录
$op.prepend(
'<a href="http://m.yohobuy.com/signin.html?refer=' + location.href + '">登录</a>' +
'<span class="sep-line">|</span>' +
'<a href="http://m.yohobuy.com/reg.html">注册</a>'
);
} else {
// 已登录
$op.prepend(
'<span>Hi,</span>' +
'<a class="user-name" href="http://m.yohobuy.com/home?tmp=' + Math.random() + '">' + user[0] + '</a>' +
'<a href="http://m.yohobuy.com/passport/signout/index">退出</a>'
);
}
if ($backToTop.length > 0) {
backToTopHammer = new Hammer($backToTop[0]);
backToTopHammer.on('tap', function(e) {
$(window).scrollTop(0);
e.srcEvent.preventDefault();
return false;
});
}
$footer.removeClass('hide');
}());
(function(w, d, s, j, f) {
var a = d.createElement(s);
var m = d.getElementsByTagName(s)[0];
w.YohoAcquisitionObject = f;
w[f] = function() {
w[f].p = arguments;
};
a.async = 1;
a.src = j;
m.parentNode.insertBefore(a, m);
}(window, document, 'script', 'http://cdn.yoho.cn/yas-jssdk/1.0.14/yas.js', '_yas'));
(function() {
var uid = getUid();
uid = uid === 0 ? '' : uid;
window._ozuid = uid;// 暴露ozuid
if (window._yas) {
window._yas(1 * new Date(), '1.0.14', 'yohobuy_m', uid, '', '');
}
}());
$header.on('touchstart', 'a', function() {
$header.find('a').removeClass('highlight');
$(this).addClass('highlight');
}).on('touchend touchcancel', 'a', function() {
$(this).removeClass('highlight');
});
$yohoPage.on('touchstart', '.tap-hightlight', function() {
$(this).siblings('.tap-hightlight').removeClass('highlight');
$(this).addClass('highlight');
}).on('touchend touchcancel', '.tap-hightlight', function() {
$(this).removeClass('highlight');
});
$('.nav-home').on('touchstart', function() {
$('.homebuttom').toggleClass('hide');
});
(function() {
var lastTime = 0,
prefixes = 'webkit moz ms o'.split(' '),
requestAnimationFrame = window.requestAnimationFrame,
cancelAnimationFrame = window.cancelAnimationFrame,
prefix,
i;
// 通过遍历各浏览器前缀,来得到requestAnimationFrame和cancelAnimationFrame在当前浏览器的实现形式
for (i = 0; i < prefixes.length; i++) {
if (requestAnimationFrame && cancelAnimationFrame) {
break;
}
prefix = prefixes[i];
requestAnimationFrame = requestAnimationFrame || window[prefix + 'RequestAnimationFrame'];
cancelAnimationFrame = cancelAnimationFrame || window[prefix + 'CancelAnimationFrame'] ||
window[prefix + 'CancelRequestAnimationFrame'];
}
// 如果当前浏览器不支持requestAnimationFrame和cancelAnimationFrame,则会退到setTimeout
if (!requestAnimationFrame || !cancelAnimationFrame) {
requestAnimationFrame = function(callback) {
var currTime = new Date().getTime();
// 为了使setTimteout的尽可能的接近每秒60帧的效果
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
cancelAnimationFrame = function(id) {
window.clearTimeout(id);
};
}
window.requestAnimationFrame = requestAnimationFrame;
window.cancelAnimationFrame = cancelAnimationFrame;
}());
// 给jQuery 扩展 queryString函数
$.extend({
queryString: function() {
var vars = [],
hash,
i;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
});
// 临时修改 footer
function phoneHidden(phone) {
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
if ($footer.find('.user-name').text().length === 11) {
$footer.find('.user-name').html(phoneHidden($footer.find('.user-name').text()));
}
// 暴露公共接口
window.cookie = cookie;
window.setCookie = setCookie;
window.isCookiesEnabled = isCookiesEnabled;
window.getUser = getUser;
window.getUid = getUid;
window.getShoppingKey = getShoppingKey;
window.rePosFooter = rePosFooter;
window.reMarginFooter = reMarginFooter;
... ...
... ... @@ -13,9 +13,9 @@ var $ = require('yoho-jquery'),
var stopLoading = false,
page = 1;
ellipsis.init();
require('./list-common');
$('body').addClass('star-class-body');
ellipsis.init();
function massageAJAX(pageData) {
var $this, $title, $cont;
... ... @@ -65,24 +65,6 @@ function scrollHandler() {
}
}
// 分享成功
window.successShare = function() {
$.ajax({
type: 'POST',
url: '/guang/starclass/forward',
success: function(data) {
var code = data.code;
if (code === 200 && data.data > 0) {
tip.show('分享成功,亲密度+10');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
};
$(window).scroll(function() {
scrollHandler();
});
... ... @@ -90,51 +72,3 @@ $(window).scroll(function() {
if ($('.collocation-list').find('li').length === 0) {
massageAJAX(1);
}
// 星搭配收藏请求
$(document).on('click', '.collection', function() {
var $that = $(this),
$icon = $that.find('.collected-ico');
var type;
if ($icon.hasClass('collected')) {
type = 'del';
} else {
type = 'fav';
}
$.ajax({
type: 'POST',
url: '/guang/starclass/setFavorite',
data: {
articleId: $that.parents('li').attr('articleId'),
type: type
},
success: function(data) {
var code = data.code;
if (code === 200) {
if ($icon.hasClass('collected')) {
$icon.removeClass('collected');
} else {
$icon.addClass('collected');
}
}
if (code === 201) {
if ($('#collocation-link').length <= 0) {
$('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' +
'<span class="collocation-link"></span></a>');
}
$('.collocation-link').click();
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
... ...
/**
* 星潮教室-明星专题列表
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/6/7
*/
var $ = require('yoho-jquery'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading'),
lazyLoad = require('yoho-jquery-lazyload'),
ellipsis = require('yoho-mlellipsis');
var $detailList = $('.detail-list'),
stopLoading = false,
page = 1;
require('./list-common');
ellipsis.init();
// 翻页
function massageAJAX(pageData) {
var $this, $title, $cont;
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: '/guang/star/detailList',
data: {
page: pageData,
tag: $('.detail-list').data('name')
},
dataType: 'html',
success: function(data) {
stopLoading = false;
if (data === '') {
stopLoading = true;
tip.show('没有更多内容了');
}
$('.detail-list').append(data);
// 限制标题字数
$('.cont-area').each(function() {
$this = $(this);
$title = $this.find('.title');
$cont = $this.find('.cont-txt');
$title[0].mlellipsis(2);
$cont[0].mlellipsis(2);
});
lazyLoad($('img.lazy'));
loading.hideLoadingMask();
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
function scrollHandler() {
if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) {
stopLoading = true;
page++;
massageAJAX(page);
}
}
$(window).scroll(function() {
scrollHandler();
});
if ($detailList.find('li').length === 0) {
massageAJAX(1);
}
... ...
/**
* 星潮教室-列表公共部分
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/6/7
*/
var $ = require('yoho-jquery'),
tip = require('../plugin/tip');
require('../common/common');
// 星搭配收藏请求
$(document).on('touchstart', '.collection', function(event) {
var $that = $(this),
$icon = $that.find('.collected-ico');
var type;
event.stopPropagation();
if ($icon.hasClass('collected')) {
type = 'del';
} else {
type = 'fav';
}
$.ajax({
type: 'POST',
url: '/guang/starclass/setFavorite',
data: {
articleId: $that.parents('li').attr('articleId'),
type: type
},
success: function(data) {
var code = data.code;
if (code === 200) {
if ($icon.hasClass('collected')) {
$icon.removeClass('collected');
} else {
$icon.addClass('collected');
}
}
if (code === 201) {
if ($('#collocation-link').length <= 0) {
$('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' +
'<span class="collocation-link"></span></a>');
}
$('.collocation-link').click();
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
// 分享成功
window.successShare = function() {
$.ajax({
type: 'POST',
url: '/guang/starclass/forward',
success: function(data) {
var code = data.code;
if (code === 200 && data.data > 0) {
tip.show('分享成功,亲密度+10');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
};
... ...
... ... @@ -11,14 +11,21 @@ var $ = require('yoho-jquery'),
PullRefresh = require('../plugin/pull-refresh');
var $window = $(window),
$starArticle = $('.star-article'),
$starArticle = $('.star-article');
/*
$swiperView = $('.swiper-view'),
$viewImg = $('.view-img'),
$body = $('body'),
imgs = [],
allImgs = {};
var avatarSwiper, avatarKey, mySwiper;
var mySwiper;
*/
var avatarSwiper, avatarKey;
require('../common/common');
lazyLoad($('img.lazy'));
ellipsis.init();
... ... @@ -47,6 +54,18 @@ $(function() {
});
});
// 设置默认头像
function setAvatar($userAvatar) {
var myImage = new Image(),
avatar;
// 部分老用户没有头像,显示默认头像
avatar = $userAvatar.data('avatar');
myImage.src = avatar;
myImage.onload = function() {
$userAvatar.css('background-image', 'url(' + avatar + ')');
};
}
// 限制标题字数
function txtLimit(dom) {
... ... @@ -58,6 +77,7 @@ function txtLimit(dom) {
}
// 明星动态文章图片相关操作
/*
function articleImgAction(dom, key) {
var $articeImgs = dom.find('.artice-imgs'),
$li = $articeImgs.find('li'),
... ... @@ -111,7 +131,7 @@ function articleImgAction(dom, key) {
addFlagDom.append('<div class="img-size"><i class="pic-icon"></i>' + imgLen + '</div>');
}
}
*/
// banner swiper 初始化
if ($('.banner-swiper .swiper-slide').length > 1) {
... ... @@ -154,13 +174,16 @@ if ($('.article-avatar-swiper').find('li').length > 1) {
});
}
if ($('.star-info').find('li').length > 0) {
$starArticle.each(function(key, item) {
txtLimit($(item));
articleImgAction($(item), key);
// articleImgAction($(item), key);
});
}
// 明星头像点击居中显示或跳转
$('.avatar-swiper li').on('click', function() {
if ($(this).hasClass('swiper-slide-active')) {
... ... @@ -170,3 +193,10 @@ $('.avatar-swiper li').on('click', function() {
avatarSwiper.slideTo(avatarKey, 1000, false);
}
});
$('.rank-avatar').each(function(key, item) {
if ($(item).attr('data-avatar') !== '') {
setAvatar($(item));
}
});
... ...
... ... @@ -216,6 +216,12 @@
.artice-imgs-area {
width: 100%;
overflow: hidden;
img {
width: 266px;
float: left;
margin: 25px 0;
}
}
.artice-imgs {
... ... @@ -335,6 +341,13 @@
}
}
}
.rank-avatar {
background-image: resolve("guang/star/user-avatar.png");
background-repeat: no-repeat;
background-size: contain;
float: left;
}
}
.star-index-bg {
... ...