Authored by 刘传洋

guang detail

... ... @@ -171,7 +171,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 +184,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;
}
// 登陆后自动收藏
... ... @@ -289,19 +300,32 @@ exports.listDynamicData = (req, res) => {
exports.detailDynamicData = (req, res) => {
let id = req.query.id;
guangModel.getDynamicDataByIds(id).then(ret => {
res.status(200).send(ret);
guangModel.getDynamicDataById(id).then(() => {
// res.status(200).send(ret);
res.status(200).send({
code: 200,
data: {
browseNum: 88823212,
id: id,
isFavor: 'Y',
isPraise: 'Y',
praiseNum: 58
}
});
}).catch(() => {
res.status(400);
});
};
exports.detailCommentData = (req, res) => {
let param = {
id: req.query.id,
page: req.query.page
};
let id = req.query.id,
page = req.query.page,
pageSize = req.query.pageSize || 20;
res.render('', param);
return guangModel.getArticleComments(id, page, pageSize).then(ret => {
return res.status(200).send(ret);
});
};
/**
... ...
... ... @@ -8,6 +8,7 @@
const _ = require('lodash');
const moment = require('moment');
const ghelper = require('./guang-helper');
const querystring = require('querystring');
const helpers = global.yoho.helpers;
... ... @@ -732,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;
... ... @@ -755,7 +756,10 @@ const getArticleComments = (aid, page, pageSize) => {
return {
commentNum: num,
list: list
pageSize: pageSize,
page: page,
list: list,
baseUrl: `?${querystring.stringify({pageSize: pageSize})}`
};
});
};
... ... @@ -830,13 +834,6 @@ const cancelCollect = (aid, uid) => serviceApi.get('guang/api/v1/favorite/cancel
const getDynamicDataById = id => {
return serviceApi.get('', {
id: id
}).then(res => {
if (res && res.code === 200 && res.data) {
return res.data;
}
return Promise.reject('获取失败');
});
};
... ...
... ... @@ -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>
... ...
... ... @@ -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}}
... ...
... ... @@ -9,22 +9,11 @@ function getDynamicById(id) {
'use strict';
var param = {
return_type: 'jsonp',
id: id
};
return $.getJSON('//guang.yohobuy.com/guang/info/detailData?callback=?', param);
}
function getDynamicCommentList(id, page) {
'use strict';
var param = {
id: id,
page: page
};
return $.getJSON('//guang.yohobuy.com/guang/info/commentData?callback=?', param);
// //guang.yohobuy.com/guang/info/detailData
return $.getJSON('/guang/info/detailData', param);
}
function renderData(data) {
... ... @@ -48,22 +37,16 @@ function renderData(data) {
}
$praise.find('.like-num').text(data.data.praiseNum || 0);
$('.detail-body .article-click em').text(data.data.browseNum || 0);
}
}
function renderComment() {
'use strict';
}
function refreshData() {
'use strict';
var id = $('.detail-body').attr('data-id');
getDynamicById(id).done(renderData);
getDynamicCommentList(id).done(renderComment);
}
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() {
... ...