From 6667c4273619a4c15c9c41fea5192c0588959be5 Mon Sep 17 00:00:00 2001
From: yiyu66 <1226572422@qq.com>
Date: Sun, 26 Sep 2021 13:03:44 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20(=E6=96=87=E7=AB=A0=E6=9F=A5?=
=?UTF-8?q?=E7=9C=8B)=20=E6=96=B0=E5=A2=9E=E6=B5=8F=E8=A7=88=E9=87=8F?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E7=82=B9=E8=B5=9E=EF=BC=8C=E6=94=B6?=
=?UTF-8?q?=E8=97=8F=E5=8A=9F=E8=83=BD=E5=A4=84=E7=90=86=EF=BC=8C=E7=94=A8?=
=?UTF-8?q?=E6=88=B7=E5=A4=B4=E5=83=8F=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
进入界面后请求浏览接口,增加头像显示
---
packages/blog-view/src/api/article.js | 7 +++--
.../src/components/page/CommentCard.vue | 18 ++++++-----
packages/blog-view/src/pages/Topic.vue | 31 +++++++++++++------
3 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/packages/blog-view/src/api/article.js b/packages/blog-view/src/api/article.js
index 6d4982d..138173d 100644
--- a/packages/blog-view/src/api/article.js
+++ b/packages/blog-view/src/api/article.js
@@ -22,7 +22,10 @@ export const postArticle = (param, token) => {
export const getArticleInfo = (params) => {
return axios.get(`/api/article/${params}`)
}
-
+// 浏览
+export const postView = (params) => {
+ return axios.post(`/api/view/`, params)
+}
// 获取点赞状态
export const getLike = params => {
return axios.get('/api/like', params)
@@ -35,7 +38,7 @@ export const postLike = (params) => {
// 删除点赞接口
export const deleteLike = (params) => {
- return axios.delete(`/api/like`, params)
+ return axios.delete('/api/like', { article: params })
}
// 评论接口
diff --git a/packages/blog-view/src/components/page/CommentCard.vue b/packages/blog-view/src/components/page/CommentCard.vue
index ca56e7d..3abb7f7 100644
--- a/packages/blog-view/src/components/page/CommentCard.vue
+++ b/packages/blog-view/src/components/page/CommentCard.vue
@@ -6,12 +6,12 @@
>
-
+ >
{
if (res.code === 200) {
console.log(res.msg)
console.log('点赞成功')
- this.comment.likecount += 1
- this.isliked = true
+ // this.comment.likecount += 1
+ // this.isliked = true
} else if (res.code === 201) {
console.log('已经点赞了')
this.isliked = true
}
})
} else {
+ this.isliked = false
+ this.comment.likecount -= 1
this.$service.article
.deleteLike({ comment_id: this.comment.id, action: 1 })
.then(res => {
if (res.code === 200) {
- this.isliked = false
- this.comment.likecount -= 1
+ // this.isliked = false
+ // this.comment.likecount -= 1
}
})
}
diff --git a/packages/blog-view/src/pages/Topic.vue b/packages/blog-view/src/pages/Topic.vue
index f9591ff..a5b1fdb 100644
--- a/packages/blog-view/src/pages/Topic.vue
+++ b/packages/blog-view/src/pages/Topic.vue
@@ -189,20 +189,20 @@ export default {
}
},
mounted () {
- let id = '614ec5c2214711d2b0c79c06'
- console.log('当前文章ID:' + id)
// 加在这里更快,但是没有loading
// this.pageload.topicload = true
// this.pageload.commentload = true
- this.getArticle(id)
+ this.getArticle()
+ this.$service.article.postView()
// this.getLikeState(id)
// this.getCollectState(id)
},
methods: {
// 请求文章内容
- getArticle (id) {
+ getArticle () {
+ console.log('当前文章ID:' + this.$route.query.topic_id)
this.$service.article
- .getArticleInfo(id)
+ .getArticleInfo(this.$route.query.topic_id)
.then(res => {
if (res.code === 200) {
this.topicData = res.data
@@ -210,6 +210,7 @@ export default {
if (this.topicData.article.img) {
this.showArticleimg = true
}
+ // 日期格式等下改
let time = this.topicData.article.datetime
this.topicData.article.datetime = time.substring(0, 10)
}
@@ -219,26 +220,34 @@ export default {
},
// 点赞
addlike (id) {
+ console.log(id)
let params = 'article=' + id
if (!this.isliked) {
+ this.isliked = true
+ this.topicData.article.data.like += 1
this.$service.article
.postLike(params)
.then(res => {
if (res.code === 200) {
console.log(res.msg)
- console.log('点赞成功')
- this.isliked = true
+ // this.isliked = true
+ // this.topicData.article.data.like += 1
} else if (res.code === 201) {
console.log('已经点赞了')
this.isliked = true
}
})
} else {
+ this.isliked = false
+ this.topicData.article.data.like -= 1
+ let params = 'article=' + id
this.$service.article
.deleteLike(params)
.then(res => {
+ console.log('取消点赞' + res)
if (res.code === 200) {
- this.isliked = false
+ // this.isliked = false
+ // this.topicData.article.data.like -= 1
}
})
}
@@ -312,21 +321,23 @@ export default {
// 收藏
addCollect (id) {
if (!this.iscollected) {
+ this.iscollected = true
this.$service.article
.postCollect(id)
.then(res => {
console.log(res)
if (res.code === 200) {
- this.iscollected = true
+ // this.iscollected = true
}
})
} else {
+ this.iscollected = false
this.$service.article
.deleteCollect(id)
.then(res => {
console.log(res)
if (res.code === 200) {
- this.iscollected = false
+ // this.iscollected = false
}
})
}
--
Gitee