Skip to content

Commit

Permalink
feat:新增收藏帖子功能
Browse files Browse the repository at this point in the history
  • Loading branch information
anguoo committed Feb 21, 2024
1 parent c8ff496 commit f0d72da
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/views/posts/post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div
class="like"
v-if="!postDetail.liked"
@click="likePost()"
@click="likePost"
>
<i class="iconfont icon-a-dianzan2"></i>
<div>点赞 {{ postDetail.likeCount }}</div>
Expand All @@ -46,10 +46,18 @@
<i class="iconfont icon-a-xiaoxi1"></i>
<div>评论 {{ postDetail.commentCount }}</div>
</div>
<div class="collect">
<i class="iconfont icon-xihuan02"></i>
<div
class="collect"
v-if="!postDetail.collected"
@click="collectPost"
>
<i class="iconfont icon-shoucang01"></i>
<div>收藏</div>
</div>
<div class="collected" v-if="postDetail.collected">
<i class="iconfont icon-shoucang01"></i>
<div>已收藏</div>
</div>
<div class="share">
<i class="iconfont icon-fenxiang"></i>
<div>分享</div>
Expand Down Expand Up @@ -124,6 +132,10 @@ onMounted(() => {
getPost()
})
const collectPost = () => {
createRelation(3)
}
const likePost = () => {
if (myUserId.value === '') {
errorMsg('请先登录')
Expand All @@ -134,16 +146,25 @@ const likePost = () => {
return
}
else {
post('/relation/createRelation', {
toId: postId,
toType: 4,
relationType: 1
})
.then(() => {
createRelation(1)
}
}
const createRelation = (type: number) => {
post('/relation/createRelation', {
toId: postId,
toType: 4,
relationType: type
})
.then(() => {
if (type === 1) {
postDetail.value.liked = true
postDetail.value.likeCount++
})
}
}
else if (type === 3) {
postDetail.value.collected = true
}
})
}
const deletePost = () => {
Expand Down Expand Up @@ -431,6 +452,7 @@ const getPost = () => {
.liked,
.remark,
.collect,
.collected,
.share,
.more{
display: flex;
Expand All @@ -448,8 +470,10 @@ const getPost = () => {
color: #6d99ec;
font-weight: 600;
}
.liked:hover {
color: #494848;
.collected {
color: #ff9d5b;
font-weight: 600;
}
}
}
Expand Down

0 comments on commit f0d72da

Please sign in to comment.