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

Commit

Permalink
feat: (#274) 动态详情下可以删除自己发布的评论了
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Jun 28, 2018
1 parent c87cce6 commit a908abb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
22 changes: 18 additions & 4 deletions src/api/feeds.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import api, { get, limit } from "./api.js";
import api, { limit } from "./api.js";
import router from "@/routers";
/**
* 获取 首页动态列表
Expand Down Expand Up @@ -39,23 +39,37 @@ export function getFeedsByType(type, limit = 15, after) {
* @type {Number}
*/
export function getCollectedFeed({ limit = 15, offset = 0 }) {
return get("/feeds/collections", {
return api.get("/feeds/collections", {
limit,
offset
});
}

// 获取单条动态的评论
export function getFeedComments({ feedId, after = 0 }) {
return get(`/feeds/${feedId}/comments`, {
return api.get(`/feeds/${feedId}/comments`, {
limit,
after
});
}

export function getFeedCommentPinneds(after = 0) {
return get("/user/feed-comment-pinneds", {
return api.get("/user/feed-comment-pinneds", {
limit,
after
});
}

/**
* 删除动态评论
* @author mutoe <[email protected]>
* @export
* @param {Number} feedId
* @param {Number} commentId
* @returns {Promise}
*/
export function deleteFeedComment(feedId, commentId) {
return api.delete(`/feeds/${feedId}/comments/${commentId}`, {
validateStatus: s => s === 204
});
}
55 changes: 28 additions & 27 deletions src/page/feed/feedDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ import ArticleCard from "@/page/article/ArticleCard.vue";
import CommentItem from "@/page/article/ArticleComment.vue";
import wechatShare from "@/util/wechatShare.js";
import { limit } from "@/api/api.js";
import { getFeedComments } from "@/api/feeds.js";
import { getFeedComments, deleteFeedComment } from "@/api/feeds.js";
import { followUserByStatus, getUserInfoById } from "@/api/user.js";
export default {
Expand Down Expand Up @@ -513,34 +513,27 @@ export default {
];
bus.$emit("actionSheet", [...defaultActions, ...actions], "取消");
},
replyComment(uid, uname) {
uid === this.CURRENTUSER.id
? bus.$emit(
"actionSheet",
[
{
text: "申请评论置顶",
method: () => {
this.$Message.info("置顶功能开发中,敬请期待");
}
},
{
text: "删除评论",
method: () => {
this.$Message.info("评论删除功能开发中,敬请期待");
}
}
],
"取消"
)
: bus.$emit("commentInput", {
placeholder: `回复: ${uname}`,
onOk: text => {
this.sendComment({ reply_user: uid, body: text });
replyComment(uid, uname, commentId) {
if (uid === this.CURRENTUSER.id) {
const actionSheet = [
{
text: "申请评论置顶",
method: () => {
this.$Message.info("置顶功能开发中,敬请期待");
}
});
},
{ text: "删除评论", method: () => this.deleteComment(commentId) }
];
bus.$emit("actionSheet", actionSheet, "取消");
} else {
bus.$emit("commentInput", {
placeholder: `回复: ${uname}`,
onOk: text => {
this.sendComment({ reply_user: uid, body: text });
}
});
}
},
sendComment({ reply_user: replyUser, body }) {
const params = {};
if (body && body.length > 0) {
Expand All @@ -564,6 +557,13 @@ export default {
this.$Message.error("评论内容不能为空");
}
},
deleteComment(commentId) {
deleteFeedComment(this.feedID, commentId).then(() => {
this.fetchFeedComments();
this.commentCount -= 1;
this.$Message.success("删除评论成功");
});
},
followUserByStatus(status) {
if (!status || this.fetchFollow) return;
this.fetchFollow = true;
Expand Down Expand Up @@ -634,6 +634,7 @@ export default {
}
};
</script>

<style lang="less">
.feed-detail-video {
height: 100vw;
Expand Down

0 comments on commit a908abb

Please sign in to comment.