diff --git a/src/store/modules/topic.ts b/src/store/modules/topic.ts index c14d4e05..5486bd20 100644 --- a/src/store/modules/topic.ts +++ b/src/store/modules/topic.ts @@ -102,16 +102,6 @@ export const useKUNGalgameTopicStore = defineStore({ isReplyRewriting: false, }, - - commentDraft: { - tid: 0, - rid: 0, - c_uid: 0, - to_uid: 0, - content: '', - - isShowCommentPanelRid: 0, - }, }), actions: { // 左侧相同标签下的其它话题 @@ -265,12 +255,17 @@ export const useKUNGalgameTopicStore = defineStore({ }, // 创建一个评论 - async postNewComment(): Promise { + async postNewComment( + tid: number, + rid: number, + toUid: number, + content: string + ): Promise { const requestData: TopicCreateCommentRequestData = { - tid: this.commentDraft.tid, - rid: this.commentDraft.rid, - to_uid: this.commentDraft.to_uid, - content: this.commentDraft.content, + tid: tid, + rid: rid, + to_uid: toUid, + content: content, } return await postCommentByPidAndRidApi(requestData) }, @@ -291,16 +286,6 @@ export const useKUNGalgameTopicStore = defineStore({ this.replyRequest.page = 1 this.isLoading = true }, - // 设置评论草稿为原始值,用于评论发布按钮 - resetCommentDraft() { - this.commentDraft.tid = 0 - this.commentDraft.rid = 0 - this.commentDraft.c_uid = 0 - this.commentDraft.to_uid = 0 - this.commentDraft.content = '' - - this.commentDraft.isShowCommentPanelRid = 0 - }, // 重置重新编辑回复数据,用于重新编辑回复 resetRewriteTopicData() { this.replyDraft.textCount = 0 diff --git a/src/store/temp/comment.ts b/src/store/temp/comment.ts new file mode 100644 index 00000000..7e0726d7 --- /dev/null +++ b/src/store/temp/comment.ts @@ -0,0 +1,20 @@ +// 评论的临时数据,用于组件间传输 +import { defineStore } from 'pinia' + +export const useTempCommentStore = defineStore({ + id: 'tempComment', + // 不持久 + persist: false, + state: () => ({ + tid: 0, + rid: 0, + toUid: 0, + toUsername: '', + content: '', + + // 要展示哪个回复底下的评论面板 + isShowCommentPanelRid: 0, + }), + getters: {}, + actions: {}, +}) diff --git a/src/store/types/topic.d.ts b/src/store/types/topic.d.ts index abbad32c..b1d3b61a 100644 --- a/src/store/types/topic.d.ts +++ b/src/store/types/topic.d.ts @@ -36,19 +36,6 @@ interface ReplyRequest { sortOrder: 'asc' | 'desc' } -// 评论的缓存 -interface CommentDraft { - // 评论的内容 - tid: number - rid: number - c_uid: number - to_uid: number - content: string - - // 显示哪个评论的评论面板 - isShowCommentPanelRid: number -} - // 更新评论的缓存 interface ReplyRewrite { tid: number @@ -83,7 +70,4 @@ export interface TopicStore { replyRequest: ReplyRequest // 更新评论的缓存 replyRewrite: ReplyRewrite - - // 评论的缓存 - commentDraft: CommentDraft } diff --git a/src/utils/toggle.ts b/src/utils/toggle.ts new file mode 100644 index 00000000..9a5d4d6d --- /dev/null +++ b/src/utils/toggle.ts @@ -0,0 +1,18 @@ +import { ref } from 'vue' + +const toggleStatus = (initState: boolean, delay: number) => { + const on = ref(initState ?? false) + + const toggle = (value: boolean) => { + setTimeout(() => { + on.value = value ?? !on.value + }, delay) + } + + return { + on, + toggle, + } +} + +export default toggleStatus diff --git a/src/views/topic/KUNGalgameTopicPage.vue b/src/views/topic/KUNGalgameTopicPage.vue index 452370f9..549d4b9c 100644 --- a/src/views/topic/KUNGalgameTopicPage.vue +++ b/src/views/topic/KUNGalgameTopicPage.vue @@ -32,6 +32,8 @@ import { useKUNGalgameTopicStore } from '@/store/modules/topic' import { useTempReplyStore } from '@/store/temp/reply' // 回复重新编辑响应的临时数据 import { useTempReplyRewriteStore } from '@/store/temp/replyRewrite' +// 使用不持久的评论 store +import { useTempCommentStore } from '@/store/temp/comment' import { storeToRefs } from 'pinia' // 当前的路由 @@ -42,7 +44,6 @@ const { isShowAdvance, isEdit, replyRequest, - commentDraft, isScrollToTop, isLoading, scrollToReplyId, @@ -51,6 +52,7 @@ const { tempReply } = storeToRefs(useTempReplyStore()) const { rid, replyContent, tags, edited } = storeToRefs( useTempReplyRewriteStore() ) +const { isShowCommentPanelRid } = storeToRefs(useTempCommentStore()) const tid = computed(() => { return Number(route.params.tid) @@ -227,7 +229,7 @@ const topicPageWidth = computed(() => { // 在页面跳转和刷新时关闭回复面板和评论面板 const resetPanelStatus = () => { - commentDraft.value.isShowCommentPanelRid = 0 + isShowCommentPanelRid.value = 0 isShowAdvance.value = false isEdit.value = false // 重置重新编辑回复的数据 diff --git a/src/views/topic/components/comment/CommentPanel.vue b/src/views/topic/components/comment/CommentPanel.vue index 3581fc4d..4182a8be 100644 --- a/src/views/topic/components/comment/CommentPanel.vue +++ b/src/views/topic/components/comment/CommentPanel.vue @@ -1,5 +1,5 @@