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

Commit

Permalink
feat: (#277) 圈子帖子可以删除和申请置顶了
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Jun 29, 2018
1 parent e8f638f commit e76dffb
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 46 deletions.
16 changes: 16 additions & 0 deletions src/api/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ export function getFeedCommentPinneds(after = 0) {
});
}

/**
* 发表动态评论
* @author mutoe <[email protected]>
* @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 <[email protected]>
Expand Down
22 changes: 17 additions & 5 deletions src/api/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @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 <[email protected]>
Expand Down
40 changes: 18 additions & 22 deletions src/components/FeedCard/FeedCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import FeedVideo from "./FeedVideo.vue";
import CommentItem from "./CommentItem.vue";
import { time2txt } from "@/filters.js";
import {
postComment,
applyTopFeed,
applyTopFeedComment,
deleteFeed,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(() => {
Expand Down
36 changes: 17 additions & 19 deletions src/components/FeedCard/GroupFeedCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import bus from "@/bus.js";
import FeedCard from "./FeedCard.vue";
import {
collectGroupPost,
postComment,
applyTopPostComment,
deletePostComment
} from "@/api/group.js";
Expand Down Expand Up @@ -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(() => {
Expand Down
74 changes: 74 additions & 0 deletions src/page/group/GroupPostDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { limit } from "@/api/api.js";
import {
likeGroupPost,
collectGroupPost,
applyTopPost,
applyTopPostComment,
deletePost,
deletePostComment
} from "@/api/group.js";
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit e76dffb

Please sign in to comment.