feat: get new comment in place

This commit is contained in:
KUN1007 2023-09-19 21:52:06 +08:00
parent 1e5cd52545
commit 5f77cc4ada
4 changed files with 29 additions and 7 deletions

View file

@ -293,6 +293,8 @@ export const useKUNGalgameTopicStore = defineStore({
this.commentDraft.c_uid = 0
this.commentDraft.to_uid = 0
this.commentDraft.content = ''
this.commentDraft.isShowCommentPanelRid = 0
},
},
})

View file

@ -4,6 +4,8 @@ import { onMounted, ref } from 'vue'
import { Icon } from '@iconify/vue'
import { debounce } from '@/utils/debounce'
import { TopicComment } from '@/api/index'
// store
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
// store
@ -12,6 +14,7 @@ import { storeToRefs } from 'pinia'
const { name, uid } = storeToRefs(useKUNGalgameUserStore())
// props
const { tid, rid, to_user } = defineProps<{
tid: number
rid: number
@ -21,6 +24,11 @@ const { tid, rid, to_user } = defineProps<{
}
}>()
const emits = defineEmits<{
getCommentEmits: [newComment: TopicComment]
}>()
// 使 store
const { commentDraft } = storeToRefs(useKUNGalgameTopicStore())
//
@ -52,11 +60,13 @@ const handlePublishComment = async () => {
commentDraft.value.to_uid = to_user.uid
commentDraft.value.content = commentValue.value
const r = (await useKUNGalgameTopicStore().postNewComment()).data
console.log(r)
const newComment = (await useKUNGalgameTopicStore().postNewComment()).data
//
useKUNGalgameTopicStore().resetCommentDraft()
//
emits('getCommentEmits', newComment)
}
//
@ -69,8 +79,9 @@ const handleCloseCommentPanel = () => {
<div class="panel" v-if="commentDraft.isShowCommentPanelRid === rid">
<div class="top">
<div class="title">
<span>{{ name }}</span
>评论 @<span>{{ to_user.name }}</span>
<span>{{ name }}</span>
评论 @
<span>{{ to_user.name }}</span>
</div>
<div class="confirm">
<button @click="handlePublishComment">发布评论</button>

View file

@ -27,9 +27,13 @@ const getComments = async (tid: number, rid: number) => {
return (await useKUNGalgameTopicStore().getComments(tid, rid)).data
}
// push
const getCommentEmits = (newComment: TopicComment) => {
commentsData.value?.push(newComment)
}
onMounted(async () => {
commentsData.value = await getComments(tid, rid)
console.log(commentsData.value)
})
</script>
@ -37,7 +41,12 @@ onMounted(async () => {
<!-- 评论容器 -->
<div class="comment-container">
<!-- 评论的弹出面板 -->
<CommentPanel :tid="tid" :rid="rid" :to_user="toUser" />
<CommentPanel
@getCommentEmits="getCommentEmits"
:tid="tid"
:rid="rid"
:to_user="toUser"
/>
<!-- 评论的展示区域 -->
<div class="container" v-if="commentsData?.length">

View file

@ -35,12 +35,12 @@ defineProps<{
const isCommentPanelOpen = ref(false)
//
const handleClickComment = (rid: number) => {
isCommentPanelOpen.value = !isCommentPanelOpen.value
if (isCommentPanelOpen.value) {
commentDraft.value.isShowCommentPanelRid = rid
} else {
commentDraft.value.isShowCommentPanelRid = 0
}
isCommentPanelOpen.value = !isCommentPanelOpen.value
}
</script>