import React, { useState } from "react"; import { Modal, Button, Tabs, Empty, message } from "antd"; import type { TabsProps } from "antd"; import axios from "axios"; import { MESSAGE_STATUS, MESSAGE_TAB } from "@/constants"; import { useNotificationStore } from "@/store/NotificationStore"; import { Eraser, FileText } from "lucide-react"; import dayjs from "dayjs"; import { renderNoticeLength } from "@/utils/utils"; interface MessageModalProps { visible: boolean; onClose: () => void; socket: any; } const MessageModal: React.FC = ({ visible, onClose, socket, }) => { const [activeKey, setActiveKey] = useState(MESSAGE_TAB.UNREAD); const { notifications, changeNotification } = useNotificationStore(); const unreadNotifications = notifications.filter( (notification) => notification.is_read === MESSAGE_STATUS.UNREAD ); const tabItems: TabsProps["items"] = [ { key: MESSAGE_TAB.ALL, label: 全部, }, { key: MESSAGE_TAB.UNREAD, label: ( 未读 {!!unreadNotifications.length && ( {renderNoticeLength(unreadNotifications)} )} ), }, { key: MESSAGE_TAB.HAS_READ, label: 已读, }, ]; return ( 消息中心 {!!renderNoticeLength(unreadNotifications) && `(${renderNoticeLength(unreadNotifications)})`}
{ const res = await axios.post(`/notification/bazb/clearMsg`); if (res.data.code === 200) { changeNotification({ type: "clear" }); } }} > 清除消息
} open={visible} onCancel={onClose} footer={null} style={{ top: 30, maxWidth: "90%", maxHeight: "80%", }} >
{ setActiveKey(key); }} />
{(() => { let filteredNotifications = notifications; if (activeKey === MESSAGE_TAB.UNREAD) { filteredNotifications = notifications.filter( (notification) => notification.is_read === MESSAGE_STATUS.UNREAD ); } else if (activeKey === MESSAGE_TAB.HAS_READ) { filteredNotifications = notifications.filter( (notification) => notification.is_read === MESSAGE_STATUS.HAS_READ ); } return ( <> {filteredNotifications.length === 0 && (
)} {filteredNotifications.map((message, index) => (
病例时效提醒
{dayjs(message.timestamp).format("YYYY-MM-DD HH:mm")}

{message.title}

{message.content}

{message.footer || "祝您工作顺利!"}

))} ); })()}
); }; export default MessageModal;