Showing
6 changed files
with
59 additions
and
34 deletions
@@ -330,7 +330,11 @@ module.exports = function(flag) { | @@ -330,7 +330,11 @@ module.exports = function(flag) { | ||
330 | url: '', | 330 | url: '', |
331 | publishTime: '2月13日 12:34', | 331 | publishTime: '2月13日 12:34', |
332 | pageView: 3445, | 332 | pageView: 3445, |
333 | - like: true, | 333 | + //like为false则不显示点赞 |
334 | + like: { | ||
335 | + count: 123, | ||
336 | + isLiked: true | ||
337 | + }, | ||
334 | share: false //不显示share标签 | 338 | share: false //不显示share标签 |
335 | } | 339 | } |
336 | ] | 340 | ] |
@@ -349,7 +353,10 @@ module.exports = function(flag) { | @@ -349,7 +353,10 @@ module.exports = function(flag) { | ||
349 | url: '', | 353 | url: '', |
350 | publishTime: '2月13日 12:34', | 354 | publishTime: '2月13日 12:34', |
351 | pageView: 3445, | 355 | pageView: 3445, |
352 | - like: true, | 356 | + like: { |
357 | + count: 459, | ||
358 | + isLiked: true | ||
359 | + }, | ||
353 | share: false //不显示share标签 | 360 | share: false //不显示share标签 |
354 | }, | 361 | }, |
355 | { | 362 | { |
@@ -364,7 +371,7 @@ module.exports = function(flag) { | @@ -364,7 +371,7 @@ module.exports = function(flag) { | ||
364 | url: '', | 371 | url: '', |
365 | publishTime: '2月13日 12:34', | 372 | publishTime: '2月13日 12:34', |
366 | pageView: 3445, | 373 | pageView: 3445, |
367 | - like: true, | 374 | + like: false, |
368 | share: false | 375 | share: false |
369 | } | 376 | } |
370 | ]; | 377 | ]; |
@@ -390,7 +397,10 @@ module.exports = function(flag) { | @@ -390,7 +397,10 @@ module.exports = function(flag) { | ||
390 | url: '', | 397 | url: '', |
391 | publishTime: '2月13日 12:34', | 398 | publishTime: '2月13日 12:34', |
392 | pageView: 3445, | 399 | pageView: 3445, |
393 | - like: true, | 400 | + like: { |
401 | + count: 459, | ||
402 | + isLiked: true | ||
403 | + }, | ||
394 | share: false //不显示share标签 | 404 | share: false //不显示share标签 |
395 | }, | 405 | }, |
396 | { | 406 | { |
@@ -405,7 +415,7 @@ module.exports = function(flag) { | @@ -405,7 +415,7 @@ module.exports = function(flag) { | ||
405 | url: '', | 415 | url: '', |
406 | publishTime: '2月13日 12:34', | 416 | publishTime: '2月13日 12:34', |
407 | pageView: 3445, | 417 | pageView: 3445, |
408 | - like: true, | 418 | + like: false, |
409 | share: false | 419 | share: false |
410 | } | 420 | } |
411 | ] | 421 | ] |
@@ -490,7 +500,10 @@ module.exports = function(flag) { | @@ -490,7 +500,10 @@ module.exports = function(flag) { | ||
490 | 'In England中Panul Smith缔造了一个传奇', | 500 | 'In England中Panul Smith缔造了一个传奇', |
491 | publishTime: '2月13日 12:34', | 501 | publishTime: '2月13日 12:34', |
492 | pageView: 3445, | 502 | pageView: 3445, |
493 | - like: true, | 503 | + like: { |
504 | + count: 459, | ||
505 | + isLiked: true | ||
506 | + }, | ||
494 | share: true, | 507 | share: true, |
495 | url: '', | 508 | url: '', |
496 | likeUrl: '' | 509 | likeUrl: '' |
@@ -503,7 +516,10 @@ module.exports = function(flag) { | @@ -503,7 +516,10 @@ module.exports = function(flag) { | ||
503 | 'In England中Panul Smith缔造了一个传奇', | 516 | 'In England中Panul Smith缔造了一个传奇', |
504 | publishTime: '2月13日 12:34', | 517 | publishTime: '2月13日 12:34', |
505 | pageView: 3445, | 518 | pageView: 3445, |
506 | - like: true, | 519 | + like: { |
520 | + count: 100, | ||
521 | + isLiked: false | ||
522 | + }, | ||
507 | share: true, | 523 | share: true, |
508 | url: '', | 524 | url: '', |
509 | likeUrl: '' | 525 | likeUrl: '' |
@@ -130,22 +130,24 @@ exports.init = function() { | @@ -130,22 +130,24 @@ exports.init = function() { | ||
130 | $('#info-content').delegate('.like-btn', 'touchstart', function(e) { | 130 | $('#info-content').delegate('.like-btn', 'touchstart', function(e) { |
131 | var $cur = $(e.currentTarget), | 131 | var $cur = $(e.currentTarget), |
132 | $info = $cur.closest('.info-block'), | 132 | $info = $cur.closest('.info-block'), |
133 | - id = $info.data('id'); | 133 | + id = $info.data('id'), |
134 | + url; | ||
134 | //取消点赞的处理 | 135 | //取消点赞的处理 |
135 | - if ($cur.hasClass('like')) { | ||
136 | - $cur.next('span.like-count').text(''); | ||
137 | $cur.toggleClass('like'); | 136 | $cur.toggleClass('like'); |
138 | - return; | 137 | + |
138 | + if ($cur.hasClass('like')) { | ||
139 | + url = '/guang/info/praise'; | ||
140 | + } else { | ||
141 | + url = '/guang/info/cancelpraise'; | ||
139 | } | 142 | } |
140 | $.ajax({ | 143 | $.ajax({ |
141 | type: 'GET', | 144 | type: 'GET', |
142 | - url: '/favorite/praise', | 145 | + url: url, |
143 | data: { | 146 | data: { |
144 | id: id | 147 | id: id |
145 | } | 148 | } |
146 | }).then(function(data) { | 149 | }).then(function(data) { |
147 | if (data.code === 200) { | 150 | if (data.code === 200) { |
148 | - $cur.toggleClass('like'); | ||
149 | //更新点赞数 | 151 | //更新点赞数 |
150 | $cur.next('span.like-count').text(data.data); | 152 | $cur.next('span.like-count').text(data.data); |
151 | } else if (data.code === 400) { | 153 | } else if (data.code === 400) { |
@@ -85,26 +85,27 @@ exports.init = function() { | @@ -85,26 +85,27 @@ exports.init = function() { | ||
85 | this.mlellipsis(2); | 85 | this.mlellipsis(2); |
86 | }); | 86 | }); |
87 | 87 | ||
88 | - //文章点赞 | 88 | + //文章点赞和取消点赞 |
89 | $('.tag-container').delegate('.like-btn', 'touchstart', function(e) { | 89 | $('.tag-container').delegate('.like-btn', 'touchstart', function(e) { |
90 | var $cur = $(e.currentTarget), | 90 | var $cur = $(e.currentTarget), |
91 | $info = $cur.closest('.tag-content'), | 91 | $info = $cur.closest('.tag-content'), |
92 | - id = $info.data('id'); | ||
93 | - //点赞的只有取消点赞的效果, 不发送请求, 不改变点赞数字 | ||
94 | - if ($cur.hasClass('like')) { | ||
95 | - $cur.next('span.like-count').text(''); | 92 | + id = $info.data('id'), |
93 | + url; | ||
96 | $cur.toggleClass('like'); | 94 | $cur.toggleClass('like'); |
97 | - return; | 95 | + |
96 | + if ($cur.hasClass('like')) { | ||
97 | + url = '/guang/info/praise'; | ||
98 | + } else { | ||
99 | + url = '/guang/info/cancelpraise'; | ||
98 | } | 100 | } |
99 | $.ajax({ | 101 | $.ajax({ |
100 | type: 'GET', | 102 | type: 'GET', |
101 | - url: '/favorite/praise', | 103 | + url: url, |
102 | data: { | 104 | data: { |
103 | id: id | 105 | id: id |
104 | } | 106 | } |
105 | }).then(function(data) { | 107 | }).then(function(data) { |
106 | if (data.code === 200) { | 108 | if (data.code === 200) { |
107 | - $cur.toggleClass('like'); | ||
108 | //更新点赞数 | 109 | //更新点赞数 |
109 | $cur.next('span.like-count').text(data.data); | 110 | $cur.next('span.like-count').text(data.data); |
110 | } else if (data.code === 400) { | 111 | } else if (data.code === 400) { |
@@ -28,7 +28,9 @@ module.exports = function(app) { | @@ -28,7 +28,9 @@ module.exports = function(app) { | ||
28 | 28 | ||
29 | app.get('/favorite/product', fav.prod); //商品收藏或取消收藏 | 29 | app.get('/favorite/product', fav.prod); //商品收藏或取消收藏 |
30 | app.get('/favorite/brand', fav.brand); //品牌收藏或取消收藏 | 30 | app.get('/favorite/brand', fav.brand); //品牌收藏或取消收藏 |
31 | - app.get('/favorite/praise', fav.article); //文章点赞或取消点赞 | 31 | + |
32 | + app.get('/guang/info/praise', fav.article); //文章点赞或取消点赞 | ||
33 | + app.get('/guang/info/cancelpraise', fav.article); | ||
32 | 34 | ||
33 | app.get('/common/articletpl', ps.readTpl); //获取相关资讯模板 | 35 | app.get('/common/articletpl', ps.readTpl); //获取相关资讯模板 |
34 | app.get('/common/goodinfo', template.readTpl); //读取模板 | 36 | app.get('/common/goodinfo', template.readTpl); //读取模板 |
@@ -48,17 +48,21 @@ exports.brand = function(req, res) { | @@ -48,17 +48,21 @@ exports.brand = function(req, res) { | ||
48 | 48 | ||
49 | //文章点赞或取消点赞 | 49 | //文章点赞或取消点赞 |
50 | exports.article = function(req, res) { | 50 | exports.article = function(req, res) { |
51 | - if (req.query.st === '0') { | ||
52 | - res.send({ | ||
53 | - code: 400, | ||
54 | - message: "", | ||
55 | - data: 99 | ||
56 | - }); | ||
57 | - } else { | 51 | + // if (req.query.st === '0') { |
52 | + // res.send({ | ||
53 | + // code: 400, | ||
54 | + // message: "", | ||
55 | + // data: 99 | ||
56 | + // }); | ||
57 | + // } else { | ||
58 | + // res.send({ | ||
59 | + // code: 200, | ||
60 | + // message: "", | ||
61 | + // data: 100 | ||
62 | + // }); | ||
63 | + // } | ||
58 | res.send({ | 64 | res.send({ |
59 | code: 200, | 65 | code: 200, |
60 | - message: "", | ||
61 | - data: 100 | 66 | + data: parseInt(Math.random() * 100, 10) |
62 | }); | 67 | }); |
63 | - } | ||
64 | }; | 68 | }; |
@@ -5,8 +5,8 @@ | @@ -5,8 +5,8 @@ | ||
5 | {{pageView}} | 5 | {{pageView}} |
6 | <div class="like-share-container"> | 6 | <div class="like-share-container"> |
7 | {{# like}} | 7 | {{# like}} |
8 | - <a href="javascript:;" class="iconfont like-btn"></a> | ||
9 | - <span class="like-count"></span> | 8 | + <a href="javascript:;" class="iconfont like-btn{{#isLiked}} like{{/isLiked}}"></a> |
9 | + <span class="like-count">{{count}}</span> | ||
10 | {{/ like}} | 10 | {{/ like}} |
11 | {{# share}} | 11 | {{# share}} |
12 | <a href="{{.}}" class="iconfont share-btn"></a> | 12 | <a href="{{.}}" class="iconfont share-btn"></a> |
-
Please register or login to post a comment