Authored by shuaiguo

feat(article/detail): 详情点赞同步列表 reviewed by 邱骏

@@ -2,6 +2,8 @@ const FETCH_DETAIL_INFO = 'FETCH_DETAIL_INFO'; @@ -2,6 +2,8 @@ const FETCH_DETAIL_INFO = 'FETCH_DETAIL_INFO';
2 const UPDATE_ARTICLE_PRAISE_INFO = 'UPDATE_ARTICLE_PRAISE_INFO'; 2 const UPDATE_ARTICLE_PRAISE_INFO = 'UPDATE_ARTICLE_PRAISE_INFO';
3 const FETCH_RECOMMEND_ARTICLES = 'FETCH_RECOMMEND_ARTICLES'; 3 const FETCH_RECOMMEND_ARTICLES = 'FETCH_RECOMMEND_ARTICLES';
4 4
  5 +import { UPDATE_ARTICLE_PRAISE } from './list/types';
  6 +
5 export default function() { 7 export default function() {
6 return { 8 return {
7 namespaced: true, 9 namespaced: true,
@@ -30,6 +32,7 @@ export default function() { @@ -30,6 +32,7 @@ export default function() {
30 }); 32 });
31 33
32 if (res.code === 200) { 34 if (res.code === 200) {
  35 + commit(`article/articleList/${UPDATE_ARTICLE_PRAISE}`, {articleId, status}, {root: true});
33 commit(UPDATE_ARTICLE_PRAISE_INFO); 36 commit(UPDATE_ARTICLE_PRAISE_INFO);
34 } 37 }
35 }, 38 },
@@ -33,9 +33,15 @@ export default { @@ -33,9 +33,15 @@ export default {
33 33
34 // 更新点赞 34 // 更新点赞
35 [Types.UPDATE_ARTICLE_PRAISE](state, {articleId, status, index}) { 35 [Types.UPDATE_ARTICLE_PRAISE](state, {articleId, status, index}) {
36 - let article = state.articleList[index]; 36 + let article = null;
37 37
38 - if (article.articleId === parseInt(articleId, 10)) { 38 + if (index) {
  39 + article = state.articleList[index];
  40 + } else {
  41 + article = state.articleList.find(item => +item.articleId === +articleId);
  42 + }
  43 +
  44 + if (article && article.articleId === parseInt(articleId, 10)) {
39 if (article.praiseCount === 0 && status === 0) { 45 if (article.praiseCount === 0 && status === 0) {
40 article.praiseCount += 1; 46 article.praiseCount += 1;
41 article.hasPraised = 'Y'; 47 article.hasPraised = 'Y';