Authored by Aiden Xu

资讯详情

@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 9
10 // const helpers = global.yoho.helpers; 10 // const helpers = global.yoho.helpers;
11 const model = require('../models/detail'); 11 const model = require('../models/detail');
  12 +const camelCase = global.yoho.camelCase;
12 13
13 /** 14 /**
14 * 商品详情 15 * 商品详情
@@ -46,9 +47,11 @@ const component = { @@ -46,9 +47,11 @@ const component = {
46 const params = { 47 const params = {
47 article_id: req.params[0], 48 article_id: req.params[0],
48 udid: req.sessionID 49 udid: req.sessionID
  50 +
  51 + // uid: req.user.uid || 8050378
49 }; 52 };
50 53
51 - model.like(params, Boolean.valueOf(params.flag)).then(result => { 54 + model.like(params, 'true' === req.query.flag).then(result => {
52 res.json(result); 55 res.json(result);
53 }).catch(next); 56 }).catch(next);
54 }, 57 },
@@ -75,9 +78,28 @@ const component = { @@ -75,9 +78,28 @@ const component = {
75 return; 78 return;
76 } 79 }
77 */ 80 */
78 - model.favorite(params, Boolean.valueOf(params.flag)).then(result => { 81 + model.favorite(params, 'true' === req.query.flag).then(result => {
79 res.json(result); 82 res.json(result);
80 }).catch(next); 83 }).catch(next);
  84 + },
  85 +
  86 + /**
  87 + * 杂项信息
  88 + *
  89 + * @param req
  90 + * @param res
  91 + * @param next
  92 + */
  93 + misc(req, res, next) {
  94 + const params = {
  95 + article_id: req.params[0],
  96 + uid: req.user.uid || 8050378,
  97 + udid: req.sessionID
  98 + };
  99 +
  100 + model.misc(params).then(result => {
  101 + res.json(camelCase(result));
  102 + }).catch(next);
81 } 103 }
82 }; 104 };
83 105
@@ -27,9 +27,8 @@ const model = { @@ -27,9 +27,8 @@ const model = {
27 offset: 0, 27 offset: 0,
28 limit: 3 28 limit: 3
29 }, params)); 29 }, params));
30 - const base = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', params);  
31 30
32 - return camelCase([article, content, brands, other, base]); 31 + return camelCase([article, content, brands, other]);
33 })(); 32 })();
34 }, 33 },
35 34
@@ -41,11 +40,21 @@ const model = { @@ -41,11 +40,21 @@ const model = {
41 * @returns {*} 40 * @returns {*}
42 */ 41 */
43 like(params, flag) { 42 like(params, flag) {
44 - if (flag) {  
45 - return serviceAPI.get('guang/api/v2/praise/setPraise', params);  
46 - } else {  
47 - return serviceAPI.get('guang/api/v2/praise/cancel', params);  
48 - } 43 + return Promise.coroutine(function*() {
  44 + let ret = null;
  45 +
  46 + if (flag) {
  47 + ret = yield serviceAPI.get('guang/api/v2/praise/setPraise', params);
  48 + } else {
  49 + ret = yield serviceAPI.get('guang/api/v2/praise/cancel', params);
  50 + }
  51 +
  52 + const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
  53 + id: params.article_id
  54 + }, params));
  55 +
  56 + return [ret, misc];
  57 + })();
49 }, 58 },
50 59
51 /** 60 /**
@@ -56,11 +65,32 @@ const model = { @@ -56,11 +65,32 @@ const model = {
56 * @returns {*} 65 * @returns {*}
57 */ 66 */
58 favorite(params, flag) { 67 favorite(params, flag) {
59 - if (flag) {  
60 - return serviceAPI.get('guang/api/v1/favorite/setFavorite', params);  
61 - } else {  
62 - return serviceAPI.get('guang/api/v1/favorite/cancelFavorite', params);  
63 - } 68 + return Promise.coroutine(function*() {
  69 + let ret = null;
  70 +
  71 + if (flag) {
  72 + ret = yield serviceAPI.get('guang/api/v1/favorite/setFavorite', params);
  73 + } else {
  74 + ret = yield serviceAPI.get('guang/api/v1/favorite/cancelFavorite', params);
  75 + }
  76 +
  77 + const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
  78 + id: params.article_id
  79 + }, params));
  80 +
  81 + return [ret, misc];
  82 + })();
  83 + },
  84 +
  85 + /**
  86 + * 其它信息
  87 + *
  88 + * @param params
  89 + */
  90 + misc(params) {
  91 + return serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
  92 + id: params.article_id
  93 + }, params));
64 } 94 }
65 }; 95 };
66 96
@@ -17,6 +17,7 @@ router.get(/\/([\d]+)(.*)/, detail.index); // 详情routers @@ -17,6 +17,7 @@ router.get(/\/([\d]+)(.*)/, detail.index); // 详情routers
17 router.get(/news_(\d+)\.json/, detail.news); 17 router.get(/news_(\d+)\.json/, detail.news);
18 router.get(/like_(\d+)\.json/, detail.like); 18 router.get(/like_(\d+)\.json/, detail.like);
19 router.get(/favorite_(\d+)\.json/, detail.favorite); 19 router.get(/favorite_(\d+)\.json/, detail.favorite);
  20 +router.get(/misc_(\d+)\.json/, detail.misc);
