diff --git a/src/App.vue b/src/App.vue index 4897802..86b2657 100644 --- a/src/App.vue +++ b/src/App.vue @@ -19,5 +19,16 @@ const app = useStore().theme; const lang = useStore().lang; diff --git a/src/components/CommentReply/src/CommentList/CommentList.vue b/src/components/CommentReply/src/CommentList/CommentList.vue index 52dd44c..8a670f5 100644 --- a/src/components/CommentReply/src/CommentList/CommentList.vue +++ b/src/components/CommentReply/src/CommentList/CommentList.vue @@ -91,9 +91,7 @@ {{ item.likes }} - - + + + @@ -231,27 +231,6 @@ function formatTimeAgo(dateString: string) { } -/** - * 获取回复列表 throttled - */ -const replyListThrottled = useThrottleFn(getReplyList, 1000); - -/** - * 获取回复列表 - * @param reply_id - * @param page - * @param size - */ -async function getReplyList(reply_id: number, page: number = 1, size: number = 5) { - const params: any = { - topic_id: topicId.value, - page: page, - size: size, - comment_id: reply_id, - }; - await comment.getReplyList(params); -} - const commentLikeThrottled = useThrottleFn(commentLike, 1000); /** diff --git a/src/components/CommentReply/src/CommentList/index.scss b/src/components/CommentReply/src/CommentList/index.scss index c89d23f..e6b2c15 100644 --- a/src/components/CommentReply/src/CommentList/index.scss +++ b/src/components/CommentReply/src/CommentList/index.scss @@ -40,6 +40,22 @@ .reply-content { margin-left: 20px; + .fade-enter { + opacity: 0; + } + + .fade-enter-active { + transition: opacity 0.3s; + } + + .fade-leave-to { + opacity: 0; + } + + .fade-leave-active { + transition: opacity 0.3s; + } + .reply-name { font-size: 14px; font-weight: 600; diff --git a/src/components/CommentReply/src/ReplyInput/ReplyInput.vue b/src/components/CommentReply/src/ReplyInput/ReplyInput.vue index 6385876..9812c4f 100644 --- a/src/components/CommentReply/src/ReplyInput/ReplyInput.vue +++ b/src/components/CommentReply/src/ReplyInput/ReplyInput.vue @@ -204,12 +204,12 @@ async function replySubmit(point: any) { nickname: user.user.nickname, avatar: user.user.avatar, is_liked: false, - reply_username: props.item.nickname, + reply_nickname: props.item.nickname, }; - if (!comment.replyList.comments) { - comment.replyList.comments = []; // 初始化 comments 数组 + if (!comment.replyVisibility[props.item.id].data.comments) { + comment.replyVisibility[props.item.id].data.comments = []; // 初始化 comments 数组 } - comment.replyList.comments.unshift(tmpData); + comment.replyVisibility[props.item.id].data.comments.unshift(tmpData); comment.commentMap[props.item.id].reply_count++; comment.closeReplyInput(); replyContent.value = ""; diff --git a/src/components/CommentReply/src/ReplyList/ReplyList.vue b/src/components/CommentReply/src/ReplyList/ReplyList.vue index 418de54..8210df8 100644 --- a/src/components/CommentReply/src/ReplyList/ReplyList.vue +++ b/src/components/CommentReply/src/ReplyList/ReplyList.vue @@ -1,8 +1,9 @@ diff --git a/src/components/CommentReply/src/ReplyList/index.scss b/src/components/CommentReply/src/ReplyList/index.scss index b47f50b..197977a 100644 --- a/src/components/CommentReply/src/ReplyList/index.scss +++ b/src/components/CommentReply/src/ReplyList/index.scss @@ -58,7 +58,7 @@ .reply-card-child { box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); - width: 530px; + width: 525px; .reply-action-item-child { margin-top: 10px; diff --git a/src/components/CommentReply/src/ReplyReplyInput/ReplyReply.vue b/src/components/CommentReply/src/ReplyReplyInput/ReplyReply.vue index d918ad3..451b821 100644 --- a/src/components/CommentReply/src/ReplyReplyInput/ReplyReply.vue +++ b/src/components/CommentReply/src/ReplyReplyInput/ReplyReply.vue @@ -207,13 +207,13 @@ async function replyReplySubmit(point: any) { nickname: user.user.nickname, avatar: user.user.avatar, is_liked: false, - reply_username: props.item.nickname, + reply_nickname: props.item.nickname, reply_to: result.data.reply_to, }; - if (!comment.replyList.comments) { - comment.replyList.comments = []; // 初始化 comments 数组 + if (!comment.replyVisibility[props.item.id].data.comments) { + comment.replyVisibility[props.item.id].data.comments = []; // 初始化 comments 数组 } - comment.replyList.comments.unshift(tmpData); + comment.replyVisibility[props.item.id].data.comments.unshift(tmpData); comment.commentMap[props.item.id].reply_count++; replyReplyContent.value = ""; await comment.clearFileList(); diff --git a/src/components/CommentReply/src/ReplyReplyInput/index.scss b/src/components/CommentReply/src/ReplyReplyInput/index.scss index 885db0d..444bf2d 100644 --- a/src/components/CommentReply/src/ReplyReplyInput/index.scss +++ b/src/components/CommentReply/src/ReplyReplyInput/index.scss @@ -25,7 +25,7 @@ //margin-left: 10px; .comment-text-reply-child { - width: 530px; + width: 525px; } .comment-actions-reply-child { diff --git a/src/store/modules/commentStore.ts b/src/store/modules/commentStore.ts index 5aef77b..9400574 100644 --- a/src/store/modules/commentStore.ts +++ b/src/store/modules/commentStore.ts @@ -14,10 +14,10 @@ export const useCommentStore = defineStore( () => { const commentList = ref({} as Comment); const commentLoading = ref(true); - const replyLoading = ref(true); + const replyLoading = reactive<{ [key: number]: boolean }>({}); const showReplyInput = ref(null); const showCommentReply = ref(null); - const replyList = ref({} as Comment); + const replyVisibility = ref<{ [key: number]: { visible: boolean; data: Comment } }>({}); const commentMap = reactive({}); const slideCaptchaData = reactive({ captKey: "", @@ -54,16 +54,14 @@ export const useCommentStore = defineStore( const result: any = await commentListApi(data); if (result.code === 200 && result.data) { commentList.value = result.data; - commentLoading.value = false; if (Array.isArray(commentList.value.comments)) { commentList.value.comments.map((item: any) => { commentMap[item.id] = item; + replyLoading[item.id] = false; }); } - } else { - commentLoading.value = false; } - + commentLoading.value = false; } /** @@ -78,34 +76,52 @@ export const useCommentStore = defineStore( const closeReplyInput = () => { showReplyInput.value = null; }; + /** - * 是否显示回复 + * 切换回复可见性 + * @param topic_id + * @param page + * @param size + * @param commentId */ - const handleShowCommentReply = (index: any) => { - showCommentReply.value = showCommentReply.value === index ? null : index; - }; + async function toggleReplyVisibility(topic_id: string, page: number, size: number, commentId: number) { + replyLoading[commentId] = true; + const params: any = { + topic_id: topic_id, + page: page, + size: size, + comment_id: commentId, + }; + if (!replyVisibility.value[commentId]) { + // 如果不存在这个评论的状态,初始化 + replyVisibility.value[commentId] = {visible: false, data: {} as Comment}; + await getReplyList(params); + } else { + // 切换可见性 + replyVisibility.value[commentId].visible = !replyVisibility.value[commentId].visible; + // 在展开时检查数据是否需要更新 + if (replyVisibility.value[commentId].visible) { + await getReplyList(params); // 重新获取最新的子评论 + } + } + replyLoading[commentId] = false; + + } /** * 获取回复列表 * @param data */ async function getReplyList(data: any) { - const params: any = { - topic_id: data.topic_id, - page: data.page, - size: data.size, - comment_id: data.comment_id, - }; - replyLoading.value = true; - replyList.value = {} as Comment; // 获取评论列表 - const result: any = await replyListApi(params); + const result: any = await replyListApi(data); if (result.code === 200 && result.data) { - replyList.value = result.data; - replyLoading.value = false; - } else { - replyLoading.value = false; + if (replyVisibility.value[data.comment_id].data !== result.data) { + replyVisibility.value[data.comment_id].data = result.data; + } + replyVisibility.value[data.comment_id].visible = true; } + replyLoading[data.comment_id] = false; } /** @@ -278,7 +294,7 @@ export const useCommentStore = defineStore( commentLoading, showReplyInput, showCommentReply, - replyList, + replyVisibility, replyLoading, slideCaptchaData, commentMap, @@ -293,7 +309,7 @@ export const useCommentStore = defineStore( getCommentList, handleShowReplyInput, closeReplyInput, - handleShowCommentReply, + toggleReplyVisibility, getReplyList, commentLike, cancelCommentLike, @@ -312,7 +328,7 @@ export const useCommentStore = defineStore( persist: { key: 'comment', storage: localStorage, - pick: ["emojiList", "commentList", "replyList", "commentMap"], + pick: ["emojiList", "commentList", "replyVisibility", "commentMap"], } } );