Authored by 石坚

Merge branch 'feature/guang' of http://git.yoho.cn/fe/yohobuy-node into feature/guang

... ... @@ -99,6 +99,7 @@ exports.tags = (req, res, next) => {
tag: query,
guangIndexPage: true,
baseUrl: `?${querystring.stringify(req.query)}`,
pageSize: pageSize,
type: type,
pathNav: pathNav,
... ... @@ -140,18 +141,14 @@ exports.editor = (req, res, next) => {
res.render('editor', {
title: ret[0].name + (res.locals.title || ''),
guang: {
editor: {
avatar: ret[0] && ret[0].avatar,
name: ret[0] && ret[0].name,
intro: ret[0] && ret[0].author_desc,
info: '设计理念:时尚,线条流畅'
},
editor: ret[0],
msgs: ret[1] && ret[1].msgs,
hotTags: ret[2],
ads: ret[3],
exRecos: ret[4],
gender: gender,
baseUrl: `?${querystring.stringify(req.query)}`,
pageSize: pageSize,
pathNav: pathNav,
page: page,
... ... @@ -171,7 +168,7 @@ exports.detail = (req, res, next) => {
let id = req.params.id || req.query.id;
let page = req.query.page || 1;
let pageSize = req.query.pageSize || 20;
let pageSize = req.query.pageSize || 10;
let col = req.query.col || 0;
let pjax = req.query._pjax;
let uid = req.user.uid;
... ... @@ -184,9 +181,20 @@ exports.detail = (req, res, next) => {
}
if (pjax) {
return guangModel.getArticleComments(id, page, pageSize).then(ret => {
return res.render('comment', ret);
guangModel.getArticleComments(id, page, pageSize).then(ret => {
res.render('detail-comment', {
layout: false,
comment: ret
}, function(err, html) {
if (err) {
return res.send('');
}
return res.status(200).send(html);
});
});
return;
}
// 登陆后自动收藏
... ... @@ -276,8 +284,26 @@ exports.detail = (req, res, next) => {
exports.listDynamicData = (req, res) => {
let ids = req.query.ids;
guangModel.getDynamicDataByIds(ids).then(ret => {
res.status(200).send(ret);
let udid = ghelper.getUdid(req, res);
let other = {};
let query = req.query.query,
type = req.query.type;
if (req.user.uid) {
other.uid = req.user.uid;
}
if (query) {
other.query = query;
}
if (type) {
other.type = type;
}
guangModel.getDynamicDataByIds(ids, udid, other).then(ret => {
res.send(ret);
});
};
... ... @@ -287,23 +313,17 @@ exports.listDynamicData = (req, res) => {
* @param res
*/
exports.detailDynamicData = (req, res) => {
let id = req.query.id;
let id = req.query.id,
uid = req.user.uid,
udid = ghelper.getUdid(req, res);
guangModel.getDynamicDataByIds(id).then(ret => {
guangModel.getDynamicDataById(id, uid, udid).then((ret) => {
res.status(200).send(ret);
}).catch(() => {
res.status(400);
});
};
exports.detailCommentData = (req, res) => {
let param = {
id: req.query.id,
page: req.query.page
};
res.render('', param);
};
/**
* 添加评论
*/
... ...
... ... @@ -9,7 +9,6 @@ const _ = require('lodash');
const moment = require('moment');
const ghelper = require('./guang-helper');
const helpers = global.yoho.helpers;
const serviceApi = global.yoho.ServiceAPI;
const yohoApi = global.yoho.API;
... ... @@ -364,7 +363,7 @@ const getCategory = currentSortId => {
list.push({
typeId: cat.id,
type: cat.name,
isActive: cat.id === currentSortId,
isActive: ('' + cat.id) === ('' + currentSortId),
navUrl: helpers.urlFormat('/index/index', {type: cat.id}, 'guang')
});
}
... ... @@ -734,7 +733,7 @@ const getArticleComments = (aid, page, pageSize) => {
return serviceApi.get('guang/api/v1/comments/getList', {
article_id: aid,
page: page,
pageSize: pageSize
limit: pageSize
}).then(res => {
let num = (res.data && res.data.total) || 0;
... ... @@ -757,7 +756,13 @@ const getArticleComments = (aid, page, pageSize) => {
return {
commentNum: num,
list: list
pageSize: pageSize,
page: page,
list: list,
baseUrl: helpers.urlFormat('/info/index', {
id: aid,
pageSize: pageSize
}, 'guang')
};
});
};
... ... @@ -829,35 +834,46 @@ const cancelCollect = (aid, uid) => serviceApi.get('guang/api/v1/favorite/cancel
* @param ids
* @returns {Promise.<T>|*}
*/
const getDynamicDataById = id => {
return serviceApi.get('', {
id: id
}).then(res => {
if (res && res.code === 200 && res.data) {
return res.data;
}
return Promise.reject('获取失败');
const getDynamicDataById = (id, uid, udid) => {
return serviceApi.get('/gateway/guang/api/*/article/getArticlePraiseAndFavor', {
id: id,
uid: uid,
udid: udid
});
};
/**
* 获取制指定文章的动态信息
* @param ids
* @param udid
* @param other [Obejct] 包含uid,query,type等非必传参数
* @returns {Promise.<T>|*}
*/
const getDynamicDataByIds = ids => {
return serviceApi.get('', {
ids: ids
}).then(res => {
const getDynamicDataByIds = (ids, udid, other) => {
let params = {
articleIds: ids,
udid: udid
};
if (res && res.code === 200 && res.data) {
return res.data;
}
if (other.uid) {
_.assign(params, {
uid: other.uid
});
}
return Promise.reject('获取失败');
});
if (other.query) {
_.assign(params, {
query: other.query
});
}
if (other.type) {
_.assign(params, {
type: other.type
});
}
return serviceApi.get('guang/api/*/article/getSimpleArticleList', params, {cache: true});
};
module.exports = {
... ...
... ... @@ -23,5 +23,9 @@ router.get('/info/cancelPraise', guangController.cancelPraise);
router.get('/info/collect', guangController.collect);
router.get('/info/cancelCollect', guangController.cancelCollect);
router.get('/info/listData', guangController.listDynamicData);
router.get('/info/detailData', guangController.detailDynamicData);
// router.get('/info/commentData', guangController.detailCommentData);
module.exports = router;
... ...
... ... @@ -17,7 +17,7 @@
</div>
<div class="article-status clearfix">
<span class="article-time">{{time}}</span>
<span class="article-click">点击:{{click}}</span>
<span class="article-click">点击:<em>{{click}}</em></span>
<a href="#comment-info" id="article-comment" class="article-comment"><em class="comment-num">{{commentNum}}</em>条评论</a>
</div>
</div>
... ... @@ -147,4 +147,4 @@
{{> right-side}}
</div>
{{/ guang}}
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -20,11 +20,11 @@
{{/ msgs}}
</div>
<div class="msg-pager pager">
{{{msgPager}}}
{{pager baseUrl totalRecords=total page=page type="ellipsis" theme="msg-pager"}}
</div>
</div>
<div class="right-side">
{{> right-side}}
</div>
{{/ guang}}
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -12,10 +12,10 @@
{{/ msgs}}
</div>
{{pager totalRecords=total page=page type="ellipsis" theme="msg-pager"}}
{{pager baseUrl totalRecords=total page=page type="ellipsis" theme="msg-pager"}}
</div>
<div class="right-side">
{{> right-side}}
</div>
{{/ guang}}
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -18,6 +18,6 @@
</li>
{{/ list}}
</ul>
<div class="comment-pager pager">{{pager totalRecords=commentNum page=page type="ellipsis" theme="msg-pager"}}</div>
<div class="comment-pager pager">{{pager baseUrl totalRecords=commentNum page=page pageSize=pageSize type="ellipsis" theme="msg-pager"}}</div>
</div>
{{/ comment}}
... ...
... ... @@ -22,7 +22,7 @@
</span>
<span class="page-view">
<i class="iconfont">&#xe627;</i>
{{pView}}
<em>{{pView}}</em>
</span>
</p>
<p class="content">{{content}}</p>
... ... @@ -40,7 +40,7 @@
<span class="comment">
<i class="iconfont">&#xe624;</i>
{{# comment}}
({{.}})
(<em>{{.}}</em>)
{{/ comment}}
</span>
</div>
... ...
/**
* 动态获取页面数据
* @author liuchuanyang
* @date 2016/10/09
*/
var $ = require('yoho-jquery');
function getDynamicById(id) {
'use strict';
var param = {
id: id
};
// //guang.yohobuy.com/guang/info/detailData
return $.getJSON('/guang/info/detailData', param);
}
function renderData(data) {
'use strict';
var $favor = $('#collect-btn'),
$praise = $('#prise-btn');
if (data && data.code === 200 && data.data) {
if (data.data.isFavor === 'Y') {
$favor.addClass('collected');
} else {
$favor.removeClass('collected');
}
if (data.data.isPraise === 'Y') {
$praise.addClass('liked');
} else {
$praise.removeClass('liked');
}
$praise.find('.like-num').text(data.data.praiseNum || 0);
$('.detail-body .article-click em').text(data.data.browseNum || 0);
}
}
function refreshData() {
'use strict';
var id = $('.detail-body').attr('data-id');
getDynamicById(id).done(renderData);
}
refreshData();
... ...
... ... @@ -21,6 +21,7 @@ require('./right-side');
require('./img-blink');
require('../common/share');
require('./detail-dynamic');
// Pjax
require('yoho-jquery-pjax');
... ... @@ -214,6 +215,9 @@ $(document).pjax('.comment-pager a', '#pjax-container', {
$(document).on('pjax:end', function() {
showComment();
$('html,body').scrollTop($('#comment-info').offset().top);
// 设置头部评论数
$('#article-comment .comment-num').text($('#comment-area .comment-num').text());
});
$('#comment-info').keyup(function() {
... ...
/**
* 动态获取页面数据
* @author liuchuanyang
* @date 2016/10/09
*/
var $ = require('yoho-jquery');
function getDynamicById(id) {
'use strict';
var param = {
return_type: 'jsonp',
id: id
};
return $.getJSON('//guang.yohobuy.com/guang/suggest?callback=?', param);
}
function getDynamicByIds(ids) {
'use strict';
var param = {
return_type: 'jsonp',
ids: ids
};
return $.getJSON('//guang.yohobuy.com/guang/suggest?callback=?', param);
}
function getDynamicCommentList(id, page) {
'use strict';
var param = {
id: id,
page: page
};
return $.getJSON('//guang.yohobuy.com/guang/suggest?callback=?', param);
}
module.exports = {
getDynamicById,
getDynamicByIds,
getDynamicCommentList
};
... ... @@ -15,6 +15,9 @@ require('./img-blink');
require('./right-side');
// page cache下更新点赞状态、点赞数、评论数、阅读数
require('./list-dynamic');
$('#slider').slider(); // 初始化slider
$(document).pjax('.pjax-link, .msg-pager a', '#pjax-container', {
... ...
/**
* 动态获取页面数据
* @author liuchuanyang
* @date 2016/10/09
*/
var $ = require('yoho-jquery');
var $msgs = $('#msg-list');
require('../common');
function getDynamicByIds(ids) {
'use strict';
var data = {
ids: ids
};
var qs = window.queryString();
if (qs.query) {
// 标签列表
data.query = qs.query;
} else if (qs.type) {
// 逛首页type
data.type = qs.type;
} else if (!qs.author_id) {
// 非编辑页的情况下,为逛首页默认type=0
data.type = '0';
}
return $.ajax({
type: 'GET',
url: '/guang/info/listData',
data: data
});
}
function renderData(data) {
'use strict';
var i,
it,
$it;
var list;
if (data && data.code === 200 && (list = data.data.artList)) {
for (i = 0; i < list.length; i++) {
it = list[i];
if (it && it.articleId) {
$it = $('.msg-content[data-id=' + it.articleId + ']', $msgs);
// 浏览数目
$it.find('.page-view em').text(it.views_num);
// 点赞状态
if (it.isPraise === 'Y') {
$it.find('.like-icon').addClass('liked');
} else {
$it.find('.like-icon').removeClass('liked');
}
// 点赞数目
$it.find('.like .num').text(it.praise_num);
// 评论数目
$it.find('.comment em').text(it.comment_num);
}
}
}
}
(function() {
'use strict';
var idArr = [];
$msgs.children('.msg-content').each(function() {
var id = $(this).data('id');
if (id) {
idArr.push(id);
}
});
getDynamicByIds(idArr.join(',')).then(renderData);
}());
... ...
... ... @@ -7,3 +7,6 @@
require('./msg');
require('./img-blink');
require('./right-side');
// page cache下更新点赞状态、点赞数、评论数、阅读数
require('./list-dynamic');
... ...