Authored by 陈轩

Merge remote-tracking branch 'origin/release/5.1' into release/5.1

@@ -42,6 +42,7 @@ const editor = (req, res, next) => { @@ -42,6 +42,7 @@ const editor = (req, res, next) => {
42 let authorData = datas[0], 42 let authorData = datas[0],
43 articleListData = datas[1]; 43 articleListData = datas[1];
44 let build = []; 44 let build = [];
  45 +
45 if (articleListData.data.list.artList) { 46 if (articleListData.data.list.artList) {
46 articleListData.data.list.artList.forEach(articleData => { 47 articleListData.data.list.artList.forEach(articleData => {
47 build.push(guangProcess.formatArticle(articleData, true, isApp, false, uid)); 48 build.push(guangProcess.formatArticle(articleData, true, isApp, false, uid));
@@ -60,7 +61,7 @@ const editor = (req, res, next) => { @@ -60,7 +61,7 @@ const editor = (req, res, next) => {
60 } else { 61 } else {
61 return next(); 62 return next();
62 } 63 }
63 - 64 +
64 }).catch(next); 65 }).catch(next);
65 66
66 }; 67 };
@@ -178,7 +179,7 @@ const tag = (req, res, next) => { @@ -178,7 +179,7 @@ const tag = (req, res, next) => {
178 179
179 }; 180 };
180 181
181 - 182 +
182 responseData.pageHeader.navTitle = param.tag || '标签'; 183 responseData.pageHeader.navTitle = param.tag || '标签';
183 184
184 185
@@ -187,9 +188,60 @@ const tag = (req, res, next) => { @@ -187,9 +188,60 @@ const tag = (req, res, next) => {
187 }).catch(next); 188 }).catch(next);
188 }; 189 };
189 190
  191 + /**
  192 + * 列表页(列表首页、标签列表页、作者列表页)动态数据,如:查看数,点赞数,评论数,是否点赞,是否回复
  193 + * @param req
  194 + * @param res
  195 + */
  196 +const listDynamicData = (req, res) => {
  197 + let ids = req.query.ids;
  198 +
  199 + let udid = req.sessionID;
  200 +
  201 + let other = {};
  202 + let query = req.query.query,
  203 + type = req.query.type;
  204 +
  205 + if (req.user.uid) {
  206 + other.uid = req.user.uid;
  207 + }
  208 +
  209 + if (query) {
  210 + other.query = query;
  211 + }
  212 +
  213 + if (type) {
  214 + other.type = type;
  215 + }
  216 +
  217 + indexModel.getDynamicDataByIds(ids, udid, other).then(ret => {
  218 + res.send(ret);
  219 + });
  220 +};
  221 +
  222 + /**
  223 + * 详情页动态数据,如:评论数,回复数,是否点赞,是否收藏
  224 + * @param req
  225 + * @param res
  226 + */
  227 +const detailDynamicData = (req, res) => {
  228 +
  229 + let id = req.query.id,
  230 + uid = req.user.uid,
  231 + udid = req.sessionID;
  232 +
  233 + indexModel.getDynamicDataById(id, uid, udid).then((ret) => {
  234 + res.status(200).send(ret);
  235 + }).catch(() => {
  236 + res.status(400);
  237 + });
  238 +};
  239 +
190 module.exports = { 240 module.exports = {
191 editor, 241 editor,
192 pageData, 242 pageData,
193 index, 243 index,
194 - tag 244 + tag,
  245 + listDynamicData,
  246 + detailDynamicData
195 }; 247 };
@@ -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 };
@@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
6 'use strict'; 6 'use strict';
7 const serviceAPI = global.yoho.ServiceAPI; 7 const serviceAPI = global.yoho.ServiceAPI;
8 const api = global.yoho.API; 8 const api = global.yoho.API;
9 -const _ = require('lodash');  
10 9
11 const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/'; 10 const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
12 const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/'; 11 const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
@@ -84,14 +83,6 @@ const packageData = (id, isApp) => { @@ -84,14 +83,6 @@ const packageData = (id, isApp) => {
84 cache: true 83 cache: true
85 })); 84 }));
86 85
87 - if (isApp) {  
88 - promises.push(api.get('', {  
89 - method: 'app.resources.getSingleTemplate',  
90 - module: 'wechat',  
91 - key: 'guang_detail_wechat'  
92 - }));  
93 - }  
94 -  
95 // 获取资讯相关的其它资讯 86 // 获取资讯相关的其它资讯
96 if (typeof article.tag !== 'undefined') { 87 if (typeof article.tag !== 'undefined') {
97 param = { 88 param = {
@@ -108,10 +99,19 @@ const packageData = (id, isApp) => { @@ -108,10 +99,19 @@ const packageData = (id, isApp) => {
108 cache: true 99 cache: true
109 })); 100 }));
110 } 101 }
  102 +
  103 + if (isApp) {
  104 + promises.push(api.get('', {
  105 + method: 'app.resources.getSingleTemplate',
  106 + module: 'wechat',
  107 + key: 'guang_detail_wechat'
  108 + }));
  109 + }
  110 +
