Authored by Aiden Xu

资讯详情

... ... @@ -9,6 +9,7 @@
// const helpers = global.yoho.helpers;
const model = require('../models/detail');
const camelCase = global.yoho.camelCase;
/**
* 商品详情
... ... @@ -46,9 +47,11 @@ const component = {
const params = {
article_id: req.params[0],
udid: req.sessionID
// uid: req.user.uid || 8050378
};
model.like(params, Boolean.valueOf(params.flag)).then(result => {
model.like(params, 'true' === req.query.flag).then(result => {
res.json(result);
}).catch(next);
},
... ... @@ -75,9 +78,28 @@ const component = {
return;
}
*/
model.favorite(params, Boolean.valueOf(params.flag)).then(result => {
model.favorite(params, 'true' === req.query.flag).then(result => {
res.json(result);
}).catch(next);
},
/**
* 杂项信息
*
* @param req
* @param res
* @param next
*/
misc(req, res, next) {
const params = {
article_id: req.params[0],
uid: req.user.uid || 8050378,
udid: req.sessionID
};
model.misc(params).then(result => {
res.json(camelCase(result));
}).catch(next);
}
};
... ...
... ... @@ -27,9 +27,8 @@ const model = {
offset: 0,
limit: 3
}, params));
const base = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', params);
return camelCase([article, content, brands, other, base]);
return camelCase([article, content, brands, other]);
})();
},
... ... @@ -41,11 +40,21 @@ const model = {
* @returns {*}
*/
like(params, flag) {
if (flag) {
return serviceAPI.get('guang/api/v2/praise/setPraise', params);
} else {
return serviceAPI.get('guang/api/v2/praise/cancel', params);
}
return Promise.coroutine(function*() {
let ret = null;
if (flag) {
ret = yield serviceAPI.get('guang/api/v2/praise/setPraise', params);
} else {
ret = yield serviceAPI.get('guang/api/v2/praise/cancel', params);
}
const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
id: params.article_id
}, params));
return [ret, misc];
})();
},
/**
... ... @@ -56,11 +65,32 @@ const model = {
* @returns {*}
*/
favorite(params, flag) {
if (flag) {
return serviceAPI.get('guang/api/v1/favorite/setFavorite', params);
} else {
return serviceAPI.get('guang/api/v1/favorite/cancelFavorite', params);
}
return Promise.coroutine(function*() {
let ret = null;
if (flag) {
ret = yield serviceAPI.get('guang/api/v1/favorite/setFavorite', params);
} else {
ret = yield serviceAPI.get('guang/api/v1/favorite/cancelFavorite', params);
}
const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
id: params.article_id
}, params));
return [ret, misc];
})();
},
/**
* 其它信息
*
* @param params
*/
misc(params) {
return serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
id: params.article_id
}, params));
}
};
... ...
... ... @@ -17,6 +17,7 @@ router.get(/\/([\d]+)(.*)/, detail.index); // 详情routers
router.get(/news_(\d+)\.json/, detail.news);
router.get(/like_(\d+)\.json/, detail.like);
router.get(/favorite_(\d+)\.json/, detail.favorite);
router.get(/misc_(\d+)\.json/, detail.misc);
const news = require(`${cRoot}/index`);
... ...
... ... @@ -43,12 +43,12 @@ const model = {
*
* @param params
*/
favorite(params) {
favorite(params, flag) {
let method = '';
if (params.operation === 'add') {
if (flag) {
method = 'app.favorite.add';
} else if (params.operation === 'remove') {
} else {
method = 'app.favorite.cancel';
}
... ...
... ... @@ -5,7 +5,7 @@
<h1>{{article.articleTitle}}</h1>
<div class="status-bar">
<span class="icon icon-timeshare"></span><span class="label">{{article.publishTime | formatUnixTime 'MM.DD HH:mm'}}</span>
<span class="icon icon-eye"></span><span class="label">{{article.pageViews}}</span>
<span class="icon icon-read"></span><span class="label">{{article.pageViews}}</span>
</div>
</div>
... ... @@ -57,10 +57,6 @@
}
.show-box {
&.first-box {
margin-top: 80px;
}
background: $bgcolor;
margin-top: 30px;
border-bottom: 1px solid #eee;
... ... @@ -205,6 +201,7 @@
init() {
const newsId = $('#app').data('newsId');
this.id = newsId;
let loadDeferred = null;
$.get(`/news/news_${newsId}.json`).then(result => {
... ... @@ -212,6 +209,7 @@
content = result[1],
brands = result[2],
other = result[3];
let goods, prodMap = {};
if (article && article.code === 200 && article.data) {
... ... @@ -225,7 +223,6 @@
return block && typeof block.goods === 'object';
});
const list = [];
goods = products[0] ? products[0].goods.data : null;
... ...
... ... @@ -3,7 +3,7 @@
<navbar>
<template slot="right">
<a class="right-button" href="javascript:void(0);" @click="like()">
<span class="icon icon-check"></span>
<span class="icon icon-like" :class=""></span>
{{likeCount}}
</a>
... ... @@ -42,7 +42,8 @@
return {
isApp: yoho.isApp,
likeCount: this.article.praise,
isFavorite: false
isFavorite: false,
isLiked: false
};
},
watch: {
... ... @@ -52,18 +53,33 @@
},
methods: {
like: function() {
$.get(`/news/like_${this.article.id}.json`, (result)=> {
$.get(`/news/like_${this.article.id}.json`, {
flag: !this.isLiked
}, (results)=> {
const result = results[0], misc = results[1];
if (result.code === 200) {
this.likeCount = result.data;
}
if (misc.code === 200) {
this.isLiked = misc.data.isPraise === 'Y';
}
});
},
favorite: function() {
$.get(`/news/favorite_${this.article.id}.json`, (result)=> {
$.get(`/news/favorite_${this.article.id}.json`, {
flag: !this.isFavorite
}, (results)=> {
const result = results[0], misc = results[1];
if (result.code === 200) {
//this.
// TODO:
}
if (misc.code === 200) {
this.isFavorite = misc.data.isFavor === 'Y';
}
});
},
share: function() {
... ... @@ -81,6 +97,14 @@
})
});
}
},
created() {
$.get(`/news/misc_${this.id}.json`).then(result => {
if (result.code === 200) {
this.isFavorite = result.data.isFavor === 'Y';
this.isLiked = result.data.isPraise === 'Y';
}
});
}
};
</script>
... ...