import { useState, useEffect } from "react"; import { View, Text, ScrollView, Image } from "@tarojs/components"; import { Avatar } from "@nutui/nutui-react-taro"; import GuideBar from "@/components/GuideBar"; import { withAuth } from "@/components"; import noticeService from "@/services/noticeService"; import Taro, { useRouter } from "@tarojs/taro"; import "./index.scss"; // 消息类型定义 interface MessageItem { id: string; type: "system" | "user" | "like" | "comment" | "follow"; title: string; content: string; time: string; avatar?: string; isRead: boolean; hasAction?: boolean; actionText?: string; } const Message = () => { const [activeTab] = useState<"all" | "like" | "comment" | "follow">("all"); const [messageList, setMessageList] = useState([]); useEffect(() => { const getNoticeList = async () => { try { const res = await noticeService.getNotificationList({}); if (res.code === 0) { setMessageList(res.data.list); } } catch (e) { Taro.showToast({ title: "获取列表失败,请重试", icon: "none", duration: 2000, }); } finally { } }; getNoticeList(); }, []); // 过滤消息 const filteredMessages = messageList.filter((message) => { if (activeTab === "all") return true; return message.type === activeTab; }); // 渲染消息项 const renderMessageItem = (message: MessageItem) => { if (message.type === "system") { return ( {message.title} {message.time} {message.content} {message.hasAction && ( {message.actionText} )} ); } return ( {message.title} {message.time} {message.content} {!message.isRead && } ); }; return ( {/* 导航栏 */} 消息 {/* 消息列表 */} {filteredMessages.length > 0 ? ( {filteredMessages.map(renderMessageItem)} ) : ( 暂无消息 )} {/* 底部导航 */} ); }; export default withAuth(Message);