111 return Promise.all(promises).then(datas => { 111 return Promise.all(promises).then(datas => {
112 let getArticleContent = datas[1].data; 112 let getArticleContent = datas[1].data;
113 113
114 - if (datas[3].data) { 114 + if (isApp && datas[4].data) {
115 115
116 let preCount = 0; 116 let preCount = 0;
117 let i; 117 let i;
@@ -122,14 +122,14 @@ const packageData = (id, isApp) => { @@ -122,14 +122,14 @@ const packageData = (id, isApp) => {
122 } 122 }
123 } 123 }
124 124
125 - getArticleContent.splice(preCount, 0, {weixinPublic: datas[3].data}); 125 + getArticleContent.splice(preCount, 0, {weixinPublic: datas[4].data});
126 } 126 }
127 127
128 result.getAuthor = datas[0].data; 128 result.getAuthor = datas[0].data;
129 result.getArticleContent = getArticleContent; 129 result.getArticleContent = getArticleContent;
130 result.getBrand = datas[2].data; 130 result.getBrand = datas[2].data;
131 - if (datas.length === 5) {  
132 - result.getOtherArticle = datas[4].data; 131 + if (datas.length === 5 && isApp || datas.length === 4 && !isApp) {
  132 + result.getOtherArticle = datas[3].data;
133 } 133 }
134 return result; 134 return result;
135 }); 135 });
@@ -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;
@@ -94,7 +94,7 @@ const _getShopDecorator = (shopId) => { @@ -94,7 +94,7 @@ const _getShopDecorator = (shopId) => {
94 cache: true, 94 cache: true,
95 code: 200 95 code: 200
96 }).then((result) => { 96 }).then((result) => {
97 - return result.data; 97 + return (result && result.data) || {};
98 }); 98 });
99 }; 99 };
100 100
@@ -748,14 +748,28 @@ const getShopCategory = (params) => { @@ -748,14 +748,28 @@ const getShopCategory = (params) => {
748 _.forEach(value.sub, (subValue, subKey) => { 748 _.forEach(value.sub, (subValue, subKey) => {
749 value.sub[subKey].url = helpers.urlFormat('/product/search/list', { 749 value.sub[subKey].url = helpers.urlFormat('/product/search/list', {
750 shop_id: params.shopId, 750 shop_id: params.shopId,
751 - sort: _.get(value, 'relation_parameter.sort', ''), 751 + sort: _.get(subValue, 'relation_parameter.sort', ''),
752 title: subValue.category_name, 752 title: subValue.category_name,
753 query: subValue.category_name 753 query: subValue.category_name
754 }); 754 });
755 }); 755 });
756 756
  757 + let subCategory = [
  758 + {
  759 + category_name: '全部' + value.category_name,
  760 + url: helpers.urlFormat('/product/search/list', {
  761 + shop_id: params.shopId,
  762 + sort: _.get(value, 'relation_parameter.sort', ''),
  763 + title: '全部' + value.category_name,
  764 + query: value.category_name
  765 + })
  766 + }
  767 + ];
  768 +
  769 + subCategory = subCategory.concat(value.sub);
  770 +
757 finalResult.category.push({ 771 finalResult.category.push({
758 - subcategory: value.sub 772 + subcategory: subCategory
759 }); 773 });
760 }); 774 });
761 775
@@ -58,6 +58,12 @@ $categoryContainer.on('touchend', function(e) { @@ -58,6 +58,12 @@ $categoryContainer.on('touchend', function(e) {
58 $cur, index; 58 $cur, index;
59 59
60 $cur = $this.closest('.p-level-item'); 60 $cur = $this.closest('.p-level-item');
  61 +
  62 + // 第一次单击右则空白处,出现冒泡
  63 + if ($(e.target).closest('.sub-level').length <= 0) {
  64 + e.preventDefault();
  65 + }
  66 +
61 if ($cur.length > 0) { 67 if ($cur.length > 0) {
62 index = $cur.index(); 68 index = $cur.index();
63 $subLevel = $this.closest('.content').find('.sub-level'); 69 $subLevel = $this.closest('.content').find('.sub-level');
  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();
@@ -26,6 +26,7 @@ var setting = { @@ -26,6 +26,7 @@ var setting = {
26 var $infos = $('#info-list'); 26 var $infos = $('#info-list');
27 27
28 require('../common'); 28 require('../common');
  29 +require('./list-dynamic');
29 30
30 info.initInfosEvt($infos); 31 info.initInfosEvt($infos);
31 32
@@ -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 * 计算搭配的箭头的位置
@@ -196,12 +197,12 @@ $('img').on('load', function() { @@ -196,12 +197,12 @@ $('img').on('load', function() {
196 197
197 if ($('.guang-detail-page').hasClass('guang-detail')) { 198 if ($('.guang-detail-page').hasClass('guang-detail')) {
198 useIscroll = true; 199 useIscroll = true;
199 - } else if($('.guang-detail-page').hasClass('guang-ezine')) { 200 + } else if ($('.guang-detail-page').hasClass('guang-ezine')) {
200 useIscroll = false; 201 useIscroll = false;
201 } 202 }
202 $('.main-wrap').css({ 203 $('.main-wrap').css({
203 position: 'static' 204 position: 'static'
204 - }) 205 + });
205 206
206 pageInIscroll = isIphone && useIscroll; 207 pageInIscroll = isIphone && useIscroll;
207 208
  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('like');
  63 + } else {
  64 + $it.find('.like-btn').removeClass('like');
  65 + }
  66 +
  67 + // 点赞数目
  68 + $it.find('.like-count').text(it.praise_num);
  69 + }
  70 + }
  71 + }
  72 +}
  73 +
  74 +(function() {
  75 + 'use strict';
  76 +
  77 + var idArr = [];
  78 +
  79 + $msgs.find('.guang-info').each(function() {
  80 + var id = $(this).data('id');
  81 +
  82 + if (id) {
  83 + idArr.push(id);
  84 + }
  85 + });
  86 +
  87 + getDynamicByIds(idArr.join(',')).then(renderData);
  88 +}());
@@ -135,7 +135,8 @@ function initFilter(opt) { @@ -135,7 +135,8 @@ function initFilter(opt) {
135 var $this = $(e.target), 135 var $this = $(e.target),
136 $cur; 136 $cur;
137 137
138 - // e.preventDefault();//防止透点 138 + // 这行不能注释,iphone下会出现穿透
  139 + e.preventDefault();// 防止透点
139 140
140 if ($this.closest('.filter-body').length > 0) { 141 if ($this.closest('.filter-body').length > 0) {
141 $cur = $this.closest('.sub-item'); 142 $cur = $this.closest('.sub-item');
@@ -34,6 +34,11 @@ $categoryContainer.on('touchend', function(e) { @@ -34,6 +34,11 @@ $categoryContainer.on('touchend', function(e) {
34 34
35 $cur = $this.closest('.p-level-item'); 35 $cur = $this.closest('.p-level-item');
36 36
  37 + // 第一次单击右则空白处,出现冒泡
  38 + if ($(e.target).closest('.sub-level').length <= 0) {
  39 + e.preventDefault();
  40 + }
  41 +
37 $subLevelContainer = $this.closest('.content').find('.sub-level-container'); 42 $subLevelContainer = $this.closest('.content').find('.sub-level-container');
38 $subLevelContainer.removeClass('hide'); 43 $subLevelContainer.removeClass('hide');
39 44