import { Text, View } from "@tarojs/components"; import { useLoad, setNavigationBarTitle, navigateTo } from "@tarojs/taro"; import { timeFormat } from "../../../utils"; import { Image } from "@nutui/nutui-react-taro"; import { Message } from "@nutui/icons-react-taro"; import { useEffect, useState } from "react"; import CommentInput from "../../../components/comment-list/comment-input"; import { getNotificationListApi, markAsReadByTypeApi, } from "../../../api/notifications"; const MessageList = () => { const [showCommentInput, setShowCommentInput] = useState(false); const [notificationList, setNotificationList] = useState([]); const [CommentPostId, setCommentPostId] = useState(0); const [CommentParentCommentId, setCommentParentCommentId] = useState(0); const [type, setType] = useState(""); const [typeId, setTypeId] = useState("0"); useLoad((options) => { setType(options.type); switch (options.type) { case "like": setTypeId("4,5"); handleReadNotification("4,5"); setNavigationBarTitle({ title: "收到的点赞", }); break; case "comment": setTypeId("1,2,3"); handleReadNotification("1,2,3"); setNavigationBarTitle({ title: "评论和@", }); break; case "follow": setTypeId("6,7"); handleReadNotification("6,7"); setNavigationBarTitle({ title: "关注和分享", }); break; default: break; } }); // 标记消息类型通知为已读 const handleReadNotification = async (type_id) => { markAsReadByTypeApi({ type_id }); }; const getNotificationList = async () => { const res: any = await getNotificationListApi({ type_id: typeId, page: 1, page_size: 10, }); if (res.code === 200) { setNotificationList(res.data.list); } }; useEffect(() => { getNotificationList(); }, [typeId]); return ( {notificationList.map((item) => { return ( {item.nickname || item.username} {timeFormat(item.created_at)} {item.type_id === 4 ? "点赞了你的动态" : ""} {item.type_id === 5 ? "点赞了你的评论" : ""} {item.type_id === 2 ? "评论了你的动态" : ""} {item.type_id === 3 ? item.reply_comment_info.content : ""} {item.type_id === 1 ? `${ item.source_type === "post" ? "在动态中" : "在评论中" }刚刚@了你 ` : ""} {item.type_id === 6 ? "关注了你" : ""} {item.type_id === 7 ? "分享了你的动态" : ""} {item.source_type === "comment" ? item.sourse_info.content : ""} {item.source_type === "post" && item.type_id === 2 ? item.reply_comment_info.content : ""} {/* 回复/评论 */} {item.type_id === 2 || item.type_id === 3 || (item.type_id === 1 && item.source_type === "comment") ? ( { setShowCommentInput(true); setCommentPostId(item.source_post_info.id); setCommentParentCommentId(item.reply_comment_info.id); }} > 回复 ) : ( <> )} {item.source_post_info ? ( { navigateTo({ url: `/pages/detail/index?id=${item.source_post_info.id}`, }); }} > ) : ( <> )} ); })} {showCommentInput ? ( setShowCommentInput(false)} onOK={() => { setShowCommentInput(false); getNotificationList(); }} /> ) : null} ); }; export default MessageList;