Authored by Aiden Xu

资讯详情

@@ -17,15 +17,21 @@ const component = { @@ -17,15 +17,21 @@ const component = {
17 index(req, res) { 17 index(req, res) {
18 res.render('detail', { 18 res.render('detail', {
19 module: 'news', 19 module: 'news',
20 - page: 'detail' 20 + page: 'detail',
  21 + newsId: req.params[0]
21 }); 22 });
22 }, 23 },
23 news(req, res, next) { 24 news(req, res, next) {
  25 + const id = req.params[0];
  26 +
24 let params = { 27 let params = {
25 - uid: req.user.uid || 8050378 // TODO: fix this hard coded uid 28 + // uid: req.user.uid || 8050378 // TODO: fix this hard coded uid
  29 + article_id: id,
  30 + client_type: 'h5'
26 }; 31 };
27 32
28 - model.product(params).then(result => { 33 +
  34 + model.index(params).then(result => {
29 res.json(result); 35 res.json(result);
30 }).catch(next); 36 }).catch(next);
31 } 37 }
@@ -8,16 +8,27 @@ @@ -8,16 +8,27 @@
8 // const _ = require('lodash'); 8 // const _ = require('lodash');
9 9
10 // const helpers = global.yoho.helpers; 10 // const helpers = global.yoho.helpers;
11 -const api = global.yoho.API; 11 +const serviceAPI = global.yoho.ServiceAPI;
  12 +const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
  13 +const co = require('co');
  14 +const camelCase = global.yoho.camelCase;
12 15
13 /** 16 /**
14 * 资讯详情 17 * 资讯详情
15 */ 18 */
16 const model = { 19 const model = {
17 - product(params) {  
18 - return api.get('', Object.assign({  
19 - method: 'h5.product.data' 20 + index(params) {
  21 + return co(function*() {
  22 + const article = yield serviceAPI.get(URI_PACKAGE_ARTICLE + 'getArticle', params);
  23 + const content = yield serviceAPI.get(URI_PACKAGE_ARTICLE + 'getArticleContent', params);
  24 + const other = yield serviceAPI.get(URI_PACKAGE_ARTICLE + 'getOtherArticle', Object.assign({
  25 + tags: article.data.tag,
  26 + offset: 0,
  27 + limit: 3
20 }, params)); 28 }, params));
  29 +
  30 + return camelCase([article, content, other]);
  31 + });
21 } 32 }
22 }; 33 };
23 34
@@ -14,4 +14,5 @@ const router = expressRouter(); @@ -14,4 +14,5 @@ const router = expressRouter();
14 const detail = require(`${cRoot}/detail`); 14 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 module.exports = router; 18 module.exports = router;
1 -<div id="app" class="news-page">  
2 - Damn news! 1 +<div id="app" class="news-page" data-news-id="{{newsId}}">
3 <app/> 2 <app/>
4 </div> 3 </div>
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 "dependencies": { 21 "dependencies": {
22 "bluebird": "^3.4.1", 22 "bluebird": "^3.4.1",
23 "body-parser": "^1.15.2", 23 "body-parser": "^1.15.2",
  24 + "co": "^4.6.0",
24 "connect-memcached": "^0.2.0", 25 "connect-memcached": "^0.2.0",
25 "connect-multiparty": "^2.0.0", 26 "connect-multiparty": "^2.0.0",
26 "cookie-parser": "^1.4.3", 27 "cookie-parser": "^1.4.3",
1 let Vue = require('yoho-vue'); 1 let Vue = require('yoho-vue');
2 - 2 +const moment = require('moment');
3 3
4 /** 4 /**
5 * 替换参数 5 * 替换参数
@@ -113,3 +113,11 @@ Vue.filter('convertTime', (value) => { @@ -113,3 +113,11 @@ Vue.filter('convertTime', (value) => {
113 113
114 return Y + M + D + h + m + s; 114 return Y + M + D + h + m + s;
115 }); 115 });
  116 +
  117 +
  118 +/**
  119 + * 格式化时间
  120 + */
  121 +Vue.filter('formatUnixTime', (value, format) => {
  122 + return moment.unix(value).format(format || 'YYYY-MM-DD HH:mm:ss');
  123 +});
  1 +<template>
  2 + <div v-if="block.text" class="text-block">
  3 + {{{block.text.data.text}}}
  4 + </div>
  5 +
  6 + <div v-if="block.singleImage">
  7 + <div v-for="(index, item) in block.singleImage.data">
  8 + <a :href="item.url">
  9 + <img :title="item.title"
  10 + :alt="item.alt"
  11 + :src="item.src | resize 750 469" width="375"/>
  12 + </a>
  13 + </div>
  14 + </div>
  15 +</template>
  16 +<style></style>
  17 +<script>
  18 + module.exports = {
  19 + props: {
  20 + block: Object
  21 + }
  22 + };
  23 +</script>
1 -h1 {  
2 - font-size: 43px;  
3 - font-weight: bold;  
4 - overflow: hidden;  
5 - margin-top: 36px;  
6 - margin-bottom: 0;  
7 -}  
8 -  
9 -.news-box {  
10 - padding: 30px;  
11 -}  
1 <template> 1 <template>
2 <div class="news-box"> 2 <div class="news-box">
3 - <h1>日韩风日韩风日韩风日韩风日韩风日韩风日韩风</h1>  
4 - <span class="icon icon-love"></span>  
5 - <span class="icon icon-love"></span> 3 + <h1>{{article.articleTitle}}</h1>
  4 + <div class="status-bar">
  5 + <span class="icon icon-love"></span><span class="label">{{article.publishTime | formatUnixTime 'MM.DD HH:mm'}}</span>
  6 + <span class="icon icon-love"></span><span class="label">{{article.pageViews}}</span>
  7 + </div>
  8 + </div>
  9 +
  10 + <div class="content-box">
  11 + <div v-for="(index, block) in content">
  12 + <content-block :block="block"></content-block>
  13 + </div>
  14 + </div>
  15 +
  16 + <div v-for="block in other">
  17 + <div>
  18 + <img :src="block.thumb | resize 213 134" width="107"/>
  19 + <h2></h2>
  20 + </div>
6 </div> 21 </div>
7 </template> 22 </template>
8 -<style src="./css/detail.css"></style>  
9 -<script src="./js/detail.js"></script> 23 +<style>
  24 + h1 {
  25 + font-size: 43px;
  26 + font-weight: bold;
  27 + overflow: hidden;
  28 + margin-top: 36px;
  29 + margin-bottom: 0;
  30 + }
  31 +
  32 + .news-box {
  33 + padding: 30px;
  34 + }
  35 +
  36 + .content-box {
  37 +
  38 + img {
  39 + width: 100%;
  40 + display: block;
  41 + }
  42 +
  43 + p {
  44 + font-size: 28px;
  45 + }
  46 +
  47 + .text-block {
  48 + padding: 30px;
  49 + }
  50 +
  51 + }
  52 +
  53 + .status-bar {
  54 + color: #ccc;
  55 + font-size: 24px;
  56 + margin-top: 30px;
  57 +
  58 + span.icon {
  59 + margin-right: 12px;
  60 + }
  61 +
  62 + span.label {
  63 + margin-right: 78px;
  64 + }
  65 +
  66 + }
  67 +
  68 +</style>
  69 +<script>
  70 + require('common/vue-filter');
  71 +
  72 + module.exports = {
  73 + components: {
  74 + 'content-block': require('./content-block.vue')
  75 + },
  76 + data() {
  77 + return {
  78 + article: {},
  79 + content: {},
  80 + other: {}
  81 + };
  82 + },
  83 + created() {
  84 + const newsId = $('#app').data('newsId');
  85 +
  86 + $.get(`/news/news_${newsId}.json`).then(result => {
  87 + const article = result[0], content = result[1], other = result[2];
  88 +
  89 + if (article && article.code === 200 && article.data) {
  90 + this.article = article.data;
  91 + }
  92 +
  93 + if (content && content.code === 200 && content.data) {
  94 + this.content = content.data;
  95 + }
  96 +
  97 + if (other && other.code === 200 && content.data) {
  98 + this.other = other.data;
  99 + }
  100 + });
  101 + }
  102 + };
  103 +</script>
1 -module.exports = {  
2 - components: {  
3 -  
4 - }  
5 -};