diff --git a/src/views/communtiy/pages.vue b/src/views/communtiy/pages.vue index 380c5bf3..4ae3a68e 100644 --- a/src/views/communtiy/pages.vue +++ b/src/views/communtiy/pages.vue @@ -1,253 +1,360 @@ + + fetchData() { + // 获取文章 + let datas = { id: this.ArticleId }; + ArticleById(datas) + .then((res) => { + if (res.code === 200) { + this.forums = res.data; + // 获取文章成功后再获取评论 + this.getuser(); + this.fetchComments(); + } + }) + .catch((error) => { + console.log(error); + }); + }, + // 删除评论 + DeleteComments(item) { + DeleteComments(item.commentId) + .then((res) => { + if (res.code == 200) { + this.$message.success("删除成功"); + // 获取文章成功后再获取评论 + this.fetchComments(); + } + }) + .catch((error) => { + this.$message.error(error || "删除失败"); + }); + }, + fetchComments() { + // 获取评论 + let data = { id: this.ArticleId }; + CommentsById(data) + .then((res) => { + this.msg = res.data.length || 0; + this.comments = res.data; + // console.log(this.comments); + console.log(this.comments); + }) + .catch((error) => { + console.log(error); + }); + }, + getuser() { + AllUser() + .then((response) => { + this.users = response.data; + }) + .catch((error) => { + console.error("Failed to load users:", error); + }); + }, + getUserName(userId) { + const user = this.users.find((u) => u.userId === userId); + return user ? user.userName : "未知用户"; + }, + }, +}; + \ No newline at end of file +