Authored by 郝肖肖

'news-page'

... ... @@ -13,7 +13,7 @@ const newsService = require('../models/news-service');
exports.index = (req, res, next) => {
let channel = req.yoho.channel;
req.ctx(newsService).getIndexList(channel, req.body).then(result => {
req.ctx(newsService).getIndexList(channel, req.query).then(result => {
return res.render('news-index', Object.assign({
title: '新闻 | ' + (res.locals.title || ''),
module: 'news',
... ... @@ -28,7 +28,7 @@ exports.index = (req, res, next) => {
exports.detail = (req, res, next) => {
let channel = req.yoho.channel;
req.ctx(newsService).detail(channel, req.body).then(result => {
req.ctx(newsService).detail(channel, req.query).then(result => {
return res.render('news-detail', Object.assign({
title: '新闻详情页 | ' + (res.locals.title || ''),
module: 'news',
... ...
... ... @@ -26,4 +26,38 @@ module.exports = class extends global.yoho.BaseModel {
api: global.yoho.YohoNowApi
});
}
/**
* 推荐文章
*/
getRecoArticles(params) {
return this.get({
url: 'guang/api/v2/article/getArticleByViewsNum',
data: params,
param: {
cache: true
},
api: global.yoho.ServiceAPI
});
}
/**
* 获取广告数据
* @param {String} channelType 传入频道页类型,值可以是: boys, girls, kids, lifestyle
* @return {Object}
*/
getAds(params) {
if (params.isAdDegrade) {
return Promise.resolve({});
}
return this.get({
url: 'operations/api/v5/resource/get',
data: params,
param: {
cache: true
},
api: global.yoho.ServiceAPI
});
}
};
... ...
... ... @@ -4,12 +4,23 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const headerModel = require('../../../doraemon/models/header');
const NewsAPi = require('./news-api');
const moment = require('moment');
const searchHandler = require('../../product/models/search-handler');
console.log(global.utils);
const BOYS = 'boys';
const GIRLS = 'girls';
const KIDS = 'kids';
const LIFESTYLE = 'lifestyle';
// 逛 ads code
const ADS_CODE = {
boys: '41777aa7ac86347692c5aa0d394b2f59',
girls: '722253573823ebb994e313e71b0a4fb9',
lifestyle: '02568b6042510e4be739cc688dc7d6ae',
kids: '1ffdd6ea22c58af52ee6408cd353c2d5'
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ... @@ -54,9 +65,10 @@ module.exports = class extends global.yoho.BaseModel {
return {pathNav: pathNav};
}
_formatArticle(rdata) {
_formatArticle(rdata, params) {
let list = _.get(rdata, 'data.content', []);
let total = _.get(rdata, 'data.total', 0);
let pagerData = searchHandler.handlePagerData(total, params);
let lresult = {};
let width = 360;
let height = 240;
... ... @@ -70,7 +82,7 @@ module.exports = class extends global.yoho.BaseModel {
url: helpers.urlFormat(`/news/${articleData.id}_${articleData.cid}.html`),
img: helpers.image(articleData.image, width, height, 1),
title: articleData.title,
pTime: articleData.update_time,
pTime: moment(articleData.update_time * 1000).format('YYYY年MM月DD HH:mm'),
pView: articleData.views_num,
content: articleData.summary,
isVideo: articleData.videoUrl ? true : false
... ... @@ -79,32 +91,68 @@ module.exports = class extends global.yoho.BaseModel {
return lresult;
});
return {msgs: result, total: total};
return {msgs: result, totalCount: total, footPager: pagerData};
}
_formatAds(res) {
let list = _.map(_.get(res, 'data[0].data', []), (it) => {
return {
img: helpers.image(it.src, 640, 640, 1),
url: it.url
};
});
return {ads: (list.length > 5 ? list.slice(0, 4) : list)};
}
_formatRecoArticles(res) {
let ldata = _.map(_.get(res, 'data', []), it => {
return {
url: helpers.urlFormat(`/guang/${it.id}.html`),
title: it.title,
img: it.src && helpers.image(it.src, 90, 60, 1) || ''
};
});
return {exRecos: ldata};
}
getIndexList(channel, param) {
let newsAPi = new NewsAPi(this.ctx);
let params = {
type: 'wechat',
limit: 20,
page: param.page || 1
};
let apiMethod = [
headerModel.requestHeaderData(channel),
new NewsAPi(this.ctx).getPolymerizationList(params)
newsAPi.getPolymerizationList(params),
newsAPi.getRecoArticles(params),
newsAPi.getAds({
content_code: ADS_CODE[channel] || ADS_CODE.boys,
isAdDegrade: _.get(this.ctx, 'req.app.locals.pc.guang.removeAd', false)
}),
];
return Promise.all(apiMethod).then(result => {
let responseData = {};
// 头部数据
Object.assign(responseData, result[0]);
// 列表数据
Object.assign(responseData, this._formatArticle(result[1]));
Object.assign(responseData, this._formatArticle(result[1], params));
// 获取精彩推荐
Object.assign(responseData, this._formatRecoArticles(result[2]));
// 获取广告数据
Object.assign(responseData, this._formatAds(result[3]));
// 导航pathNav
Object.assign(responseData, this.getPathNav(channel));
// 头部数据
Object.assign(responseData, result[0]);
return responseData;
});
}
... ...
... ... @@ -4,12 +4,13 @@
<div id="pjax-container" class="msg">
<div id="msg-list" class="msg-list">
{{# msgs}}
{{> msg}}
{{> news-msg}}
{{/ msgs}}
</div>
{{> common/foot-pager}}
</div>
</div>
<div class="right-side">
{{> right-side}}
{{> news-right-side}}
</div>
</div>
... ...
... ... @@ -14,17 +14,21 @@
<div class="msg-info">
<a class="msg-title" href="{{url}}" target="_blank">{{title}}</a>
<p class="msg-app">
<a href="{{editorUrl}}" target="_blank">
<span class="author">{{author}}</span>
</a>
{{#if editorUrl}}
<a href="{{editorUrl}}" target="_blank">
<span class="author">{{author}}</span>
</a>
{{/if}}
<span class="publish-time">
<i class="iconfont">&#xe625;</i>
{{pTime}}
</span>
<span class="page-view">
<i class="iconfont">&#xe627;</i>
<em>{{pView}}</em>
</span>
{{#if pView}}
<span class="page-view">
<i class="iconfont">&#xe627;</i>
<em>{{pView}}</em>
</span>
{{/if}}
</p>
<p class="content">{{content}}</p>
{{!----
... ...
... ... @@ -3,9 +3,11 @@
<div id="ex-reco-list" class="ex-reco-list">
{{# exRecos}}
<div class="ex-reco-item clearfix">
<a class="ex-reco-img" href="{{url}}" target="_blank">
<span class="bg-img" style="background-image:url({{image2 img}})"></span>
</a>
{{#if img}}
<a class="ex-reco-img" href="{{url}}" target="_blank">
<span class="bg-img" style="background-image:url({{image2 img}})"></span>
</a>
{{/if}}
<a href="{{url}}" target="_blank">
<p class="ex-reco-context">{{title}}</p>
</a>
... ...
/**
* 图片移入闪动效果JS
* @auhor: xuqi<qi.xu@yoho.cn>
* @date: 2015/7/29
*/
var $ = require('yoho-jquery');
$('.news-page').on('mouseover', 'a img, a .bg-img', function(e) {
var $el = $(e.target);
// slider中的图片不做此效果
if ($el.closest('.slider').length > 0) {
return;
}
$el.addClass('blink');
setTimeout(function() {
$el.removeClass('blink');
}, 100);
});
... ...
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
var msg = require('./msg');
require('../common');
require('./img-blink');
require('./right-side');
msg.dotLazy();
... ...
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
require('yoho-jquery-dotdotdot');
// 资讯文字截取和lazyload
function dotLazy() {
// 文字截取
$('.msg-title, .msg-content .content').dotdotdot({
wrap: 'letter'
});
// Lazyload
lazyLoad($('#msg-list img.lazy'));
}
exports.dotLazy = dotLazy;
... ...
/**
* 右侧栏文字截取js
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
require('yoho-jquery-dotdotdot');
$('.ex-reco-context').dotdotdot({
wrap: 'letter'
});
lazyLoad($('.ads img.lazy'));
... ...
... ... @@ -140,6 +140,10 @@
border-bottom: 1px solid #ccc;
position: relative;
&:first-child {
padding-top: 0;
}
.content {
height: 125px;
line-height: 24px;
... ... @@ -313,23 +317,4 @@
}
}
}
.pager {
font-size: 12px;
a {
height: 24px;
padding: 0 9px;
line-height: 24px;
display: inline-block;
text-align: center;
margin-right: 8px;
color: #222;
&.cur {
background-color: #222;
color: #fff;
}
}
}
}
... ...