Authored by Aiden Xu

资讯详情

@@ -25,7 +25,7 @@ const component = { @@ -25,7 +25,7 @@ const component = {
25 const id = req.params[0]; 25 const id = req.params[0];
26 26
27 let params = { 27 let params = {
28 - uid: req.user.uid || 0, 28 + uid: req.user.uid || 8050378,
29 article_id: id, 29 article_id: id,
30 client_type: 'h5' 30 client_type: 'h5'
31 }; 31 };
@@ -33,6 +33,51 @@ const component = { @@ -33,6 +33,51 @@ const component = {
33 model.index(params).then(result => { 33 model.index(params).then(result => {
34 res.json(result); 34 res.json(result);
35 }).catch(next); 35 }).catch(next);
  36 + },
  37 +
  38 + /**
  39 + * 点赞
  40 + *
  41 + * @param req
  42 + * @param res
  43 + * @param next
  44 + */
  45 + like(req, res, next) {
  46 + const params = {
  47 + article_id: req.params[0],
  48 + udid: req.sessionID
  49 + };
  50 +
  51 + model.like(params, Boolean.valueOf(params.flag)).then(result => {
  52 + res.json(result);
  53 + }).catch(next);
  54 + },
  55 +
  56 + /**
  57 + * 收藏
  58 + *
  59 + * @param req
  60 + * @param res
  61 + * @param next
  62 + */
  63 + favorite(req, res, next) {
  64 + const params = {
  65 + article_id: req.params[0],
  66 + uid: req.user.uid || 8050378
  67 + };
  68 +
  69 + /*
  70 + if (!req.user.id) {
  71 + res.json({
  72 + code: 403
  73 + });
  74 +
  75 + return;
  76 + }
  77 + */
  78 + model.favorite(params, Boolean.valueOf(params.flag)).then(result => {
  79 + res.json(result);
  80 + }).catch(next);
36 } 81 }
37 }; 82 };
38 83
@@ -27,9 +27,40 @@ const model = { @@ -27,9 +27,40 @@ const model = {
27 offset: 0, 27 offset: 0,
28 limit: 3 28 limit: 3
29 }, params)); 29 }, params));
  30 + const base = yield serviceAPI.get(URI_PACKAGE_ARTICLE + 'getArticleBaseInfo', params);
30 31
31 - return camelCase([article, content, brands, other]); 32 + return camelCase([article, content, brands, other, base]);
32 })(); 33 })();
  34 + },
  35 +
  36 + /**
  37 + * 点赞
  38 + *
  39 + * @param params
  40 + * @param flag
  41 + * @returns {*}
  42 + */
  43 + 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 + }
  49 + },
  50 +
  51 + /**
  52 + * 收藏
  53 + *
  54 + * @param params
  55 + * @param flag
  56 + * @returns {*}
  57 + */
  58 + 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 + }
33 } 64 }
34 }; 65 };
35 66
@@ -15,6 +15,8 @@ const detail = require(`${cRoot}/detail`); @@ -15,6 +15,8 @@ const detail = require(`${cRoot}/detail`);
15 15
16 router.get(/\/([\d]+)(.*)/, detail.index); // 详情routers 16 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);
  19 +router.get(/favorite_(\d+)\.json/, detail.favorite);
18 20
19 const news = require(`${cRoot}/index`); 21 const news = require(`${cRoot}/index`);
20 22
1 <template> 1 <template>
2 - <top-nav></top-nav>  
3 - <div class="show-box no-padding first-box" :class="{'is-app': isApp}"> 2 + <top-nav :id="id" :article="article"></top-nav>
  3 + <div class="show-box no-padding first-box">
