Skip to content
This repository was archived by the owner on Nov 15, 2018. It is now read-only.

Commit 7657fba

Browse files
committed
feat: (#608) 举报动态评论
1 parent f8ab7c6 commit 7657fba

File tree

4 files changed

+97
-44
lines changed

4 files changed

+97
-44
lines changed

src/api/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ export const limit = ~~(lstore.getData("BOOTSTRAPPERS") || {}).limit || 15;
2424
export function postFile(formData) {
2525
return api.post("/files", formData, { validateStatus: s => s === 201 });
2626
}
27+
28+
/**
29+
* 举报评论
30+
*
31+
* @author mutoe <[email protected]>
32+
* @export
33+
* @param {number} commentId
34+
* @param {string} reason 举报原因
35+
* @returns
36+
*/
37+
export function reportComment(commentId, reason) {
38+
const url = `/report/comments/${commentId}`;
39+
return api.post(url, { reason }, { validateStatus: s => s === 201 });
40+
}

src/components/FeedCard/FeedCard.vue

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -352,29 +352,47 @@ export default {
352352
this.$bus.$emit("actionSheet", actions, "取消");
353353
},
354354
commentAction({ isMine = false, placeholder, reply_user, comment }) {
355+
const actions = [];
355356
if (isMine) {
356357
const isOwner = this.feed.user.id === this.CURRENTUSER.id;
357-
const actionSheet = [
358-
{
359-
text: isOwner ? "评论置顶" : "申请评论置顶",
360-
method: () => {
361-
this.$bus.$emit("applyTop", {
362-
isOwner,
363-
type: "feedComment",
364-
api: api.applyTopFeedComment,
365-
payload: { feedId: this.feedID, commentId: comment.id }
366-
});
367-
}
368-
},
369-
{ text: "删除评论", method: () => this.deleteComment(comment.id) }
370-
];
371-
this.$bus.$emit("actionSheet", actionSheet);
358+
actions.push({
359+
text: isOwner ? "评论置顶" : "申请评论置顶",
360+
method: () => {
361+
this.$bus.$emit("applyTop", {
362+
isOwner,
363+
type: "feedComment",
364+
api: api.applyTopFeedComment,
365+
payload: { feedId: this.feedID, commentId: comment.id }
366+
});
367+
}
368+
});
369+
actions.push({
370+
text: "删除评论",
371+
method: () => this.deleteComment(comment.id)
372+
});
372373
} else {
373-
this.handleComment({
374-
placeholder,
375-
reply_user
374+
actions.push({
375+
text: "回复",
376+
method: () => {
377+
this.handleComment({
378+
placeholder,
379+
reply_user
380+
});
381+
}
382+
});
383+
actions.push({
384+
text: "举报",
385+
method: () => {
386+
this.$bus.$emit("report", {
387+
type: "comment",
388+
payload: comment.id,
389+
username: comment.user.name,
390+
reference: comment.body
391+
});
392+
}
376393
});
377394
}
395+
this.$bus.$emit("actionSheet", actions);
378396
},
379397
sendComment({ reply_user: replyUser, body }) {
380398
if (body && body.length === 0)

src/components/Report.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ import { noop } from "@/util";
3939
import { reportFeed } from "@/api/feeds";
4040
import { reportNews } from "@/api/news";
4141
import { reportPost, reportPostComment } from "@/api/group";
42+
import { reportComment } from "@/api";
4243
import TextareaInput from "@/components/common/TextareaInput";
4344
4445
const apiMap = {
4546
feed: reportFeed,
4647
news: reportNews,
4748
post: reportPost,
48-
postComment: reportPostComment
49+
postComment: reportPostComment,
50+
comment: reportComment
4951
};
5052
5153
export default {
@@ -76,6 +78,7 @@ export default {
7678
return "资讯";
7779
case "group":
7880
return "帖子";
81+
case "comment":
7982
case "postComment":
8083
return "评论";
8184
default:

src/page/feed/FeedDetail.vue

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@
111111
:pinned="true"
112112
:key="`pinned-comment-${comment.id}`"
113113
:comment="comment"
114-
@click="replyComment"/>
114+
@click="replyComment(comment)"/>
115115
<comment-item
116116
v-for="(comment) in comments"
117117
:key="comment.id"
118118
:comment="comment"
119-
@click="replyComment"/>
119+
@click="replyComment(comment)"/>
120120
<div class="m-box m-aln-center m-justify-center load-more-box">
121121
<div v-if="!pinnedCom.length && !comments.length" class="m-no-find"/>
122122
<span v-else-if="noMoreCom" class="load-more-ph">---没有更多---</span>
@@ -551,35 +551,53 @@ export default {
551551
];
552552
this.$bus.$emit("actionSheet", [...defaultActions, ...actions], "取消");
553553
},
554-
replyComment(uid, uname, commentId) {
554+
replyComment(comment) {
555+
const actions = [];
555556
// 是否是自己的评论
556-
if (uid === this.CURRENTUSER.id) {
557+
if (comment.user_id === this.CURRENTUSER.id) {
557558
// 是否是自己文章的评论
558-
const isOwner = uid === this.user.id;
559-
const actionSheet = [
560-
{
561-
text: isOwner ? "评论置顶" : "申请评论置顶",
562-
method: () => {
563-
this.$bus.$emit("applyTop", {
564-
isOwner,
565-
type: "feedComment",
566-
api: api.applyTopFeedComment,
567-
payload: { feedId: this.feedID, commentId },
568-
callback: this.fetchFeedComments
569-
});
570-
}
571-
},
572-
{ text: "删除评论", method: () => this.deleteComment(commentId) }
573-
];
574-
this.$bus.$emit("actionSheet", actionSheet, "取消");
559+
const isOwner = comment.user_id === this.user.id;
560+
actions.push({
561+
text: isOwner ? "评论置顶" : "申请评论置顶",
562+
method: () => {
563+
this.$bus.$emit("applyTop", {
564+
isOwner,
565+
type: "feedComment",
566+
api: api.applyTopFeedComment,
567+
payload: { feedId: this.feedID, commentId: comment.id },
568+
callback: this.fetchFeedComments
569+
});
570+
}
571+
});
572+
actions.push({
573+
text: "删除评论",
574+
method: () => this.deleteComment(comment.id)
575+
});
575576
} else {
576-
this.$bus.$emit("commentInput", {
577-
placeholder: `回复: ${uname}`,
578-
onOk: text => {
579-
this.sendComment({ reply_user: uid, body: text });
577+
actions.push({
578+
text: "回复",
579+
method: () => {
580+
this.$bus.$emit("commentInput", {
581+
placeholder: `回复: ${comment.user.name}`,
582+
onOk: text => {
583+
this.sendComment({ reply_user: comment.user_id, body: text });
584+
}
585+
});
586+
}
587+
});
588+
actions.push({
589+
text: "举报",
590+
method: () => {
591+
this.$bus.$emit("report", {
592+
type: "comment",
593+
payload: comment.id,
594+
username: comment.user.name,
595+
reference: comment.body
596+
});
580597
}
581598
});
582599
}
600+
this.$bus.$emit("actionSheet", actions);
583601
},
584602
sendComment({ reply_user: replyUser, body }) {
585603
const params = {};

0 commit comments

Comments
 (0)