Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
feat(news): 收藏资讯
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Sep 18, 2018
1 parent 35038ff commit 6ff3269
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/api/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,27 @@ export function getRewardInfo(newsId) {
const url = `/news/${newsId}/rewards/sum`;
return api.get(url, { validateStatus: s => s === 200 });
}

/**
* 收藏资讯
* @author mutoe <[email protected]>
* @export
* @param {number} newsId
* @returns
*/
export function collectionNews(newsId) {
const url = `/news/${newsId}/collections`;
return api.post(url, { validateStatus: s => s === 201 });
}

/**
* 取消收藏资讯
* @author mutoe <[email protected]>
* @export
* @param {number} newsId
* @returns
*/
export function uncollectNews(newsId) {
const url = `/news/${newsId}/collections`;
return api.delete(url, { validateStatus: s => s === 204 });
}
34 changes: 29 additions & 5 deletions src/page/news/NewsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ export default {
},
isWechat() {
return this.$store.state.BROWSER.isWechat;
},
has_collect: {
get() {
return this.news.has_collect;
},
set(val) {
this.news.has_collect = val;
}
}
},
activated() {
Expand Down Expand Up @@ -387,12 +395,28 @@ export default {
else this.$Message.success("请使用浏览器的分享功能😳");
},
moreAction() {
const defaultActions = [
{
const defaultActions = [];
if (this.has_collect) {
defaultActions.push({
text: "取消收藏",
method: () => {
api.uncollectNews(this.newsID).then(() => {
this.$Message.success("取消成功");
this.has_collect = false;
});
}
});
} else {
defaultActions.push({
text: "收藏",
method() {}
}
];
method: () => {
api.collectionNews(this.newsID).then(() => {
this.$Message.success("收藏成功");
this.has_collect = true;
});
}
});
}
const actions = this.isMine
? [
Expand Down

1 comment on commit 6ff3269

@mutoe
Copy link
Contributor Author

@mutoe mutoe commented on 6ff3269 Sep 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refer #511

Please sign in to comment.