4 <div class="news-box"> 4 <div class="news-box">
5 <h1>{{article.articleTitle}}</h1> 5 <h1>{{article.articleTitle}}</h1>
6 <div class="status-bar"> 6 <div class="status-bar">
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 </ul> 31 </ul>
32 </div> 32 </div>
33 33
34 - <div class="show-box" v-if="other"> 34 + <div class="show-box" v-if="other && other.length > 0">
35 <h2>相关文章</h2> 35 <h2>相关文章</h2>
36 <div class="other-box" v-for="item in other"> 36 <div class="other-box" v-for="item in other">
37 <div> 37 <div>
@@ -58,11 +58,7 @@ @@ -58,11 +58,7 @@
58 58
59 .show-box { 59 .show-box {
60 &.first-box { 60 &.first-box {
61 - margin-top: 120px;  
62 - }  
63 -  
64 - &.first-box.is-app {  
65 - margin-top: 180px; 61 + margin-top: 80px;
66 } 62 }
67 63
68 background: $bgcolor; 64 background: $bgcolor;
@@ -206,8 +202,9 @@ @@ -206,8 +202,9 @@
206 recommendProducts: [] 202 recommendProducts: []
207 }; 203 };
208 }, 204 },
209 - created() { 205 + init() {
210 const newsId = $('#app').data('newsId'); 206 const newsId = $('#app').data('newsId');
  207 +
211 let loadDeferred = null; 208 let loadDeferred = null;
212 209
213 $.get(`/news/news_${newsId}.json`).then(result => { 210 $.get(`/news/news_${newsId}.json`).then(result => {
@@ -264,7 +261,6 @@ @@ -264,7 +261,6 @@
264 this.other = other.data; 261 this.other = other.data;
265 } 262 }
266 263
267 -  
268 // 延时读取商品价格、名称等信息 264 // 延时读取商品价格、名称等信息
269 loadDeferred = () => { 265 loadDeferred = () => {
270 $.get('/product/search_product.json', { 266 $.get('/product/search_product.json', {
1 <template> 1 <template>
2 <div class="top-nav"> 2 <div class="top-nav">
3 <navbar> 3 <navbar>
4 - <a slot="left" href="javascript:alert('TODO');">  
5 - <span class="icon icon-left"></span>  
6 - </a>  
7 -  
8 <template slot="right"> 4 <template slot="right">
9 - <a class="right-button" href="javascript:alert('TODO');"> 5 + <a class="right-button" href="javascript:void(0);" @click="like()">
10 <span class="icon icon-check"></span> 6 <span class="icon icon-check"></span>
11 {{likeCount}} 7 {{likeCount}}
12 </a> 8 </a>
13 9
14 - <a class="right-button" href="javascript:alert('TODO');">  
15 - <span class="icon icon-love"></span> 10 + <a class="right-button" href="javascript:void(0);" @click="favorite()">
  11 + <span class="icon" :class="{ 'icon-love': !isFavorite, 'icon-love-solid': isFavorite}"></span>
16 </a> 12 </a>
17 13
18 - <a class="right-button" href="javascript:alert('TODO');"> 14 + <a class="right-button" href="javascript:void(0);" @click="share()">
19 <span class="icon icon-share"></span> 15 <span class="icon icon-share"></span>
20 </a> 16 </a>
21 </template> 17 </template>
@@ -35,16 +31,56 @@ @@ -35,16 +31,56 @@
35 require('common/vue-filter'); 31 require('common/vue-filter');
36 32
37 module.exports = { 33 module.exports = {
  34 + props: {
  35 + id: Number,
  36 + article: Object
  37 + },
38 components: { 38 components: {
39 navbar: require('component/header.vue') 39 navbar: require('component/header.vue')
40 }, 40 },
41 data() { 41 data() {
42 return { 42 return {
43 isApp: yoho.isApp, 43 isApp: yoho.isApp,
44 - likeCount: 9, 44 + likeCount: this.article.praise,
  45 + isFavorite: false
45 }; 46 };
46 }, 47 },
47 - created() { 48 + watch: {
  49 + article: function() {
  50 + this.likeCount = this.article.praise;
  51 + }
  52 + },
  53 + methods: {
  54 + like: function() {
  55 + $.get(`/news/like_${this.article.id}.json`, (result)=> {
  56 + if (result.code === 200) {
  57 + this.likeCount = result.data;
  58 + }
  59 + });
  60 + },
  61 + favorite: function() {
  62 + $.get(`/news/favorite_${this.article.id}.json`, (result)=> {
  63 + if (result.code === 200) {
  64 + //this.
  65 + // TODO:
  66 + }
  67 + });
  68 + },
  69 + share: function() {
  70 + yoho.goShare({
  71 + title: this.article.articleTitle,
  72 + des: '优质精选,BLK潮流资讯为你呈现',
  73 + img: this.article.coverImage.replace(/(\{width}|\{height}|\{mode})/g, function($0) {
  74 + const dict = {
  75 + '{width}': 300,
  76 + '{height}': 300,
  77 + '{mode}': 2
  78 + };
  79 +
  80 + return dict[$0];
  81 + })
  82 + });
  83 + }
48 } 84 }
49 }; 85 };
50 </script> 86 </script>