Authored by shuaiguo

feat(article/detail): 推荐文章点赞 reviewed by 邱骏

... ... @@ -33,6 +33,7 @@
<waterFallList
:listData="recommendArticleList"
:item-w="344" :gutter-w="15"
@update-praise="onUpdatePraise"
>
</waterFallList>
</ClientOnly>
... ... @@ -114,6 +115,12 @@ export default {
} else {
this.$yoho.auth();
}
},
onUpdatePraise({articleId, status}) {
this.updatePraiseStatus({
articleId,
status
});
}
}
};
... ...
const FETCH_DETAIL_INFO = 'FETCH_DETAIL_INFO';
const UPDATE_ARTICLE_PRAISE_INFO = 'UPDATE_ARTICLE_PRAISE_INFO';
const FETCH_RECOMMEND_ARTICLES = 'FETCH_RECOMMEND_ARTICLES';
const FETCH_RECCOMMEND_ARTICLES = 'FETCH_RECCOMMEND_ARTICLES';
const UPDATE_RECCOMMEND_ARTICLES_PRAISE = 'UPDATE_RECCOMMEND_ARTICLES_PRAISE';
import { UPDATE_ARTICLE_PRAISE } from './list/types';
... ... @@ -34,6 +35,7 @@ export default function() {
if (res.code === 200) {
commit(`article/articleList/${UPDATE_ARTICLE_PRAISE}`, {articleId, status}, {root: true});
commit(UPDATE_ARTICLE_PRAISE_INFO);
commit(UPDATE_RECCOMMEND_ARTICLES_PRAISE, {articleId, status});
}
},
async fetchRecommendArticle({commit}, {articleId}) {
... ... @@ -42,7 +44,7 @@ export default function() {
});
if (res.code === 200) {
commit(FETCH_RECOMMEND_ARTICLES, res.data);
commit(FETCH_RECCOMMEND_ARTICLES, res.data);
}
}
},
... ... @@ -60,7 +62,25 @@ export default function() {
praiseCount: hasPraise === 'Y' ? praiseCount - 1 : praiseCount + 1
};
},
[FETCH_RECOMMEND_ARTICLES](state, list = []) {
[UPDATE_RECCOMMEND_ARTICLES_PRAISE](state, {articleId, status}) {
let article = state.recommendArticleList.find(item => +item.articleId === +articleId);
if (article && article.articleId === parseInt(articleId, 10)) {
if (article.praiseCount === 0 && status === 0) {
article.praiseCount += 1;
article.hasPraised = 'Y';
} else if (article.praiseCount > 0) {
if (status === 0) {
article.praiseCount += 1;
article.hasPraised = 'Y';
} else {
article.praiseCount -= 1;
article.hasPraised = 'N';
}
}
}
},
[FETCH_RECCOMMEND_ARTICLES](state, list = []) {
state.recommendArticleList = list.map((item)=> {
let imageHeight = item.imageHeight;
let imageWidth = item.imageWidth;
... ...