MessageModal.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import React, { useState } from "react";
  2. import { Modal, Button, Tabs } from "antd";
  3. import { CheckCircleOutlined, EyeOutlined } from "@ant-design/icons";
  4. import type { TabsProps } from "antd";
  5. import { MESSAGE_TAB } from "@/constants";
  6. import { useNotificationStore } from "@/store/NotificationStore";
  7. import { Eraser, FileText } from "lucide-react";
  8. import dayjs from "dayjs";
  9. interface MessageModalProps {
  10. visible: boolean;
  11. onClose: () => void;
  12. socket: any;
  13. }
  14. const MessageModal: React.FC<MessageModalProps> = ({
  15. visible,
  16. onClose,
  17. socket,
  18. }) => {
  19. const [activeKey, setActiveKey] = useState(MESSAGE_TAB.UNREAD);
  20. const { notifications } = useNotificationStore();
  21. console.log("notifications", notifications);
  22. const tabItems: TabsProps["items"] = [
  23. {
  24. key: MESSAGE_TAB.ALL,
  25. label: (
  26. <span className="flex">
  27. 全部
  28. <span className="text-xs text-white bg-red-500 rounded-full w-5 h-5 flex justify-center items-center">
  29. {notifications.length > 9 ? "9+" : notifications.length}
  30. </span>
  31. </span>
  32. ),
  33. },
  34. {
  35. key: MESSAGE_TAB.UNREAD,
  36. label: (
  37. <span className="flex">
  38. 未读{" "}
  39. <span className="text-xs text-white bg-red-500 rounded-full w-5 h-5 flex justify-center items-center">
  40. {notifications.filter(
  41. (notification) => notification.status === MESSAGE_TAB.UNREAD
  42. ).length > 9
  43. ? "9+"
  44. : notifications.filter(
  45. (notification) => notification.status === MESSAGE_TAB.UNREAD
  46. ).length}
  47. </span>
  48. </span>
  49. ),
  50. },
  51. {
  52. key: MESSAGE_TAB.HAS_READ,
  53. label: (
  54. <span className="flex">
  55. 已读
  56. <span className="text-xs text-white bg-red-500 rounded-full w-5 h-5 flex justify-center items-center">
  57. {notifications.filter(
  58. (notification) => notification.status === MESSAGE_TAB.HAS_READ
  59. ).length > 9
  60. ? "9+"
  61. : notifications.filter(
  62. (notification) => notification.status === MESSAGE_TAB.HAS_READ
  63. ).length}
  64. </span>
  65. </span>
  66. ),
  67. },
  68. ];
  69. return (
  70. <Modal
  71. title={
  72. <div className="flex items-center">
  73. <span>消息中心 (1)</span>
  74. <div className="cursor-pointer hover:bg-gray-100 rounded-md px-2 py-1 ml-2 text-xs flex justify-center items-center gap-1">
  75. <Eraser size={12} />
  76. 清除消息
  77. </div>
  78. </div>
  79. }
  80. open={visible}
  81. onCancel={onClose}
  82. footer={null}
  83. width={600}
  84. style={{ top: 10 }}
  85. >
  86. <div className="flex flex-col">
  87. <Tabs
  88. activeKey={activeKey}
  89. items={tabItems}
  90. className="mb-4"
  91. onChange={(key) => {
  92. setActiveKey(key);
  93. }}
  94. />
  95. <div className="space-y-4 max-h-[70vh] overflow-auto">
  96. {notifications
  97. .filter(
  98. (notification) =>
  99. activeKey === MESSAGE_TAB.ALL ||
  100. notification.status === activeKey
  101. )
  102. .map((message, index) => (
  103. <div
  104. key={index}
  105. className="p-4 bg-gray-50 rounded-lg shadow-sm flex flex-col gap-4"
  106. >
  107. <div className="flex justify-between items-center">
  108. <div className="flex gap-1 items-center">
  109. <div className="p-1 bg-blue-500 rounded-full w-6 h-6 text-white flex justify-center items-center">
  110. <FileText size={14} />
  111. </div>
  112. <div className="font-bold">病例时效提醒</div>
  113. </div>
  114. <div className="text-gray-500 text-xs">
  115. {dayjs(message.timestamp).format("YYYY-MM-DD HH:mm")}
  116. </div>
  117. </div>
  118. <div className="flex items-start space-x-4">
  119. <div className="flex-1">
  120. <div className="flex">
  121. <h4 className="text-sm font-semibold">{message.title}</h4>
  122. </div>
  123. <p className="text-gray-700 mt-1 indent-[1.75rem]">
  124. {message.message}
  125. </p>
  126. <p className="text-gray-700 mt-1 indent-[1.75rem]">
  127. {message.footer || "祝您工作顺利!"}
  128. </p>
  129. <div className="mt-2 flex space-x-2 justify-end">
  130. <Button size="middle">知道了</Button>
  131. <Button type="primary" size="middle">
  132. 去查看
  133. </Button>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. ))}
  139. </div>
  140. </div>
  141. </Modal>
  142. );
  143. };
  144. export default MessageModal;