mutations.js 1.66 KB
import * as Types from './types';

export default {
  [Types.FETCH_ARTICLE_DETAIL_REQUEST](state) {
    state.fetchArticleList = true;
  },
  [Types.FETCH_ARTICLE_DETAIL_SUCCESS](state, {data, page}) {
    state.fetchArticleList = false;
    if (page === 1) {
      state.articleList = [];
    }
    state.articleList = state.articleList.concat(data);

    state.articleList.forEach((item, index) => {
      item.index = index;
    });
  },
  [Types.FETCH_ARTICLE_DETAIL_FAILD](state) {
    state.fetchArticleList = false;
  },
  [Types.FETCH_GUANG_SUCCESS](state, data) {
    state.articleDetail = data;
  },
  [Types.CHANGE_AUTHOR_FOLLOW](state, {authorUid, follow}) {
    state.articleList.forEach(article => {
      if (article.authorUid === authorUid) {
        article.hasAttention = follow ? 'Y' : 'N';
      }
    });
  },
  [Types.CHANGE_AUTHOR_TOPIC_FOLLOW](state, {authorUid, follow}) {
    state.articleListByTopic.forEach(article => {
      if (article.authorUid === authorUid) {
        article.hasAttention = follow ? 'Y' : 'N';
      }
    });
  },
  [Types.FETCH_ARTICLE_TOPIC_REQUEST](state, {page}) {
    state.fetchArticleListByTopic = true;
    if (page === 1) {
      state.articleLastedTimeByTopic = 0;
      state.articleListByTopic = [];
    }
  },
  [Types.FETCH_ARTICLE_TOPIC_SUCCESS](state, {data}) {
    state.fetchArticleListByTopic = false;
    state.articleListByTopic = state.articleListByTopic.concat(data.detailList);
    state.articleLastedTimeByTopic = data.lastedTime;

    state.articleListByTopic.forEach((item, index) => {
      item.index = index;
    });
  },
  [Types.FETCH_ARTICLE_TOPIC_FAILD](state) {
    state.fetchArticleListByTopic = false;
  },
};