Authored by xuqi

文章点赞和取消点赞

... ... @@ -330,7 +330,11 @@ module.exports = function(flag) {
url: '',
publishTime: '2月13日 12:34',
pageView: 3445,
like: true,
//like为false则不显示点赞
like: {
count: 123,
isLiked: true
},
share: false //不显示share标签
}
]
... ... @@ -349,7 +353,10 @@ module.exports = function(flag) {
url: '',
publishTime: '2月13日 12:34',
pageView: 3445,
like: true,
like: {
count: 459,
isLiked: true
},
share: false //不显示share标签
},
{
... ... @@ -364,7 +371,7 @@ module.exports = function(flag) {
url: '',
publishTime: '2月13日 12:34',
pageView: 3445,
like: true,
like: false,
share: false
}
];
... ... @@ -390,7 +397,10 @@ module.exports = function(flag) {
url: '',
publishTime: '2月13日 12:34',
pageView: 3445,
like: true,
like: {
count: 459,
isLiked: true
},
share: false //不显示share标签
},
{
... ... @@ -405,7 +415,7 @@ module.exports = function(flag) {
url: '',
publishTime: '2月13日 12:34',
pageView: 3445,
like: true,
like: false,
share: false
}
]
... ... @@ -490,7 +500,10 @@ module.exports = function(flag) {
'In England中Panul Smith缔造了一个传奇',
publishTime: '2月13日 12:34',
pageView: 3445,
like: true,
like: {
count: 459,
isLiked: true
},
share: true,
url: '',
likeUrl: ''
... ... @@ -503,7 +516,10 @@ module.exports = function(flag) {
'In England中Panul Smith缔造了一个传奇',
publishTime: '2月13日 12:34',
pageView: 3445,
like: true,
like: {
count: 100,
isLiked: false
},
share: true,
url: '',
likeUrl: ''
... ...
... ... @@ -130,22 +130,24 @@ exports.init = function() {
$('#info-content').delegate('.like-btn', 'touchstart', function(e) {
var $cur = $(e.currentTarget),
$info = $cur.closest('.info-block'),
id = $info.data('id');
id = $info.data('id'),
url;
//取消点赞的处理
if ($cur.hasClass('like')) {
$cur.next('span.like-count').text('');
$cur.toggleClass('like');
return;
if ($cur.hasClass('like')) {
url = '/guang/info/praise';
} else {
url = '/guang/info/cancelpraise';
}
$.ajax({
type: 'GET',
url: '/favorite/praise',
url: url,
data: {
id: id
}
}).then(function(data) {
if (data.code === 200) {
$cur.toggleClass('like');
//更新点赞数
$cur.next('span.like-count').text(data.data);
} else if (data.code === 400) {
... ...
... ... @@ -85,26 +85,27 @@ exports.init = function() {
this.mlellipsis(2);
});
//文章点赞
//文章点赞和取消点赞
$('.tag-container').delegate('.like-btn', 'touchstart', function(e) {
var $cur = $(e.currentTarget),
$info = $cur.closest('.tag-content'),
id = $info.data('id');
//点赞的只有取消点赞的效果, 不发送请求, 不改变点赞数字
if ($cur.hasClass('like')) {
$cur.next('span.like-count').text('');
id = $info.data('id'),
url;
$cur.toggleClass('like');
return;
if ($cur.hasClass('like')) {
url = '/guang/info/praise';
} else {
url = '/guang/info/cancelpraise';
}
$.ajax({
type: 'GET',
url: '/favorite/praise',
url: url,
data: {
id: id
}
}).then(function(data) {
if (data.code === 200) {
$cur.toggleClass('like');
//更新点赞数
$cur.next('span.like-count').text(data.data);
} else if (data.code === 400) {
... ...
... ... @@ -28,7 +28,9 @@ module.exports = function(app) {
app.get('/favorite/product', fav.prod); //商品收藏或取消收藏
app.get('/favorite/brand', fav.brand); //品牌收藏或取消收藏
app.get('/favorite/praise', fav.article); //文章点赞或取消点赞
app.get('/guang/info/praise', fav.article); //文章点赞或取消点赞
app.get('/guang/info/cancelpraise', fav.article);
app.get('/common/articletpl', ps.readTpl); //获取相关资讯模板
app.get('/common/goodinfo', template.readTpl); //读取模板
... ...
... ... @@ -48,17 +48,21 @@ exports.brand = function(req, res) {
//文章点赞或取消点赞
exports.article = function(req, res) {
if (req.query.st === '0') {
res.send({
code: 400,
message: "",
data: 99
});
} else {
// if (req.query.st === '0') {
// res.send({
// code: 400,
// message: "",
// data: 99
// });
// } else {
// res.send({
// code: 200,
// message: "",
// data: 100
// });
// }
res.send({
code: 200,
message: "",
data: 100
data: parseInt(Math.random() * 100, 10)
});
}
};
\ No newline at end of file
... ...
... ... @@ -5,8 +5,8 @@
{{pageView}}
<div class="like-share-container">
{{# like}}
<a href="javascript:;" class="iconfont like-btn">&#xe601;</a>
<span class="like-count"></span>
<a href="javascript:;" class="iconfont like-btn{{#isLiked}} like{{/isLiked}}">&#xe601;</a>
<span class="like-count">{{count}}</span>
{{/ like}}
{{# share}}
<a href="{{.}}" class="iconfont share-btn">&#xe600;</a>
... ...