Showing
10 changed files
with
249 additions
and
6 deletions
@@ -187,9 +187,60 @@ const tag = (req, res, next) => { | @@ -187,9 +187,60 @@ const tag = (req, res, next) => { | ||
187 | }).catch(next); | 187 | }).catch(next); |
188 | }; | 188 | }; |
189 | 189 | ||
190 | + /** | ||
191 | + * 列表页(列表首页、标签列表页、作者列表页)动态数据,如:查看数,点赞数,评论数,是否点赞,是否回复 | ||
192 | + * @param req | ||
193 | + * @param res | ||
194 | + */ | ||
195 | + const listDynamicData = (req, res) => { | ||
196 | + let ids = req.query.ids; | ||
197 | + | ||
198 | + let udid = req.sessionID; | ||
199 | + | ||
200 | + let other = {}; | ||
201 | + let query = req.query.query, | ||
202 | + type = req.query.type; | ||
203 | + | ||
204 | + if (req.user.uid) { | ||
205 | + other.uid = req.user.uid; | ||
206 | + } | ||
207 | + | ||
208 | + if (query) { | ||
209 | + other.query = query; | ||
210 | + } | ||
211 | + | ||
212 | + if (type) { | ||
213 | + other.type = type; | ||
214 | + } | ||
215 | + | ||
216 | + indexModel.getDynamicDataByIds(ids, udid, other).then(ret => { | ||
217 | + res.send(ret); | ||
218 | + }); | ||
219 | + }; | ||
220 | + | ||
221 | + /** | ||
222 | + * 详情页动态数据,如:评论数,回复数,是否点赞,是否收藏 | ||
223 | + * @param req | ||
224 | + * @param res | ||
225 | + */ | ||
226 | + const detailDynamicData = (req, res) => { | ||
227 | + | ||
228 | + let id = req.query.id, | ||
229 | + uid = req.user.uid, | ||
230 | + udid = req.sessionID; | ||
231 | + | ||
232 | + indexModel.getDynamicDataById(id, uid, udid).then((ret) => { | ||
233 | + res.status(200).send(ret); | ||
234 | + }).catch(() => { | ||
235 | + res.status(400); | ||
236 | + }); | ||
237 | + }; | ||
238 | + | ||
190 | module.exports = { | 239 | module.exports = { |
191 | editor, | 240 | editor, |
192 | pageData, | 241 | pageData, |
193 | index, | 242 | index, |
194 | - tag | 243 | + tag, |
244 | + listDynamicData, | ||
245 | + detailDynamicData | ||
195 | }; | 246 | }; |
@@ -9,6 +9,7 @@ const api = global.yoho.API; | @@ -9,6 +9,7 @@ const api = global.yoho.API; | ||
9 | const logger = global.yoho.logger; | 9 | const logger = global.yoho.logger; |
10 | const helpers = global.yoho.helpers; | 10 | const helpers = global.yoho.helpers; |
11 | const guangProcess = require(`${global.utils}/guang-process`); | 11 | const guangProcess = require(`${global.utils}/guang-process`); |
12 | +const _ = require('lodash'); | ||
12 | 13 | ||
13 | /** | 14 | /** |
14 | * [获取作者信息] | 15 | * [获取作者信息] |
@@ -65,12 +66,13 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u | @@ -65,12 +66,13 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u | ||
65 | sort_id: sortId, | 66 | sort_id: sortId, |
66 | tag: tag, | 67 | tag: tag, |
67 | author_id: authorId, | 68 | author_id: authorId, |
68 | - limit: limit | 69 | + limit: 20 |
69 | }; | 70 | }; |
70 | 71 | ||
71 | return serviceAPI.get('guang/api/v2/article/getList', param, { | 72 | return serviceAPI.get('guang/api/v2/article/getList', param, { |
72 | cache: useCache | 73 | cache: useCache |
73 | }).then((result) => { | 74 | }).then((result) => { |
75 | + console.log(result) | ||
74 | if (result && result.code === 200) { | 76 | if (result && result.code === 200) { |
75 | return result; | 77 | return result; |
76 | } else { | 78 | } else { |
@@ -297,10 +299,60 @@ const getTagEditor = (param) => { | @@ -297,10 +299,60 @@ const getTagEditor = (param) => { | ||
297 | 299 | ||
298 | }; | 300 | }; |
299 | 301 | ||
302 | + /** | ||
303 | + * 获取制指定文章的动态信息 | ||
304 | + * @param ids | ||
305 | + * @param udid | ||
306 | + * @param other [Obejct] 包含uid,query,type等非必传参数 | ||
307 | + * @returns {Promise.<T>|*} | ||
308 | + */ | ||
309 | + const getDynamicDataByIds = (ids, udid, other) => { | ||
310 | + let params = { | ||
311 | + articleIds: ids, | ||
312 | + udid: udid | ||
313 | + }; | ||
314 | + | ||
315 | + if (other.uid) { | ||
316 | + _.assign(params, { | ||
317 | + uid: other.uid | ||
318 | + }); | ||
319 | + } | ||
320 | + | ||
321 | + if (other.query) { | ||
322 | + _.assign(params, { | ||
323 | + query: other.query | ||
324 | + }); | ||
325 | + } | ||
326 | + | ||
327 | + if (other.type) { | ||
328 | + _.assign(params, { | ||
329 | + type: other.type | ||
330 | + }); | ||
331 | + } | ||
332 | + | ||
333 | + return serviceAPI.get('guang/api/*/article/getSimpleArticleList', params, {cache: true}); | ||
334 | + }; | ||
335 | + | ||
336 | + /** | ||
337 | + | ||
338 | + * 获取制指定文章的动态信息 | ||
339 | + * @param ids | ||
340 | + * @returns {Promise.<T>|*} | ||
341 | + */ | ||
342 | + const getDynamicDataById = (id, uid, udid) => { | ||
343 | + return serviceAPI.get('/gateway/guang/api/*/article/getArticlePraiseAndFavor', { | ||
344 | + id: id, | ||
345 | + uid: uid, | ||
346 | + udid: udid | ||
347 | + }); | ||
348 | + }; | ||
349 | + | ||
300 | module.exports = { | 350 | module.exports = { |
301 | getAuthor, | 351 | getAuthor, |
302 | getArticleList, | 352 | getArticleList, |
303 | getPageData, | 353 | getPageData, |
304 | getArticle, | 354 | getArticle, |
305 | - getTagEditor | 355 | + getTagEditor, |
356 | + getDynamicDataByIds, | ||
357 | + getDynamicDataById | ||
306 | }; | 358 | }; |
@@ -51,4 +51,7 @@ router.get('/plustar/brandinfo', plustar.getDetailData); // 祕 | @@ -51,4 +51,7 @@ router.get('/plustar/brandinfo', plustar.getDetailData); // 祕 | ||
51 | 51 | ||
52 | router.get('/rss', rss.index); // 订阅资讯 | 52 | router.get('/rss', rss.index); // 订阅资讯 |
53 | 53 | ||
54 | +router.get('/info/listData', index.listDynamicData); | ||
55 | +router.get('/info/detailData', index.detailDynamicData); | ||
56 | + | ||
54 | module.exports = router; | 57 | module.exports = router; |
@@ -25,6 +25,11 @@ module.exports = { | @@ -25,6 +25,11 @@ module.exports = { | ||
25 | // service: 'http://service-test1.yohops.com:9999/', | 25 | // service: 'http://service-test1.yohops.com:9999/', |
26 | // liveApi: 'http://testapi.live.yohops.com:9999/', | 26 | // liveApi: 'http://testapi.live.yohops.com:9999/', |
27 | // singleApi: 'http://api-test1.yohops.com:9999/', | 27 | // singleApi: 'http://api-test1.yohops.com:9999/', |
28 | + | ||
29 | + // favApi: 'http://192.168.102.31:8092/brower', | ||
30 | + // api: 'http://192.168.102.205:8080/gateway/', | ||
31 | + // service: 'http://192.168.102.205:8080/gateway/', | ||
32 | + // search: 'http://192.168.102.216:8080/yohosearch/' | ||
28 | }, | 33 | }, |
29 | subDomains: { | 34 | subDomains: { |
30 | host: '.m.yohobuy.com', | 35 | host: '.m.yohobuy.com', |
public/js/guang/detail-dynamic.js
0 → 100644
1 | +/** | ||
2 | + * 动态获取页面数据 | ||
3 | + * @author liuchuanyang | ||
4 | + * @date 2016/10/09 | ||
5 | + */ | ||
6 | +var $ = require('yoho-jquery'); | ||
7 | + | ||
8 | +require('../common'); | ||
9 | + | ||
10 | +function getDynamicById(id) { | ||
11 | + 'use strict'; | ||
12 | + | ||
13 | + var param = { | ||
14 | + id: id | ||
15 | + }; | ||
16 | + | ||
17 | +// //guang.yohobuy.com/guang/info/detailData | ||
18 | + return $.getJSON('/guang/info/detailData', param); | ||
19 | +} | ||
20 | + | ||
21 | +function renderData(data) { | ||
22 | + 'use strict'; | ||
23 | + | ||
24 | + if (data && data.code === 200 && data.data) { | ||
25 | + | ||
26 | + $('.guang-detail-page .page-view').text(data.data.browseNum || 0); | ||
27 | + } | ||
28 | +} | ||
29 | + | ||
30 | +function refreshData() { | ||
31 | + 'use strict'; | ||
32 | + | ||
33 | + var qs = window.queryString; | ||
34 | + | ||
35 | + var id = qs.id; | ||
36 | + | ||
37 | + getDynamicById(id).done(renderData); | ||
38 | +} | ||
39 | + | ||
40 | +refreshData(); |
@@ -22,6 +22,7 @@ var $infoList = $('#info-list'), | @@ -22,6 +22,7 @@ var $infoList = $('#info-list'), | ||
22 | curType = $curNav.data('type'); | 22 | curType = $curNav.data('type'); |
23 | 23 | ||
24 | require('../common'); | 24 | require('../common'); |
25 | +require('./list-dynamic'); | ||
25 | 26 | ||
26 | var state = {}; | 27 | var state = {}; |
27 | 28 | ||
@@ -49,8 +50,6 @@ info.initInfosEvt($infoList); | @@ -49,8 +50,6 @@ info.initInfosEvt($infoList); | ||
49 | end: false | 50 | end: false |
50 | }; | 51 | }; |
51 | }); | 52 | }); |
52 | - | ||
53 | - console.log(state); | ||
54 | }()); | 53 | }()); |
55 | $nav.bind('contextmenu', function(e) { | 54 | $nav.bind('contextmenu', function(e) { |
56 | return false; | 55 | return false; |
@@ -258,7 +258,7 @@ function loadMore($container, opt, url) { | @@ -258,7 +258,7 @@ function loadMore($container, opt, url) { | ||
258 | delete opt.isTab; | 258 | delete opt.isTab; |
259 | }, | 259 | }, |
260 | error: function() { | 260 | error: function() { |
261 | - console.log('error') | 261 | + //console.log('error') |
262 | tip.show('网络断开连接了~'); | 262 | tip.show('网络断开连接了~'); |
263 | searching = false; | 263 | searching = false; |
264 | delete opt.isTab; | 264 | delete opt.isTab; |
@@ -29,6 +29,7 @@ scrollToEl = document.querySelector('#wrapper .collocation-block'); | @@ -29,6 +29,7 @@ scrollToEl = document.querySelector('#wrapper .collocation-block'); | ||
29 | 29 | ||
30 | require('../common'); | 30 | require('../common'); |
31 | require('../plugin/wx-share')(); | 31 | require('../plugin/wx-share')(); |
32 | +require('./detail-dynamic'); | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * 计算搭配的箭头的位置 | 35 | * 计算搭配的箭头的位置 |
public/js/guang/list-dynamic.js
0 → 100644
1 | +/** | ||
2 | + * 动态获取页面数据 | ||
3 | + * @author liuchuanyang | ||
4 | + * @date 2016/10/09 | ||
5 | + */ | ||
6 | +var $ = require('yoho-jquery'); | ||
7 | + | ||
8 | +var $msgs = $('#info-list'); | ||
9 | + | ||
10 | +require('../common'); | ||
11 | + | ||
12 | +function getDynamicByIds(ids) { | ||
13 | + 'use strict'; | ||
14 | + var data = { | ||
15 | + ids: ids | ||
16 | + }; | ||
17 | + | ||
18 | + var qs = window.queryString; | ||
19 | + | ||
20 | + if (qs.query) { | ||
21 | + | ||
22 | + // 标签列表 | ||
23 | + data.query = qs.query; | ||
24 | + } else if (qs.type) { | ||
25 | + | ||
26 | + // 逛首页type | ||
27 | + data.type = qs.type; | ||
28 | + } else if (!qs.author_id) { | ||
29 | + | ||
30 | + // 非编辑页的情况下,为逛首页默认type=0 | ||
31 | + data.type = '0'; | ||
32 | + } | ||
33 | + | ||
34 | + return $.ajax({ | ||
35 | + type: 'GET', | ||
36 | + url: '/guang/info/listData', | ||
37 | + data: data | ||
38 | + }); | ||
39 | +} | ||
40 | + | ||
41 | +function renderData(data) { | ||
42 | + 'use strict'; | ||
43 | + | ||
44 | + var i, | ||
45 | + it, | ||
46 | + $it; | ||
47 | + | ||
48 | + var list; | ||
49 | + | ||
50 | + if (data && data.code === 200 && (list = data.data.artList)) { | ||
51 | + for (i = 0; i < list.length; i++) { | ||
52 | + it = list[i]; | ||
53 | + | ||
54 | + if (it && it.articleId) { | ||
55 | + $it = $('.guang-info[data-id=' + it.articleId + ']', $msgs); | ||
56 | + | ||
57 | + // 浏览数目 | ||
58 | + $it.find('.page-view').text(it.views_num); | ||
59 | + | ||
60 | + // 点赞状态 | ||
61 | + if (it.isPraise === 'Y') { | ||
62 | + $it.find('.like-btn').addClass('liked'); | ||
63 | + } else { | ||
64 | + $it.find('.like-btn').removeClass('liked'); | ||
65 | + } | ||
66 | + | ||
67 | + // 点赞数目 | ||
68 | + $it.find('.like-count').text(it.praise_num); | ||
69 | + | ||
70 | + // 评论数目 | ||
71 | + $it.find('.like-count').text(it.comment_num); | ||
72 | + } | ||
73 | + } | ||
74 | + } | ||
75 | +} | ||
76 | + | ||
77 | +(function() { | ||
78 | + 'use strict'; | ||
79 | + | ||
80 | + var idArr = []; | ||
81 | + | ||
82 | + $msgs.find('.guang-info').each(function() { | ||
83 | + var id = $(this).data('id'); | ||
84 | + | ||
85 | + if (id) { | ||
86 | + idArr.push(id); | ||
87 | + } | ||
88 | + }); | ||
89 | + | ||
90 | + getDynamicByIds(idArr.join(',')).then(renderData); | ||
91 | +}()); |
-
Please register or login to post a comment