From 718a0cbbdb0ed7f8924f98abf1f8cec4a05b9d1e Mon Sep 17 00:00:00 2001 From: ruibaby Date: Fri, 3 May 2019 12:25:21 +0800 Subject: [PATCH] Refactor comment list. --- src/api/comment.js | 8 ++++ src/components/Tools/UserMenu.vue | 2 +- src/views/comment/CommentList.vue | 75 ++++++++++++++++++++++++++++--- 3 files changed, 77 insertions(+), 8 deletions(-) diff --git a/src/api/comment.js b/src/api/comment.js index 97a300d8..568c3017 100644 --- a/src/api/comment.js +++ b/src/api/comment.js @@ -33,6 +33,14 @@ commentApi.delete = commentId => { }) } +commentApi.create = comment => { + return service({ + url: baseUrl, + data: comment, + method: 'post' + }) +} + commentApi.commentStatus = { PUBLISHED: { color: 'green', diff --git a/src/components/Tools/UserMenu.vue b/src/components/Tools/UserMenu.vue index 0fb351d1..48271e6f 100644 --- a/src/components/Tools/UserMenu.vue +++ b/src/components/Tools/UserMenu.vue @@ -36,7 +36,7 @@ - + 通过 - - 通过该评论 - 回复并通过 + + + 通过 + + + 通过并回复 + 回复 + + + + + + + + + @@ -206,6 +240,7 @@ export default { data() { return { columns, + replyCommentVisible: false, pagination: { current: 1, pageSize: 10, @@ -221,6 +256,8 @@ export default { selectedRowKeys: [], selectedRows: [], comments: [], + selectComment: {}, + replyComment: {}, commentsLoading: false, commentStatus: commentApi.commentStatus } @@ -267,6 +304,25 @@ export default { this.loadComments() }) }, + handleReplyAndPassClick(comment) { + this.handleReplyClick(comment) + this.handleEditStatusClick(comment.id, 'PUBLISHED') + }, + handleReplyClick(comment) { + this.selectComment = comment + this.replyCommentVisible = true + this.replyComment.parentId = comment.id + this.replyComment.postId = comment.post.id + }, + handleCreateClick() { + commentApi.create(this.replyComment).then(response => { + this.$message.success('回复成功!') + this.replyComment = {} + this.selectComment = {} + this.replyCommentVisible = false + this.loadComments() + }) + }, handlePaginationChange(page, pageSize) { this.$log.debug(`Current: ${page}, PageSize: ${pageSize}`) this.pagination.current = page @@ -277,6 +333,11 @@ export default { this.queryParam.keyword = null this.queryParam.status = null this.loadComments() + }, + onReplyClose() { + this.replyComment = {} + this.selectComment = {} + this.replyCommentVisible = false } } }