Authored by 王水玲

Merge branch 'feature/star' of git.yoho.cn:fe/yohobuywap-node into feature/star

... ... @@ -6,9 +6,11 @@
'use strict';
const mRoot = '../models';
const library = '../../../library';
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header');
const starModel = require(`${mRoot}/star`);
const helpers = require(`${library}/helpers`);
const headTab = [
{
... ... @@ -110,7 +112,7 @@ exports.collocation = (req, res) => {
*/
exports.collocationList = (req, res) => {
let params = req.query;
let uid = 9239279 || req.user.uid || 0;
let uid = req.user.uid || 0;
starModel.getCollocationListData(params, uid).then((result) => {
res.render('star/list', _.assign({
... ... @@ -123,6 +125,26 @@ exports.collocationList = (req, res) => {
};
/**
* 收藏文章
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]}
*/
exports.setFavorite = (req, res) => {
let params = req.body;
let uid = req.user.uid || 0;
starModel.setFavorite(params, uid).then((result) => {
if (result.code === 401) {
result.data = helpers.urlFormat('/signin.html', {
refer: req.get('Referer') || '/guang/star/collocation'
});
}
res.json(result);
});
};
/**
* 明星文章专区
* @param {[object]} req
* @param {[object]} res
... ...
... ... @@ -212,3 +212,19 @@ exports.getCollocationListData = (params, uid) => {
}
});
};
exports.setFavorite = (params, uid) => {
if (!uid) {
return Promise.resolve({
code: 401,
message: '未登录'
});
}
return api.get('', sign.apiSign({
method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
client_type: 'h5',
article_id: params.articleId,
uid: uid
}));
};
... ...
... ... @@ -19,4 +19,6 @@ router.get('/star/special', star.special); // 星潮教室星专题
router.get('/star/collocation', star.collocation); // 星潮教室星搭配
router.get('/star/collocation/list', star.collocationList); // 星潮教室星搭配文章请求
router.post('/star/setFavorite', star.setFavorite); // 收藏文章
module.exports = router;
... ...
... ... @@ -25,7 +25,7 @@ $(document).on('click', '.collection', function() {
$.ajax({
type: 'POST',
url: '/guang/starclass/setFavorite',
url: '/guang/star/setFavorite',
data: {
articleId: $that.parents('li').attr('articleId'),
type: type
... ... @@ -42,7 +42,7 @@ $(document).on('click', '.collection', function() {
}
if (code === 201) {
if (code === 401) {
if ($('#collocation-link').length <= 0) {
$('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' +
'<span class="collocation-link"></span></a>');
... ...