20 21
21 const news = require(`${cRoot}/index`); 22 const news = require(`${cRoot}/index`);
22 23
@@ -43,12 +43,12 @@ const model = { @@ -43,12 +43,12 @@ const model = {
43 * 43 *
44 * @param params 44 * @param params
45 */ 45 */
46 - favorite(params) { 46 + favorite(params, flag) {
47 let method = ''; 47 let method = '';
48 48
49 - if (params.operation === 'add') { 49 + if (flag) {
50 method = 'app.favorite.add'; 50 method = 'app.favorite.add';
51 - } else if (params.operation === 'remove') { 51 + } else {
52 method = 'app.favorite.cancel'; 52 method = 'app.favorite.cancel';
53 } 53 }
54 54
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <h1>{{article.articleTitle}}</h1> 5 <h1>{{article.articleTitle}}</h1>
6 <div class="status-bar"> 6 <div class="status-bar">
7 <span class="icon icon-timeshare"></span><span class="label">{{article.publishTime | formatUnixTime 'MM.DD HH:mm'}}</span> 7 <span class="icon icon-timeshare"></span><span class="label">{{article.publishTime | formatUnixTime 'MM.DD HH:mm'}}</span>
8 - <span class="icon icon-eye"></span><span class="label">{{article.pageViews}}</span> 8 + <span class="icon icon-read"></span><span class="label">{{article.pageViews}}</span>
9 </div> 9 </div>
10 </div> 10 </div>
11 11
@@ -57,10 +57,6 @@ @@ -57,10 +57,6 @@
57 } 57 }
58 58
59 .show-box { 59 .show-box {
60 - &.first-box {  
61 - margin-top: 80px;  
62 - }  
63 -  
64 background: $bgcolor; 60 background: $bgcolor;
65 margin-top: 30px; 61 margin-top: 30px;
66 border-bottom: 1px solid #eee; 62 border-bottom: 1px solid #eee;
@@ -205,6 +201,7 @@ @@ -205,6 +201,7 @@
205 init() { 201 init() {
206 const newsId = $('#app').data('newsId'); 202 const newsId = $('#app').data('newsId');
207 203
  204 + this.id = newsId;
208 let loadDeferred = null; 205 let loadDeferred = null;
209 206
210 $.get(`/news/news_${newsId}.json`).then(result => { 207 $.get(`/news/news_${newsId}.json`).then(result => {
@@ -212,6 +209,7 @@ @@ -212,6 +209,7 @@
212 content = result[1], 209 content = result[1],
213 brands = result[2], 210 brands = result[2],
214 other = result[3]; 211 other = result[3];
  212 +
215 let goods, prodMap = {}; 213 let goods, prodMap = {};
216 214
217 if (article && article.code === 200 && article.data) { 215 if (article && article.code === 200 && article.data) {
@@ -225,7 +223,6 @@ @@ -225,7 +223,6 @@
225 return block && typeof block.goods === 'object'; 223 return block && typeof block.goods === 'object';
226 }); 224 });
227 225
228 -  
229 const list = []; 226 const list = [];
230 227
231 goods = products[0] ? products[0].goods.data : null; 228 goods = products[0] ? products[0].goods.data : null;
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <navbar> 3 <navbar>
4 <template slot="right"> 4 <template slot="right">
5 <a class="right-button" href="javascript:void(0);" @click="like()"> 5 <a class="right-button" href="javascript:void(0);" @click="like()">
6 - <span class="icon icon-check"></span> 6 + <span class="icon icon-like" :class=""></span>
7 {{likeCount}} 7 {{likeCount}}
8 </a> 8 </a>
9 9
@@ -42,7 +42,8 @@ @@ -42,7 +42,8 @@
42 return { 42 return {
43 isApp: yoho.isApp, 43 isApp: yoho.isApp,
44 likeCount: this.article.praise, 44 likeCount: this.article.praise,
45 - isFavorite: false 45 + isFavorite: false,
  46 + isLiked: false
46 }; 47 };
47 }, 48 },
48 watch: { 49 watch: {
@@ -52,18 +53,33 @@ @@ -52,18 +53,33 @@
52 }, 53 },
53 methods: { 54 methods: {
54 like: function() { 55 like: function() {
55 - $.get(`/news/like_${this.article.id}.json`, (result)=> { 56 + $.get(`/news/like_${this.article.id}.json`, {
  57 + flag: !this.isLiked
  58 + }, (results)=> {
  59 + const result = results[0], misc = results[1];
  60 +
56 if (result.code === 200) { 61 if (result.code === 200) {
57 this.likeCount = result.data; 62 this.likeCount = result.data;
58 } 63 }
  64 +
  65 + if (misc.code === 200) {
  66 + this.isLiked = misc.data.isPraise === 'Y';
  67 + }
59 }); 68 });
60 }, 69 },
61 favorite: function() { 70 favorite: function() {
62 - $.get(`/news/favorite_${this.article.id}.json`, (result)=> { 71 + $.get(`/news/favorite_${this.article.id}.json`, {
  72 + flag: !this.isFavorite
  73 + }, (results)=> {
  74 + const result = results[0], misc = results[1];
  75 +
63 if (result.code === 200) { 76 if (result.code === 200) {
64 - //this.  
65 // TODO: 77 // TODO:
66 } 78 }
  79 +
  80 + if (misc.code === 200) {
  81 + this.isFavorite = misc.data.isFavor === 'Y';
  82 + }
67 }); 83 });
68 }, 84 },
69 share: function() { 85 share: function() {
@@ -81,6 +97,14 @@ @@ -81,6 +97,14 @@
81 }) 97 })
82 }); 98 });
83 } 99 }
  100 + },
  101 + created() {
  102 + $.get(`/news/misc_${this.id}.json`).then(result => {
  103 + if (result.code === 200) {
  104 + this.isFavorite = result.data.isFavor === 'Y';
  105 + this.isLiked = result.data.isPraise === 'Y';
  106 + }
  107 + });
84 } 108 }
85 }; 109 };
86 </script> 110 </script>