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

export default {
  async fetchCommentList({commit}, {destId, columnType = 1001, limit = 20, page = 1, rootCommentId}) {
    commit(Types.FETCH_COMMENT_REQUEST);

    let params = {
      destId,
      limit,
      page,
      columnType
    };

    if (rootCommentId > 0) {
      params.rootCommentId = rootCommentId;
    }

    const result = await this.$api.get('/api/grass/queryArticleComments', params);

    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 fetchReplayList(actions, {commentId}) {
    const result = await this.$api.get('/api/grass/queryArticleCommentReply', {
      commentId,
      limit: 200,
      page: 1,
    });

    if (result && result.code === 200) {
      if (!result.data.childrenComments) {
        result.data.childrenComments = [];
      }
    }
    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(actions, {content, destId, commentId, addType, columnType = 1001}) {
    const result = await this.$api.post('/api/grass/addArticleComment', {
      destId,
      content,
      addType,
      commentId,
      columnType
    });

    return result;
  },

  async setCommentStatus(ctx, {type, commentId}) {
    if (type === 1) {
      return this.$api.post('/api/grass/deleteComment', {
        commentId
      });
    } else if (type === 2) {
      return this.$api.post('/api/grass/reportComment', {
        commentId
      });
    }
  }
};