Authored by 郝肖肖

'news-详情页'

@@ -27,8 +27,19 @@ exports.index = (req, res, next) => { @@ -27,8 +27,19 @@ exports.index = (req, res, next) => {
27 */ 27 */
28 exports.detail = (req, res, next) => { 28 exports.detail = (req, res, next) => {
29 let channel = req.yoho.channel; 29 let channel = req.yoho.channel;
  30 + let id = req.params[0] || 0;
  31 + let cid = req.params[1] || 0;
  32 + let query = {
  33 + channel: channel,
  34 + id: id,
  35 + cid: cid,
  36 + };
30 37
31 - req.ctx(newsService).detail(channel, req.query).then(result => { 38 + if (!id || !cid) {
  39 + return next();
  40 + }
  41 +
  42 + req.ctx(newsService).detail(channel, query).then(result => {
32 return res.render('news-detail', Object.assign({ 43 return res.render('news-detail', Object.assign({
33 title: '新闻详情页 | ' + (res.locals.title || ''), 44 title: '新闻详情页 | ' + (res.locals.title || ''),
34 module: 'news', 45 module: 'news',
@@ -82,7 +82,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -82,7 +82,7 @@ module.exports = class extends global.yoho.BaseModel {
82 url: helpers.urlFormat(`/news/${articleData.id}_${articleData.cid}.html`), 82 url: helpers.urlFormat(`/news/${articleData.id}_${articleData.cid}.html`),
83 img: helpers.image(articleData.image, width, height, 1), 83 img: helpers.image(articleData.image, width, height, 1),
84 title: articleData.title, 84 title: articleData.title,
85 - pTime: moment(articleData.update_time * 1000).format('YYYY年MM月DD HH:mm'), 85 + pTime: articleData.update_time && moment(articleData.update_time * 1000).format('YYYY年MM月DD HH:mm'),
86 pView: articleData.views_num, 86 pView: articleData.views_num,
87 content: articleData.summary, 87 content: articleData.summary,
88 isVideo: articleData.videoUrl ? true : false 88 isVideo: articleData.videoUrl ? true : false
@@ -127,12 +127,12 @@ module.exports = class extends global.yoho.BaseModel { @@ -127,12 +127,12 @@ module.exports = class extends global.yoho.BaseModel {
127 127
128 let apiMethod = [ 128 let apiMethod = [
129 headerModel.requestHeaderData(channel), 129 headerModel.requestHeaderData(channel),
130 - newsAPi.getPolymerizationList(params),  
131 newsAPi.getRecoArticles(params), 130 newsAPi.getRecoArticles(params),
132 newsAPi.getAds({ 131 newsAPi.getAds({
133 content_code: ADS_CODE[channel] || ADS_CODE.boys, 132 content_code: ADS_CODE[channel] || ADS_CODE.boys,
134 isAdDegrade: _.get(this.ctx, 'req.app.locals.pc.guang.removeAd', false) 133 isAdDegrade: _.get(this.ctx, 'req.app.locals.pc.guang.removeAd', false)
135 }), 134 }),
  135 + newsAPi.getPolymerizationList(params),
136 ]; 136 ];
137 137
138 return Promise.all(apiMethod).then(result => { 138 return Promise.all(apiMethod).then(result => {
@@ -141,14 +141,14 @@ module.exports = class extends global.yoho.BaseModel { @@ -141,14 +141,14 @@ module.exports = class extends global.yoho.BaseModel {
141 // 头部数据 141 // 头部数据
142 Object.assign(responseData, result[0]); 142 Object.assign(responseData, result[0]);
143 143
144 - // 列表数据  
145 - Object.assign(responseData, this._formatArticle(result[1], params));  
146 -  
147 // 获取精彩推荐 144 // 获取精彩推荐
148 - Object.assign(responseData, this._formatRecoArticles(result[2])); 145 + Object.assign(responseData, this._formatRecoArticles(result[1]));
149 146
150 // 获取广告数据 147 // 获取广告数据
151 - Object.assign(responseData, this._formatAds(result[3])); 148 + Object.assign(responseData, this._formatAds(result[2]));
  149 +
  150 + // 列表数据
  151 + Object.assign(responseData, this._formatArticle(result[3], params));
152 152
153 // 导航pathNav 153 // 导航pathNav
154 Object.assign(responseData, this.getPathNav(channel)); 154 Object.assign(responseData, this.getPathNav(channel));
@@ -157,29 +157,54 @@ module.exports = class extends global.yoho.BaseModel { @@ -157,29 +157,54 @@ module.exports = class extends global.yoho.BaseModel {
157 }); 157 });
158 } 158 }
159 159
  160 + _formatDetail(rdata) {
  161 + let contents = _.get(rdata, 'data.contents', {});
  162 + let header = {
  163 + title: contents.title,
  164 + time: contents.update_time && moment(contents.update_time * 1000).format('YYYY年MM月DD HH:mm'),
  165 + };
  166 +
  167 + return {header: header, content: contents.content};
  168 + }
  169 +
160 detail(channel, param) { 170 detail(channel, param) {
161 let params = { 171 let params = {
162 - id: param.id || 20735,  
163 - cid: param.cid || 11893 172 + id: param.id,
  173 + cid: param.cid
164 }; 174 };
  175 + let newsAPi = new NewsAPi(this.ctx);
165 let apiMethod = [ 176 let apiMethod = [
166 headerModel.requestHeaderData(channel), 177 headerModel.requestHeaderData(channel),
167 - new NewsAPi(this.ctx).getContentDetail(params) 178 + newsAPi.getRecoArticles(params),
  179 + newsAPi.getAds({
  180 + content_code: ADS_CODE[channel] || ADS_CODE.boys,
  181 + isAdDegrade: _.get(this.ctx, 'req.app.locals.pc.guang.removeAd', false)
  182 + }),
  183 + newsAPi.getContentDetail(params)
168 ]; 184 ];
169 185
170 return Promise.all(apiMethod).then(result => { 186 return Promise.all(apiMethod).then(result => {
171 let responseData = {}; 187 let responseData = {};
172 188
  189 + // 头部数据
  190 + Object.assign(responseData, result[0]);
  191 +
  192 + // 获取精彩推荐
  193 + Object.assign(responseData, this._formatRecoArticles(result[1]));
  194 +
  195 + // 获取广告数据
  196 + Object.assign(responseData, this._formatAds(result[2]));
  197 +
  198 + // 列表数据
  199 + Object.assign(responseData, this._formatDetail(result[3], params));
  200 +
173 // 导航pathNav 201 // 导航pathNav
174 Object.assign(responseData, this.getPathNav(channel, [{ 202 Object.assign(responseData, this.getPathNav(channel, [{
175 href: helpers.urlFormat('/news'), 203 href: helpers.urlFormat('/news'),
176 - name: '新闻详情页',  
177 - pathTitle: '新闻详情页' 204 + name: _.get(responseData, 'header.title', '新闻详情页'),
  205 + pathTitle: _.get(responseData, 'header.title', '新闻详情页')
178 }])); 206 }]));
179 207
180 - // 头部数据  
181 - Object.assign(responseData, result[0]);  
182 -  
183 return responseData; 208 return responseData;
184 }); 209 });
185 } 210 }
@@ -12,7 +12,7 @@ const cRoot = './controllers'; @@ -12,7 +12,7 @@ const cRoot = './controllers';
12 const newsController = require(`${cRoot}/index`); 12 const newsController = require(`${cRoot}/index`);
13 13
14 router.get(['/', '/index/index'], newsController.index); 14 router.get(['/', '/index/index'], newsController.index);
15 -router.get(/^\/news\/([\d]+)_([\d]+).html/, newsController.detail); 15 +router.get(/\/([\d]+)_([\d]+).html/, newsController.detail);
16 16
17 17
18 // ajax 18 // ajax
@@ -4,112 +4,35 @@ @@ -4,112 +4,35 @@
4 {{# header}} 4 {{# header}}
5 <h1 class="detail-title">{{title}}</h1> 5 <h1 class="detail-title">{{title}}</h1>
6 <div class="article-info clearfix"> 6 <div class="article-info clearfix">
7 - <div class="article-author">  
8 - <div class="author-avatar">  
9 - <a href="{{authorUrl}}" target="_blank">  
10 - <img src="{{image2 avatar}}">  
11 - </a> 7 + {{#if authorUrl}}
  8 + <div class="article-author">
  9 + <div class="author-avatar">
  10 + <a href="{{authorUrl}}" target="_blank">
  11 + <img src="{{image2 avatar}}">
  12 + </a>
  13 + </div>
12 </div> 14 </div>
13 - </div>  
14 - <div class="author-info">  
15 - <a class="author-name" href="{{authorUrl}}">{{name}}</a>  
16 - </div> 15 + <div class="author-info">
  16 + <a class="author-name" href="{{authorUrl}}">{{name}}</a>
  17 + </div>
  18 + {{/if}}
17 <div class="article-status clearfix"> 19 <div class="article-status clearfix">
18 - <span class="article-time">{{time}}</span>  
19 - <span class="article-click">点击:<em>{{click}}</em></span>  
20 - <a href="#comment-info" id="article-comment" class="article-comment"><em class="comment-num">{{commentNum}}</em>条评论</a> 20 + <span class="article-time">
  21 + <i class="iconfont">&#xe625;</i>
  22 + {{time}}
  23 + </span>
  24 + {{#if click}}
  25 + <span class="article-click">点击:<em>{{click}}</em></span>
  26 + {{/if}}
  27 + {{#if commentNum}}
  28 + <a href="#comment-info" id="article-comment" class="article-comment"><em class="comment-num">{{commentNum}}</em>条评论</a>
  29 + {{/if}}
21 </div> 30 </div>
22 </div> 31 </div>
23 {{/ header}} 32 {{/ header}}
24 33
25 <div class="article-main"> 34 <div class="article-main">
26 - {{# content}}  
27 - {{# video}}  
28 - <div class="article-video block">  
29 - {{{.}}}  
30 - </div>  
31 - {{/ video}}  
32 - {{# pic}}  
33 - <div class="article-pic block">  
34 - <img class="lazy" data-original="{{image2 .}}">  
35 - </div>  
36 - {{/ pic}}  
37 - {{# text}}  
38 - <div class="article-text block">  
39 - <p>{{{.}}}</p>  
40 - </div>  
41 - {{/ text}}  
42 - {{#if smallPic}}  
43 - <div class="article-small-pic block clearfix">  
44 - {{# smallPic}}  
45 - <img class="lazy" data-original="{{image2 .}}">  
46 - {{/ smallPic}}  
47 - </div>  
48 - {{/if}}  
49 - {{# relatedReco}}  
50 - <div class="related-reco block clearfix">  
51 - <div class="block-header">  
52 - 相关推荐  
53 - {{# moreReco}}  
54 - <a class="more-reco" href="{{.}}">MORE ></a>  
55 - {{/ moreReco}}  
56 - </div>  
57 - <div class="recos clearfix">  
58 - {{# recos}}  
59 - {{> product/good}}  
60 - {{/ recos}}  
61 - </div>  
62 - </div>  
63 - {{/ relatedReco}}  
64 - {{/ content}}  
65 - </div>  
66 - {{#if brands}}  
67 - <div class="related-brand block clearfix">  
68 - <div class="block-header">相关品牌</div>  
69 - <div class="brands">  
70 - {{# brands}}  
71 - <div class="brand">  
72 - <a class="thumb" href="{{url}}" target="_blank">  
73 - <img class="lazy" data-original="{{image2 thumb}}">  
74 - </a>  
75 - <p class="brand-name">{{name}}</p>  
76 - </div>  
77 - {{/ brands}}  
78 - </div>  
79 - </div>  
80 - {{/if}}  
81 - {{# userInfo}}  
82 - <div class="user-handle">  
83 - <ul class="clearfix">  
84 - <li id="prise-btn" class="like-status{{#isLike}} liked{{/isLike}}">  
85 - <a href="javascript:;">  
86 - <i class="iconfont">&#xe626;</i>  
87 - <span class="like-num">{{likeNum}}</span>  
88 - </a>  
89 - </li>  
90 - <li id="collect-btn" class="sort-collect{{#isCollected}} collected{{/isCollected}}">  
91 - <a href="javascript:;">  
92 - <i class="iconfont">&#xe611;</i>  
93 - <span>收藏</span>  
94 - <span class="cancel-collect">取消收藏</span>  
95 - </a>  
96 - </li>  
97 - </ul>  
98 - </div>  
99 - {{/ userInfo}}  
100 - <div class="article-bottom-info clearfix">  
101 - {{#if tag}}  
102 - <div class="article-tag clearfix">  
103 - <i class="tag-icon iconfont">&#xe630;</i>  
104 - <ul class="clearfix">  
105 - {{# tag}}  
106 - <li>  
107 - <a href="{{url}}" target="_blank">{{name}}</a>  
108 - </li>  
109 - {{/ tag}}  
110 - </ul>  
111 - </div>  
112 - {{/if}} 35 + {{{content}}}
113 </div> 36 </div>
114 37
115 </div> 38 </div>
1 -var $ = require('yoho-jquery'),  
2 - lazyLoad = require('yoho-jquery-lazyload');  
3 -  
4 require('../common'); 1 require('../common');
  2 +
  3 +require('./img-blink');
  4 +
  5 +require('./right-side');
@@ -10,6 +10,11 @@ @@ -10,6 +10,11 @@
10 font-style: italic; 10 font-style: italic;
11 } 11 }
12 12
  13 + i.iconfont {
  14 + color: #ccc;
  15 + font-style: normal;
  16 + }
  17 +
13 .block { 18 .block {
14 margin: 15px 0; 19 margin: 15px 0;
15 } 20 }