This commit is contained in:
张成
2025-10-01 14:22:08 +08:00
parent ccdc220638
commit 22d8a34c7b
4 changed files with 88 additions and 59 deletions

View File

@@ -19,6 +19,8 @@ interface CommentReplyItem {
activity_image: string;
activity_id: number;
activity_title: string;
parent_id: number | null; // 父评论ID用于回复
game_id: number; // 球局ID
}
const CommentReply = () => {
@@ -56,9 +58,11 @@ const CommentReply = () => {
time: item.create_time,
content: item.content || "",
original_comment: item.parent_comment?.content || "",
activity_image: item.game?.image_list?.[0] || "",
activity_image: item.game?.image || "",
activity_id: item.game_id,
activity_title: item.game?.title || "",
parent_id: item.parent_id,
game_id: item.game_id,
}));
setCommentList(mappedList);
@@ -136,26 +140,38 @@ const CommentReply = () => {
}
try {
// TODO: 调用回复接口
// await commentService.replyComment(replyTarget.id, replyContent);
// 调用回复接口
// 如果是回复评论parent_id 使用评论的 parent_id 或 id
// 如果是顶级评论parent_id 为 null则使用评论的 id 作为 parent_id
const parentId = replyTarget.parent_id || replyTarget.id;
const res = await commentService.replyComment(
parentId,
replyTarget.user_id,
replyContent.trim()
);
if (res.code === 0) {
Taro.showToast({
title: "回复成功",
icon: "success",
duration: 2000,
});
// 关闭输入框
setShowReplyInput(false);
setReplyTarget(null);
setReplyContent("");
setInputFocus(false);
// 刷新列表
getCommentReplyList();
} else {
throw new Error(res.message || "回复失败");
}
} catch (e: any) {
Taro.showToast({
title: "回复成功",
icon: "success",
duration: 2000,
});
// 关闭输入框
setShowReplyInput(false);
setReplyTarget(null);
setReplyContent("");
setInputFocus(false);
// 刷新列表
getCommentReplyList();
} catch (e) {
Taro.showToast({
title: "回复失败",
title: e.message || "回复失败",
icon: "none",
duration: 2000,
});
@@ -173,9 +189,9 @@ const CommentReply = () => {
// 输入框失去焦点
const handleInputBlur = () => {
// 延迟执行,避免点击发送按钮时输入框先失焦导致发送失败
// setTimeout(() => {
// handleCancelReply();
// }, 200);
setTimeout(() => {
handleCancelReply();
}, 200);
};
// 处理返回
@@ -202,9 +218,11 @@ const CommentReply = () => {
time: item.create_time,
content: item.content || "",
original_comment: item.parent_comment?.content || "",
activity_image: item.game?.image_list?.[0] || "",
activity_image: item.game?.image || "",
activity_id: item.game_id,
activity_title: item.game?.title || "",
parent_id: item.parent_id,
game_id: item.game_id,
}));
setCommentList(mappedList);
@@ -277,6 +295,12 @@ const CommentReply = () => {
className="activity-image"
src={item.activity_image}
mode="aspectFill"
onClick={(e) => {
e.stopPropagation();
Taro.navigateTo({
url: `/game_pages/detail/index?id=${item.game_id}`,
});
}}
/>
</View>
);