Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(comment): add comment likes #141

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/components/Articles/CommentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
>
回复评论
</span>
<span
v-if="$store.getters.loginStatus" @click="like(item);"
>
<LikeOutlined style="margin-right: 6px" :style="{color: doLikeHaveMe(item.id) ? '#000' : '#0f0'}"/>{{item.likes}}点赞
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我这里显示的时候貌似已点赞并没有成功变色?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

</span>
<span
v-if="replyTo===item.id"
@click="$store.commit('changeReplyTo',0)"
Expand All @@ -83,10 +88,12 @@
<script>
import axios from 'axios'
import { mapGetters } from 'vuex'
import { LikeOutlined } from '@ant-design/icons-vue'

export default {
name: 'CommentList',
props: ['parent', 'pageSize', 'id'],
components: { LikeOutlined },
data () {
return {
btnCommentSubmitting: false,
Expand Down Expand Up @@ -148,6 +155,33 @@ export default {
await this.$store.commit('updateComments', this.id)
this.commentsLoading = false
})
},
like (item) {
if (!this.$store.getters.loginStatus) {
this.$message.info('请先登录')
}
this.doLikeHaveMe(item.id).then(res => {
if (!res) {
item.likes += 1
axios.post(`/articles/comments/${item.id}/like`).then(() => {
this.$message.success('点赞成功')
})
} else {
item.likes -= 1
axios.delete(`/articles/comments/${item.id}/like`).then(() => {
this.$message.success('取消点赞成功')
})
}
})
},
async doLikeHaveMe (id) {
let likeUsers = []
await axios.get(`/articles/comments/${id}`).then(res => {
likeUsers = res.data.comment.like_users
})
return likeUsers.find(item => {
return item.id === this.user.id
}) !== undefined
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default new Vuex.Store({
},
content: 'content',
time: '2000-01-01 00:00:00',
parent: 123
parent: 123,
article: 0,
likes: 0
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions src/views/Words/Application.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ export default {
return
}
try {
const word = await axios.put(`/words/applications/${this.id}`, {
await axios.put(`/words/applications/${this.id}`, {
reason: this.reason,
result: result
}).then(res => {
this.application.word = res.data.word
})
await axios.put(`words/${this.application.word}`, { word: this.submit })
if (result && this.application.word !== 0) {
this.$message.success(`提交审核结果成功,词条(${this.application.content.word})${word}已修改`)
this.$message.success(`提交审核结果成功,词条(${this.application.content.word})已修改`)
} else if (result && this.application.word === 0) {
this.$message.success(`提交审核结果成功,词条(${this.application.content.word})${word}已创建`)
this.$message.success(`提交审核结果成功,词条(${this.application.content.word})已创建`)
} else if (result === false && this.application.word !== 0) {
this.$message.success('提交审核结果成功,词条修改不通过')
} else {
Expand Down