添加 消息 页面更新
This commit is contained in:
188
src/other_pages/comment_reply/index.tsx
Normal file
188
src/other_pages/comment_reply/index.tsx
Normal file
@@ -0,0 +1,188 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { View, Text, ScrollView, Image } from "@tarojs/components";
|
||||
import { Avatar } from "@nutui/nutui-react-taro";
|
||||
import { withAuth, EmptyState } from "@/components";
|
||||
import noticeService from "@/services/noticeService";
|
||||
import Taro from "@tarojs/taro";
|
||||
import "./index.scss";
|
||||
|
||||
// 评论/回复类型定义
|
||||
interface CommentReplyItem {
|
||||
id: string;
|
||||
user_avatar: string;
|
||||
user_nickname: string;
|
||||
action_type: "comment" | "reply"; // 评论了你的球局 / 回复了你的评论
|
||||
time: string;
|
||||
content: string;
|
||||
original_comment?: string; // 被回复的评论内容
|
||||
activity_image: string;
|
||||
activity_id?: string;
|
||||
is_read: number;
|
||||
}
|
||||
|
||||
const CommentReply = () => {
|
||||
const [commentList, setCommentList] = useState<CommentReplyItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
getCommentReplyList();
|
||||
}, []);
|
||||
|
||||
// 获取评论和回复列表
|
||||
const getCommentReplyList = async () => {
|
||||
if (loading) return;
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await noticeService.getNotificationList({
|
||||
notification_type: "comment", // 筛选评论类型
|
||||
});
|
||||
|
||||
if (res.code === 0) {
|
||||
// 映射数据
|
||||
const mappedList = res.data.list.map((item: any) => ({
|
||||
id: item.id,
|
||||
user_avatar: item.related_user_avatar || "",
|
||||
user_nickname: item.related_user_nickname || "匿名用户",
|
||||
action_type: (item.notification_type === "reply" ? "reply" : "comment") as "comment" | "reply",
|
||||
time: item.created_at,
|
||||
content: item.content || "",
|
||||
original_comment: item.original_content || "",
|
||||
activity_image: item.activity_image || "",
|
||||
activity_id: item.related_activity_id || "",
|
||||
is_read: item.is_read,
|
||||
}));
|
||||
|
||||
setCommentList(mappedList);
|
||||
}
|
||||
} catch (e) {
|
||||
Taro.showToast({
|
||||
title: "获取列表失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化时间显示
|
||||
const formatTime = (timeStr: string) => {
|
||||
if (!timeStr) return "";
|
||||
|
||||
const date = new Date(timeStr);
|
||||
const now = new Date();
|
||||
const diff = now.getTime() - date.getTime();
|
||||
const minutes = Math.floor(diff / (1000 * 60));
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (minutes < 60) {
|
||||
return `${minutes}分钟前`;
|
||||
} else if (hours < 24) {
|
||||
return `${hours}小时前`;
|
||||
} else if (days === 1) {
|
||||
return "1天前";
|
||||
} else if (days < 7) {
|
||||
return `${days}天前`;
|
||||
} else {
|
||||
const month = date.getMonth() + 1;
|
||||
const day = date.getDate();
|
||||
return `${month}月${day}日`;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理回复
|
||||
const handleReply = (item: CommentReplyItem) => {
|
||||
console.log("回复:", item);
|
||||
// TODO: 跳转到回复页面或弹出回复框
|
||||
};
|
||||
|
||||
// 处理返回
|
||||
const handleBack = () => {
|
||||
Taro.navigateBack();
|
||||
};
|
||||
|
||||
// 渲染评论/回复项
|
||||
const renderCommentItem = (item: CommentReplyItem) => {
|
||||
const actionText = item.action_type === "comment" ? "评论了你的球局" : "回复了你的评论";
|
||||
|
||||
return (
|
||||
<View className="comment-item" key={item.id}>
|
||||
<View className="comment-left">
|
||||
<Avatar
|
||||
className="user-avatar"
|
||||
src={item.user_avatar || "https://img.yzcdn.cn/vant/cat.jpeg"}
|
||||
size="48px"
|
||||
/>
|
||||
|
||||
<View className="comment-content">
|
||||
<Text className="user-nickname">{item.user_nickname}</Text>
|
||||
|
||||
<View className="action-row">
|
||||
<Text className="action-text">{actionText}</Text>
|
||||
<Text className="time-text">{formatTime(item.time)}</Text>
|
||||
</View>
|
||||
|
||||
<Text className="comment-text">{item.content}</Text>
|
||||
|
||||
{/* 如果是回复,显示被回复的评论 */}
|
||||
{item.action_type === "reply" && item.original_comment && (
|
||||
<View className="original-comment">
|
||||
<View className="quote-line"></View>
|
||||
<Text className="original-text">{item.original_comment}</Text>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* 回复按钮 */}
|
||||
<View className="reply-button" onClick={() => handleReply(item)}>
|
||||
<View className="reply-icon"></View>
|
||||
<Text className="reply-text">回复</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 右侧球局图片 */}
|
||||
<Image className="activity-image" src={item.activity_image} mode="aspectFill" />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<View className="comment-reply-container">
|
||||
{/* 顶部导航栏 */}
|
||||
<View className="navbar">
|
||||
<View className="navbar-content">
|
||||
<View className="back-button" onClick={handleBack}>
|
||||
<View className="back-icon"></View>
|
||||
</View>
|
||||
<Text className="navbar-title">收到的评论和回复</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 评论列表 */}
|
||||
<ScrollView
|
||||
scrollY
|
||||
className="comment-scroll"
|
||||
scrollWithAnimation
|
||||
enhanced
|
||||
showScrollbar={false}
|
||||
>
|
||||
{commentList.length > 0 ? (
|
||||
<View className="comment-list">
|
||||
{commentList.map(renderCommentItem)}
|
||||
|
||||
{/* 到底了提示 */}
|
||||
<View className="bottom-tip">
|
||||
<Text className="tip-text">到底了</Text>
|
||||
</View>
|
||||
</View>
|
||||
) : (
|
||||
<EmptyState text="暂无评论和回复" />
|
||||
)}
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default withAuth(CommentReply);
|
||||
Reference in New Issue
Block a user