Skip to content

Commit

Permalink
feat:新增帖子详情页面点赞的功能 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
anguoo authored Feb 21, 2024
1 parent c716780 commit ea74dde
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/views/posts/post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@
</section>
<footer class="detail-footer">
<div class="situation">
<div class="like">
<div
class="like"
v-if="!postDetail.liked"
@click="likePost()"
>
<i class="iconfont icon-a-dianzan2"></i>
<div>点赞 {{ postDetail.likeCount }}</div>
</div>
<div class="liked" v-if="postDetail.liked">
<i class="iconfont icon-a-dianzan2"></i>
<div>已点赞 {{ postDetail.likeCount }}</div>
</div>
<div class="remark">
<i class="iconfont icon-a-xiaoxi1"></i>
<div>评论 {{ postDetail.commentCount }}</div>
Expand Down Expand Up @@ -85,7 +93,7 @@ import { turnTime } from '@/utils/public'
import { ref, onMounted, computed } from 'vue'
import type { responseGetPost } from './utils'
import router from '@/router'
import { successMsg } from '@/utils/message'
import { errorMsg, successMsg } from '@/utils/message'
const store = useStore()
const myUserId = ref('')
Expand Down Expand Up @@ -116,6 +124,28 @@ onMounted(() => {
getPost()
})
const likePost = () => {
if (myUserId.value === '') {
errorMsg('请先登录')
return
}
else if (myUserId.value === postDetail.value.author.userId) {
errorMsg('不能给自己点赞')
return
}
else {
post('/relation/createRelation', {
toId: postId,
toType: 4,
relationType: 1
})
.then(() => {
postDetail.value.liked = true
postDetail.value.likeCount++
})
}
}
const deletePost = () => {
isShowDeletePost.value = true
isShowSetting.value = false
Expand Down Expand Up @@ -171,8 +201,6 @@ const getMyUserId = () => {
else {
myUserId.value = ''
}
console.log(myUserId.value);
}
const getPost = () => {
Expand Down Expand Up @@ -400,6 +428,7 @@ const getPost = () => {
display: flex;
.like,
.liked,
.remark,
.collect,
.share,
Expand All @@ -414,6 +443,14 @@ const getPost = () => {
margin-right: 5px;
}
}
.liked {
color: #6d99ec;
font-weight: 600;
}
.liked:hover {
color: #494848;
}
}
}
}
Expand Down

0 comments on commit ea74dde

Please sign in to comment.