actions.js 1.54 KB
import * as Types from './types';

export default {
  async fetchCommentList({commit}, {destId, columnType = 1001, limit = 10, page = 1}) {
    commit(Types.FETCH_COMMENT_REQUEST);
    const result = await this.$api.get('/api/grass/queryArticleComments', {
      destId,
      limit,
      page,
      columnType
    });

    if (result && result.code === 200) {
      if (!result.data.commentInfos) {
        result.data.commentInfos = [];
      }
      commit(Types.FETCH_COMMENT_SUCCESS);
    } else {
      commit(Types.FETCH_COMMENT_FAILD);
    }
    return result;
  },
  async fetchCommentFeebbackList({commit}, {commentId, limit = 10, page = 1}) {
    commit(Types.FETCH_COMMENT_FEEDBACK_REQUEST);
    const result = await this.$api.get('/api/grass/queryArticleCommentReply', {
      commentId,
      limit,
      page,
    });

    if (result && result.code === 200) {
      if (!result.data.childrenComments) {
        result.data.childrenComments = [];
      }
      commit(Types.FETCH_COMMENT_FEEDBACK_SUCCESS);
    } else {
      commit(Types.FETCH_COMMENT_FEEDBACK_FAILD);
    }
    return result;
  },
  async postComment({commit}, {content, destId, commentId, addType, columnType = 1001}) {
    commit(Types.POST_COMMENT_REQUEST);
    const result = await this.$api.get('/api/grass/addArticleComment', {
      destId,
      content,
      addType,
      commentId,
      columnType
    });

    if (result && result.code === 200) {
      commit(Types.POST_COMMENT_SUCCESS);
    } else {
      commit(Types.POST_COMMENT_FAILD);
    }
    return result;
  }
};