diff --git a/src/api/feeds.js b/src/api/feeds.js index 61371fdb..d54feb54 100644 --- a/src/api/feeds.js +++ b/src/api/feeds.js @@ -85,6 +85,22 @@ export function getFeedCommentPinneds(after = 0) { }); } +/** + * 发表动态评论 + * @author mutoe + * @export + * @param {Number} feedId + * @param {Object} data + * @param {String} data.body 评论内容 + * @param {Number=} data.reply_user 回复的用户id + * @returns + */ +export function postComment(feedId, data) { + return api.post(`/feeds/${feedId}/comments`, data, { + validataStatus: s => s === 201 + }); +} + /** * 评论申请置顶 * @author mutoe diff --git a/src/api/group.js b/src/api/group.js index c1900d7b..1554d7c7 100644 --- a/src/api/group.js +++ b/src/api/group.js @@ -185,14 +185,26 @@ export function getPostAudits({ after = 0, group = 0 }) { }); } -export function getPostCommentAudits({ after = 0, post = 0 }) { - return get("/plus-group/pinned/comments", { - after, - limit, - post +/** + * 发表帖子评论 + * @author mutoe + * @export + * @param {Number} postId + * @param {Object} data + * @param {String} data.body 评论内容 + * @param {Number=} data.reply_user 回复的用户id + * @returns + */ +export function postComment(postId, data) { + return api.post(`/plus-group/group-posts/${postId}/comments`, data, { + validataStatus: s => s === 201 }); } +export function getPostCommentAudits({ after = 0, post = 0 }) { + return get("/plus-group/pinned/comments", { after, limit, post }); +} + /** * 申请评论置顶 * @author mutoe diff --git a/src/components/FeedCard/FeedCard.vue b/src/components/FeedCard/FeedCard.vue index 38170d4e..7cf52cca 100644 --- a/src/components/FeedCard/FeedCard.vue +++ b/src/components/FeedCard/FeedCard.vue @@ -84,6 +84,7 @@ import FeedVideo from "./FeedVideo.vue"; import CommentItem from "./CommentItem.vue"; import { time2txt } from "@/filters.js"; import { + postComment, applyTopFeed, applyTopFeedComment, deleteFeed, @@ -151,7 +152,7 @@ export default { return this.feed.feed_comment_count || 0; }, set(val) { - val > 0 && (this.feed.feed_comment_count = val); + this.feed.feed_comment_count = val; } }, viewCount() { @@ -368,27 +369,22 @@ export default { }); }, sendComment({ reply_user: replyUser, body }) { - const params = {}; - if (body && body.length > 0) { - params.body = body; - replyUser && (params["reply_user"] = replyUser); - this.$http - .post(`/feeds/${this.feedID}/comments`, params, { - validataStatus: s => s === 201 - }) - .then(({ data = { comment: {} } }) => { - this.feed.feed_comment_count += 1; - this.feed.comments.unshift(data.comment); - this.$Message.success("评论成功"); - bus.$emit("commentInput:close", true); - }) - .catch(() => { - this.$Message.error("评论失败"); - bus.$emit("commentInput:close", true); - }); - } else { - this.$Message.error("评论内容不能为空"); - } + if (body && body.length === 0) + return this.$Message.error("评论内容不能为空"); + + const params = { + body, + reply_user: replyUser + }; + postComment(this.feedID, params) + .then(({ data = { comment: {} } }) => { + this.commentCount += 1; + this.comments.unshift(data.comment); + this.$Message.success("评论成功"); + }) + .finally(() => { + bus.$emit("commentInput:close", true); + }); }, deleteComment(commentId) { deleteFeedComment(this.feedID, commentId).then(() => { diff --git a/src/components/FeedCard/GroupFeedCard.vue b/src/components/FeedCard/GroupFeedCard.vue index 4626ae08..cd71fd9e 100644 --- a/src/components/FeedCard/GroupFeedCard.vue +++ b/src/components/FeedCard/GroupFeedCard.vue @@ -3,6 +3,7 @@ import bus from "@/bus.js"; import FeedCard from "./FeedCard.vue"; import { collectGroupPost, + postComment, applyTopPostComment, deletePostComment } from "@/api/group.js"; @@ -34,25 +35,22 @@ export default { }); }, sendComment({ reply_user: replyUser, body }) { - const params = {}; - if (body && body.length > 0) { - params.body = body; - replyUser && (params["reply_user"] = replyUser); - this.$http - .post(`/plus-group/group-posts/${this.feed.id}/comments`, params, { - validataStatus: s => s === 201 - }) - .then(() => { - this.$Message.success("评论成功"); - bus.$emit("commentInput:close", true); - }) - .catch(() => { - this.$Message.error("评论失败"); - bus.$emit("commentInput:close", true); - }); - } else { - this.$Message.error("评论内容不能为空"); - } + if (body && body.length === 0) + return this.$Message.error("评论内容不能为空"); + + const params = { + body, + reply_user: replyUser + }; + postComment(this.feed.id, params) + .then(({ data = { comment: {} } }) => { + this.commentCount += 1; + this.comments.unshift(data.comment); + this.$Message.success("评论成功"); + }) + .finally(() => { + bus.$emit("commentInput:close", true); + }); }, handleCollection() { collectGroupPost(this.feed.id, this.has_collect).then(() => { diff --git a/src/page/group/GroupPostDetail.vue b/src/page/group/GroupPostDetail.vue index a92406bd..c7512ba0 100644 --- a/src/page/group/GroupPostDetail.vue +++ b/src/page/group/GroupPostDetail.vue @@ -8,7 +8,9 @@ import { limit } from "@/api/api.js"; import { likeGroupPost, collectGroupPost, + applyTopPost, applyTopPostComment, + deletePost, deletePostComment } from "@/api/group.js"; @@ -236,6 +238,78 @@ export default { this.fetching = false; }); }, + moreAction() { + const defaultActions = [ + { + text: this.has_collect ? "取消收藏" : "收藏", + method: () => { + // POST /feeds/:feed/collections + // DELETE /feeds/:feed/uncollect + let url; + let txt; + let method; + this.has_collect + ? ((txt = "取消收藏"), + (method = "delete"), + (url = `/feeds/${this.feedID}/uncollect`)) + : ((txt = "已加入我的收藏"), + (method = "post"), + (url = `/feeds/${this.feedID}/collections`)); + this.$http({ + url, + method, + validataStatus: s => s === 204 || s === 201 + }).then(() => { + this.$Message.success(txt); + this.has_collect = !this.has_collect; + }); + } + } + ]; + + const actions = this.isMine + ? [ + { + text: "申请帖子置顶", + method: () => { + bus.$emit("applyTop", { + type: "post", + api: applyTopPost, + payload: this.postID + }); + } + }, + { + text: "删除帖子", + method: () => { + setTimeout(() => { + const actionSheet = [ + { + text: "删除", + style: { color: "#f4504d" }, + method: () => { + deletePost(this.postID).then(() => { + this.$Message.success("删除帖子成功"); + this.goBack(); + }); + } + } + ]; + bus.$emit("actionSheet", actionSheet, "取消", "确认删除?"); + }, 200); + } + } + ] + : [ + { + text: "举报", + method: () => { + this.$Message.info("举报功能开发中,敬请期待"); + } + } + ]; + bus.$emit("actionSheet", [...defaultActions, ...actions], "取消"); + }, replyComment(uid, uname, commentId) { if (uid === this.CURRENTUSER.id) { const actionSheet = [