Skip to content

Commit a97e37f

Browse files
committed
文章操作 - 发表评论
1 parent db78b7f commit a97e37f

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

project/imooc-blog/api/user.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* @Date: 2021-12-27 22:45:05
3-
* @LastEditTime: 2021-12-28 20:03:55
3+
* @LastEditTime: 2021-12-29 00:05:23
44
* @FilePath: \imooc-blog\api\user.js
55
*/
66
import request from "@/utils/request";
@@ -25,3 +25,14 @@ export function userFollow(data) {
2525
data,
2626
});
2727
}
28+
29+
/**
30+
* 发表评论
31+
*/
32+
export function userArticleComment(data) {
33+
return request({
34+
url: "/user/article/comment",
35+
method: "POST",
36+
data,
37+
});
38+
}

project/imooc-blog/components/article-comment-commit/article-comment-commit.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
* @Date: 2021-12-28 21:08:55
3-
* @LastEditTime: 2021-12-28 21:35:02
3+
* @LastEditTime: 2021-12-29 00:06:10
44
* @FilePath: \imooc-blog\components\article-comment-commit\article-comment-commit.vue
55
-->
66
<template>
@@ -25,8 +25,15 @@
2525
</template>
2626

2727
<script>
28+
import { userArticleComment } from "@/api/user";
2829
export default {
2930
name: "article-comment-commit",
31+
props: {
32+
articleId: {
33+
type: String,
34+
required: true,
35+
},
36+
},
3037
data() {
3138
return {
3239
value: "",
@@ -43,7 +50,24 @@ export default {
4350
/**
4451
* 发送按钮点击事件
4552
*/
46-
onBtnClick() {},
53+
async onBtnClick() {
54+
// 展示加载框
55+
uni.showLoading({
56+
title: "加载中",
57+
});
58+
// 异步处理即可
59+
await userArticleComment({
60+
articleId: this.articleId,
61+
content: this.value,
62+
});
63+
uni.showToast({
64+
title: "发表成功",
65+
icon: "success",
66+
mask: true,
67+
});
68+
// 发表成功之后的回调
69+
this.$emit("success");
70+
},
4771
},
4872
};
4973
</script>

project/imooc-blog/subpkg/pages/blog-detail/blog-detail.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
* @Date: 2021-12-25 14:04:11
3-
* @LastEditTime: 2021-12-28 21:32:45
3+
* @LastEditTime: 2021-12-29 00:07:22
44
* @FilePath: \imooc-blog\subpkg\pages\blog-detail\blog-detail.vue
55
-->
66
<template>
@@ -58,7 +58,11 @@
5858
<article-operate @commitClick="onCommit" />
5959
<!-- 输入评论的popup -->
6060
<uni-popup ref="popup" type="bottom" @change="onCommitPopupChange">
61-
<article-comment-commit v-if="isShowCommit" />
61+
<article-comment-commit
62+
v-if="isShowCommit"
63+
:articleId="articleId"
64+
@success="onSendSuccess"
65+
/>
6266
</uni-popup>
6367
</view>
6468
</page-meta>
@@ -197,6 +201,14 @@ export default {
197201
}, 200);
198202
}
199203
},
204+
/**
205+
* 发表评论成功
206+
*/
207+
onSendSuccess() {
208+
// 关闭弹出层
209+
this.$refs.popup.close();
210+
this.isShowCommit = false;
211+
},
200212
},
201213
};
202214
</script>

0 commit comments

Comments
 (0)