Authored by 郭成尧

frame

... ... @@ -248,6 +248,7 @@ const index = (req, res, next) => {
let resu = yield aboutModel.about(req.yoho.isApp);
data.guang.wxFooter = resu;
console.log(data);
res.render('info/index', Object.assign({
page: 'info-index',
title: '逛',
... ... @@ -424,9 +425,26 @@ const foryoho = (req, res, next) => {
})().catch(next);
};
/**
* 异步获取逛文章评论
* @param {*} req
* @param {*} res
* @param {*} next
*/
const getComments = (req, res, next) => {
req.ctx(DetailModel).comments({
article_id: req.query.article_id,
page: req.query.page
}).then(result => {
return res.render('info/comments', result);
}).catch(next);
};
module.exports = {
index,
mini,
foryoho,
indexRedirect
indexRedirect,
getComments
};
... ...
... ... @@ -11,6 +11,7 @@ const helpers = global.yoho.helpers;
const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
const URI_PACKAGE_COMMENTS = 'guang/service/v1/comments/';
class DetailModel extends global.yoho.BaseModel {
... ... @@ -348,6 +349,17 @@ class DetailModel extends global.yoho.BaseModel {
return _.get(result, 'data.product_list', []);
});
}
/**
* 获取文章评论列表
*/
comments(params) {
return serviceAPI.get(`${URI_PACKAGE_COMMENTS}getList`, {
article_id: params.article_id,
page: params.page,
limit: params.limit || 10
});
}
}
module.exports = DetailModel;
... ...
... ... @@ -58,6 +58,8 @@ router.get('/:id.html', detail.index); // 逛详情页(兼容 PC 跳转过来的
router.get('/info/mini', detail.mini); // 逛mini内容页
router.get('/info/foryoho', detail.foryoho); // 逛foryoho内容页
router.get('/info/getComments', detail.getComments); // 异步获取逛文章评论
router.get('/plustar', plustar.getListData); // 国际优选列表页
router.get('/plustar/brandinfo', plustar.getDetailData); // 国际优选详情页
router.post('/plustar/brandinfoAsync', plustar.getDetailDataAsync); // 国际优选详情页异步数据
... ...
... ... @@ -200,6 +200,7 @@
{{> wx-footer}}
</div>
{{/ wxFooter}}
<div class="comments" id="comments"></div>
</div>
{{!-- wx-share --}}
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-05-25 14:36:33
* @Last Modified by: Targaryen
* @Last Modified time: 2017-05-25 15:28:52
* @Last Modified time: 2017-05-25 17:09:44
*/
const $ = require('yoho-jquery');
const qs = window.queryString;
... ...
... ... @@ -32,6 +32,39 @@ require('./detail/guang-cart');
let CollactionBlock = require('./collocation-block');
const qs = window.queryString;
const article_id = qs.id || $('.detail').data('id');
const $comments = $('#comments');
let onLoading = false; // 是否正在加载
// let beforeScroll = document.body.scrollTop; // 滚动前位置记录
let page = 0;
/**
* 异步加载评论
*/
const getComments = () => {
if (!onLoading) {
onLoading = true;
} else {
return false;
}
$.ajax({
type: 'get',
url: '//guang.m.yohobuy.com/guang/info/getComments',
data: {
article_id: article_id,
page: page++
},
success: function(result) {
$comments.append(result);
onLoading = false;
}
});
};
getComments();
$('#wrapper').css({
'overflow-y': 'scroll'
});
... ... @@ -362,3 +395,27 @@ $('.wei-share').on('touchend', function(e) {
initIscroll();
}());
/**
* 当scroll到1/2$goodsContainer高度后继续请求下一页数据
*/
// const scrollHandler = function() {
// if ($(window).scrollTop() > $comments.height() * 0.6) {
// getComments();
// }
// };
// /**
// * 滚动加载
// */
// $(window).scroll(function() {
// setTimeout(function() {
// let afterScroll = document.body.scrollTop;
// if (afterScroll - beforeScroll > 0) {
// window.requestAnimationFrame(scrollHandler);
// beforeScroll = afterScroll;
// } else {
// return false;
// }
// }, 5);
// });
... ...
... ... @@ -6,3 +6,4 @@
@import "detail";
@import "tvls";
@import "channel/side-nav";
@import "./detail/comments";
... ...