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 7593aed commit c87cce6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
24 changes: 19 additions & 5 deletions src/api/news.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get, limit } from "./api.js";
const uri = "/user/news/contributes";
import api, { limit } from "./api.js";

/**
* 获取当前用户投稿列表
* @Author Wayne
Expand All @@ -9,7 +9,7 @@ const uri = "/user/news/contributes";
* @return [Promise]
*/
export function getMyNews({ type = 0, limit = 15, after = 0 }) {
return get(uri, {
return api.get("/user/news/contributes", {
type,
limit,
after
Expand All @@ -27,7 +27,7 @@ export function getMyNews({ type = 0, limit = 15, after = 0 }) {
export function searchNewsByKey(key = "", limit = 15, after = 0) {
return !key
? Promise.resolve([])
: get(`/news?key=${key}&limit=${limit}&after=${after}`).then(
: api.get(`/news?key=${key}&limit=${limit}&after=${after}`).then(
({ data = [] }) => {
return data;
},
Expand All @@ -39,8 +39,22 @@ export function searchNewsByKey(key = "", limit = 15, after = 0) {
}

export function getNewsCommentPinneds(after = 0) {
return get("/news/comments/pinneds", {
return api.get("/news/comments/pinneds", {
limit,
after
});
}

/**
* 删除评论
* @author mutoe <[email protected]>
* @export
* @param {Number} newsId 资讯 id
* @param {Number} commentId 评论 id
* @returns {Promise}
*/
export function deleteNewsComment(newsId, commentId) {
return api.delete(`/news/${newsId}/comments/${commentId}`, {
validateStatus: s => s === 204
});
}
57 changes: 29 additions & 28 deletions src/page/news/newsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@
</div>
</article-card>
</template>

<script>
import bus from "@/bus.js";
import md from "@/util/markdown.js";
import wechatShare from "@/util/wechatShare.js";
import ArticleCard from "@/page/article/ArticleCard.vue";
import CommentItem from "@/page/article/ArticleComment.vue";
import { deleteNewsComment } from "@/api/news";
export default {
name: "news-detail",
components: {
Expand Down Expand Up @@ -171,7 +174,7 @@ export default {
return this.news.comment_count || 0;
},
set(val) {
val > 0, (this.news.comment_count = val);
val > 0 && (this.news.comment_count = val);
}
},
time() {
Expand Down Expand Up @@ -330,33 +333,24 @@ export default {
];
bus.$emit("actionSheet", [...defaultActions, ...actions], "取消");
},
replyComment(uid, uname) {
uid === this.uid
? 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.uid) {
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 = {};
Expand All @@ -380,6 +374,13 @@ export default {
} else {
this.$Message.error("评论内容不能为空");
}
},
deleteComment(commentId) {
deleteNewsComment(this.newsID, commentId).then(() => {
this.fetchNewsComments();
this.commentCount -= 1;
this.this.$Message.success("删除评论成功");
});
}
},
activated() {
Expand Down

0 comments on commit c87cce6

Please sign in to comment.