Skip to content

Let's use AI to Earn!

通知相关问题

daoyian513dc31e6e06
diff --git a/src/app/[lng]/notification/notification.module.scss b/src/app/[lng]/notification/notification.module.scss
deleted file mode 100644
index fd71bc70..00000000
--- a/src/app/[lng]/notification/notification.module.scss
+++ /dev/null
@@ -1,171 +0,0 @@
-.notificationPage {
- min-height: 100vh;
- background-color: #f5f5f5;
- padding: 20px 0;
-}
-
-.container {
- max-width: 1200px;
- margin: 0 auto;
- padding: 0 20px;
-}
-
-.tabs {
- background: white;
- border-radius: 8px;
- padding: 20px;
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
-
- :global {
- .ant-tabs-nav {
- margin-bottom: 20px;
- }
-
- .ant-tabs-tab {
- font-size: 16px;
- font-weight: 500;
- }
- }
-}
-
-.notificationList {
- .header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20px;
- padding-bottom: 16px;
- border-bottom: 1px solid #f0f0f0;
-
- h2 {
- margin: 0;
- font-size: 20px;
- font-weight: 600;
- color: #333;
- }
- }
-}
-
-.notificationItem {
- padding: 16px 0;
- border-bottom: 1px solid #f0f0f0;
- transition: background-color 0.2s;
-
- &:hover {
- background-color: #fafafa;
- }
-
- &.unread {
- background-color: #f6ffed;
- border-left: 4px solid #52c41a;
- padding-left: 16px;
- }
-
- &:last-child {
- border-bottom: none;
- }
-}
-
-.notificationTitle {
- display: flex;
- align-items: center;
- gap: 8px;
- font-weight: 500;
- font-size: 16px;
- color: #333;
-}
-
-.notificationContent {
- width: 100%;
- margin-top: 8px;
-}
-
-.notificationMeta {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 8px;
- font-size: 12px;
- color: #666;
-
- .type {
- background-color: #f0f0f0;
- padding: 2px 8px;
- border-radius: 12px;
- font-size: 11px;
- }
-
- .time {
- color: #999;
- }
-}
-
-.content {
- color: #666;
- line-height: 1.6;
- margin-bottom: 8px;
- font-size: 14px;
-}
-
-.notificationDetail {
- h3 {
- margin-bottom: 16px;
- color: #333;
- font-size: 18px;
- font-weight: 600;
- }
-
- .meta {
- display: flex;
- justify-content: space-between;
- margin-bottom: 16px;
- padding: 12px 16px;
- background-color: #f5f5f5;
- border-radius: 6px;
- font-size: 14px;
- color: #666;
- }
-
- .content {
- line-height: 1.8;
- color: #333;
- white-space: pre-wrap;
- font-size: 14px;
- }
-}
-
-// 响应式设计
-@media (max-width: 768px) {
- .container {
- padding: 0 16px;
- }
-
- .tabs {
- padding: 16px;
- }
-
- .notificationList {
- .header {
- flex-direction: column;
- gap: 12px;
- align-items: flex-start;
-
- h2 {
- font-size: 18px;
- }
- }
- }
-
- .notificationMeta {
- flex-direction: column;
- align-items: flex-start;
- gap: 4px;
- }
-
- .notificationDetail {
- .meta {
- flex-direction: column;
- gap: 8px;
- }
- }
-}
\ No newline at end of file
diff --git a/src/app/[lng]/notification/page.tsx b/src/app/[lng]/notification/page.tsx
deleted file mode 100644
index badaf306..00000000
--- a/src/app/[lng]/notification/page.tsx
+++ /dev/null
@@ -1,227 +0,0 @@
-"use client";
-
-import React, { useState, useEffect } from "react";
-import { List, Button, message, Spin, Empty, Tabs, Badge, Modal } from "antd";
-import { CheckOutlined, CheckCircleOutlined } from "@ant-design/icons";
-import { useTransClient } from "@/app/i18n/client";
-import {
- getNotificationList,
- markNotificationAsRead,
- markAllNotificationsAsRead,
- type NotificationItem
-} from "@/api/notification";
-import styles from "./notification.module.scss";
-
-const NotificationPage = () => {
- const { t } = useTransClient("common");
- const [notifications, setNotifications] = useState<NotificationItem[]>([]);
- const [loading, setLoading] = useState(false);
- const [selectedNotification, setSelectedNotification] = useState<NotificationItem | null>(null);
- const [detailModalVisible, setDetailModalVisible] = useState(false);
- const [activeTab, setActiveTab] = useState("all");
-
- // 获取通知列表
- const fetchNotifications = async (type?: string) => {
- try {
- setLoading(true);
- const params: any = { page: 1, pageSize: 50 };
- if (type && type !== "all") {
- params.type = type;
- }
- const response = await getNotificationList(params);
- if (response && response.data) {
- setNotifications(response.data.list || []);
- }
- } catch (error) {
- message.error("获取通知列表失败");
- } finally {
- setLoading(false);
- }
- };
-
- // 标记单个通知为已读
- const handleMarkAsRead = async (id: string) => {
- try {
- await markNotificationAsRead(id);
- message.success("标记成功");
- fetchNotifications(activeTab === "all" ? undefined : activeTab);
- } catch (error) {
- message.error("标记失败");
- }
- };
-
- // 全部标记为已读
- const handleMarkAllAsRead = async () => {
- try {
- await markAllNotificationsAsRead();
- message.success("全部标记成功");
- fetchNotifications(activeTab === "all" ? undefined : activeTab);
- } catch (error) {
- message.error("标记失败");
- }
- };
-
- // 查看通知详情
- const handleViewDetail = (notification: NotificationItem) => {
- setSelectedNotification(notification);
- setDetailModalVisible(true);
- if (!notification.isRead) {
- handleMarkAsRead(notification.id);
- }
- };
-
- // 格式化时间
- const formatTime = (timeString: string) => {
- const date = new Date(timeString);
- 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 < 1) return "刚刚";
- if (minutes < 60) return `${minutes}分钟前`;
- if (hours < 24) return `${hours}小时前`;
- if (days < 7) return `${days}天前`;
- return date.toLocaleDateString();
- };
-
- // 获取通知类型文本
- const getNotificationTypeText = (type: string) => {
- const typeMap: Record<string, string> = {
- system: "系统通知",
- user: "用户通知",
- material: "素材通知",
- other: "其他通知"
- };
- return typeMap[type] || type;
- };
-
- // 处理标签页切换
- const handleTabChange = (key: string) => {
- setActiveTab(key);
- fetchNotifications(key === "all" ? undefined : key);
- };
-
- useEffect(() => {
- fetchNotifications();
- }, []);
-
- return (
- <div className={styles.notificationPage}>
- <div className={styles.container}>
- <Tabs
- activeKey={activeTab}
- onChange={handleTabChange}
- items={[
- {
- key: "all",
- label: "全部通知",
- children: (
- <div className={styles.notificationList}>
- <div className={styles.header}>
- <h2>全部通知</h2>
- <Button
- type="primary"
- icon={<CheckCircleOutlined />}
- onClick={handleMarkAllAsRead}
- disabled={!notifications.some(n => !n.isRead)}
- >
- 全部标记为已读
- </Button>
- </div>
- <Spin spinning={loading}>
- {notifications.length > 0 ? (
- <List
- dataSource={notifications}
- renderItem={(item) => (
- <List.Item
- className={`${styles.notificationItem} ${!item.isRead ? styles.unread : ""}`}
- actions={[
- !item.isRead && (
- <Button
- key="mark"
- type="text"
- size="small"
- icon={<CheckOutlined />}
- onClick={() => handleMarkAsRead(item.id)}
- >
- 标记为已读
- </Button>
- )
- ]}
- >
- <List.Item.Meta
- title={
- <div className={styles.notificationTitle}>
- <span>{item.title}</span>
- {!item.isRead && <Badge status="processing" />}
- </div>
- }
- description={
- <div className={styles.notificationContent}>
- <div className={styles.notificationMeta}>
- <span className={styles.type}>{getNotificationTypeText(item.type)}</span>
- <span className={styles.time}>{formatTime(item.createdAt)}</span>
- </div>
- <div className={styles.content}>
- {item.content.length > 200
- ? `${item.content.substring(0, 200)}...`
- : item.content
- }
- </div>
- <Button
- type="link"
- size="small"
- onClick={() => handleViewDetail(item)}
- >
- 查看详情
- </Button>
- </div>
- }
- />
- </List.Item>
- )}
- />
- ) : (
- <Empty description="暂无消息" />
- )}
- </Spin>
- </div>
- ),
- }
- ]}
- className={styles.tabs}
- />
- </div>
-
- {/* 通知详情弹窗 */}
- <Modal
- title="通知详情"
- open={detailModalVisible}
- onCancel={() => setDetailModalVisible(false)}
- footer={[
- <Button key="close" onClick={() => setDetailModalVisible(false)}>
- 关闭
- </Button>
- ]}
- width={600}
- >
- {selectedNotification && (
- <div className={styles.notificationDetail}>
- <h3>{selectedNotification.title}</h3>
- <div className={styles.meta}>
- <span>类型: {getNotificationTypeText(selectedNotification.type)}</span>
- <span>时间: {formatTime(selectedNotification.createdAt)}</span>
- </div>
- <div className={styles.content}>
- {selectedNotification.content}
- </div>
- </div>
- )}
- </Modal>
- </div>
- );
-};
-
-export default NotificationPage;
\ No newline at end of file
diff --git a/src/app/layout/LyaoutHeader.tsx b/src/app/layout/LyaoutHeader.tsx
index ff5baa47..d6c2b977 100644
--- a/src/app/layout/LyaoutHeader.tsx
+++ b/src/app/layout/LyaoutHeader.tsx
@@ -17,7 +17,7 @@ import {
} from "@ant-design/icons";
import { useRouter } from "next/navigation";
import { useTransClient } from "@/app/i18n/client";
-import NotificationPanel from "@/components/NotificationPanel";
+import NotificationPanel from "@/components/notification/NotificationPanel";
import { useNotification } from "@/hooks/useNotification";
export interface ILyaoutHeaderRef {}
diff --git a/src/app/notification/notification.module.scss b/src/app/notification/notification.module.scss
deleted file mode 100644
index fd71bc70..00000000
--- a/src/app/notification/notification.module.scss
+++ /dev/null
@@ -1,171 +0,0 @@
-.notificationPage {
- min-height: 100vh;
- background-color: #f5f5f5;
- padding: 20px 0;
-}
-
-.container {
- max-width: 1200px;
- margin: 0 auto;
- padding: 0 20px;
-}
-
-.tabs {
- background: white;
- border-radius: 8px;
- padding: 20px;
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
-
- :global {
- .ant-tabs-nav {
- margin-bottom: 20px;
- }
-
- .ant-tabs-tab {
- font-size: 16px;
- font-weight: 500;
- }
- }
-}
-
-.notificationList {
- .header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20px;
- padding-bottom: 16px;
- border-bottom: 1px solid #f0f0f0;
-
- h2 {
- margin: 0;
- font-size: 20px;
- font-weight: 600;
- color: #333;
- }
- }
-}
-
-.notificationItem {
- padding: 16px 0;
- border-bottom: 1px solid #f0f0f0;
- transition: background-color 0.2s;
-
- &:hover {
- background-color: #fafafa;
- }
-
- &.unread {
- background-color: #f6ffed;
- border-left: 4px solid #52c41a;
- padding-left: 16px;
- }
-
- &:last-child {
- border-bottom: none;
- }
-}
-
-.notificationTitle {
- display: flex;
- align-items: center;
- gap: 8px;
- font-weight: 500;
- font-size: 16px;
- color: #333;
-}
-
-.notificationContent {
- width: 100%;
- margin-top: 8px;
-}
-
-.notificationMeta {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 8px;
- font-size: 12px;
- color: #666;
-
- .type {
- background-color: #f0f0f0;
- padding: 2px 8px;
- border-radius: 12px;
- font-size: 11px;
- }
-
- .time {
- color: #999;
- }
-}
-
-.content {
- color: #666;
- line-height: 1.6;
- margin-bottom: 8px;
- font-size: 14px;
-}
-
-.notificationDetail {
- h3 {
- margin-bottom: 16px;
- color: #333;
- font-size: 18px;
- font-weight: 600;
- }
-
- .meta {
- display: flex;
- justify-content: space-between;
- margin-bottom: 16px;
- padding: 12px 16px;
- background-color: #f5f5f5;
- border-radius: 6px;
- font-size: 14px;
- color: #666;
- }
-
- .content {
- line-height: 1.8;
- color: #333;
- white-space: pre-wrap;
- font-size: 14px;
- }
-}
-
-// 响应式设计
-@media (max-width: 768px) {
- .container {
- padding: 0 16px;
- }
-
- .tabs {
- padding: 16px;
- }
-
- .notificationList {
- .header {
- flex-direction: column;
- gap: 12px;
- align-items: flex-start;
-
- h2 {
- font-size: 18px;
- }
- }
- }
-
- .notificationMeta {
- flex-direction: column;
- align-items: flex-start;
- gap: 4px;
- }
-
- .notificationDetail {
- .meta {
- flex-direction: column;
- gap: 8px;
- }
- }
-}
\ No newline at end of file
diff --git a/src/app/notification/page.tsx b/src/app/notification/page.tsx
deleted file mode 100644
index daab8992..00000000
--- a/src/app/notification/page.tsx
+++ /dev/null
@@ -1,239 +0,0 @@
-"use client";
-
-import React, { useState, useEffect } from "react";
-import { List, Button, message, Spin, Empty, Tabs, Badge, Modal } from "antd";
-import { CheckOutlined, CheckCircleOutlined } from "@ant-design/icons";
-import { useTransClient } from "@/app/i18n/client";
-import { useUserStore } from "@/store/user";
-import {
- getNotificationList,
- markNotificationAsRead,
- markAllNotificationsAsRead,
- type NotificationItem
-} from "@/api/notification";
-import styles from "./notification.module.scss";
-
-const NotificationPage = () => {
- const { t } = useTransClient("common");
- const token = useUserStore((state) => state.token);
- const [notifications, setNotifications] = useState<NotificationItem[]>([]);
- const [loading, setLoading] = useState(false);
- const [selectedNotification, setSelectedNotification] = useState<NotificationItem | null>(null);
- const [detailModalVisible, setDetailModalVisible] = useState(false);
- const [activeTab, setActiveTab] = useState("all");
-
- // 获取通知列表
- const fetchNotifications = async (type?: string) => {
- // 如果没有登录信息,不发送请求
- if (!token) {
- setNotifications([]);
- return;
- }
-
- try {
- setLoading(true);
- const params: any = { page: 1, pageSize: 50 };
- if (type && type !== "all") {
- params.type = type;
- }
- const response = await getNotificationList(params);
- if (response && response.data) {
- setNotifications(response.data.list || []);
- }
- } catch (error) {
- message.error("获取通知列表失败");
- } finally {
- setLoading(false);
- }
- };
-
- // 标记单个通知为已读
- const handleMarkAsRead = async (id: string) => {
- if (!token) return;
-
- try {
- await markNotificationAsRead(id);
- message.success("标记成功");
- fetchNotifications(activeTab === "all" ? undefined : activeTab);
- } catch (error) {
- message.error("标记失败");
- }
- };
-
- // 全部标记为已读
- const handleMarkAllAsRead = async () => {
- if (!token) return;
-
- try {
- await markAllNotificationsAsRead();
- message.success("全部标记成功");
- fetchNotifications(activeTab === "all" ? undefined : activeTab);
- } catch (error) {
- message.error("标记失败");
- }
- };
-
- // 查看通知详情
- const handleViewDetail = (notification: NotificationItem) => {
- setSelectedNotification(notification);
- setDetailModalVisible(true);
- if (!notification.isRead) {
- handleMarkAsRead(notification.id);
- }
- };
-
- // 格式化时间
- const formatTime = (timeString: string) => {
- const date = new Date(timeString);
- 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 < 1) return "刚刚";
- if (minutes < 60) return `${minutes}分钟前`;
- if (hours < 24) return `${hours}小时前`;
- if (days < 7) return `${days}天前`;
- return date.toLocaleDateString();
- };
-
- // 获取通知类型文本
- const getNotificationTypeText = (type: string) => {
- const typeMap: Record<string, string> = {
- system: "系统通知",
- user: "用户通知",
- material: "素材通知",
- other: "其他通知"
- };
- return typeMap[type] || type;
- };
-
- // 处理标签页切换
- const handleTabChange = (key: string) => {
- setActiveTab(key);
- fetchNotifications(key === "all" ? undefined : key);
- };
-
- useEffect(() => {
- fetchNotifications();
- }, [token]);
-
- return (
- <div className={styles.notificationPage}>
- <div className={styles.container}>
- <Tabs
- activeKey={activeTab}
- onChange={handleTabChange}
- items={[
- {
- key: "all",
- label: "全部通知",
- children: (
- <div className={styles.notificationList}>
- <div className={styles.header}>
- <h2>全部通知</h2>
- <Button
- type="primary"
- icon={<CheckCircleOutlined />}
- onClick={handleMarkAllAsRead}
- disabled={!notifications.some(n => !n.isRead) || !token}
- >
- 全部标记为已读
- </Button>
- </div>
- <Spin spinning={loading}>
- {notifications.length > 0 ? (
- <List
- dataSource={notifications}
- renderItem={(item) => (
- <List.Item
- className={`${styles.notificationItem} ${!item.isRead ? styles.unread : ""}`}
- actions={[
- !item.isRead && (
- <Button
- key="mark"
- type="text"
- size="small"
- icon={<CheckOutlined />}
- onClick={() => handleMarkAsRead(item.id)}
- >
- 标记为已读
- </Button>
- )
- ]}
- >
- <List.Item.Meta
- title={
- <div className={styles.notificationTitle}>
- <span>{item.title}</span>
- {!item.isRead && <Badge status="processing" />}
- </div>
- }
- description={
- <div className={styles.notificationContent}>
- <div className={styles.notificationMeta}>
- <span className={styles.type}>{getNotificationTypeText(item.type)}</span>
- <span className={styles.time}>{formatTime(item.createdAt)}</span>
- </div>
- <div className={styles.content}>
- {item.content.length > 200
- ? `${item.content.substring(0, 200)}...`
- : item.content
- }
- </div>
- <Button
- type="link"
- size="small"
- onClick={() => handleViewDetail(item)}
- >
- 查看详情
- </Button>
- </div>
- }
- />
- </List.Item>
- )}
- />
- ) : (
- <Empty description="暂无消息" />
- )}
- </Spin>
- </div>
- ),
- }
- ]}
- className={styles.tabs}
- />
- </div>
-
- {/* 通知详情弹窗 */}
- <Modal
- title="通知详情"
- open={detailModalVisible}
- onCancel={() => setDetailModalVisible(false)}
- footer={[
- <Button key="close" onClick={() => setDetailModalVisible(false)}>
- 关闭
- </Button>
- ]}
- width={600}
- >
- {selectedNotification && (
- <div className={styles.notificationDetail}>
- <h3>{selectedNotification.title}</h3>
- <div className={styles.meta}>
- <span>类型: {getNotificationTypeText(selectedNotification.type)}</span>
- <span>时间: {formatTime(selectedNotification.createdAt)}</span>
- </div>
- <div className={styles.content}>
- {selectedNotification.content}
- </div>
- </div>
- )}
- </Modal>
- </div>
- );
-};
-
-export default NotificationPage;
\ No newline at end of file
diff --git a/src/components/NotificationPanel.module.scss b/src/components/notification/NotificationPanel.module.scss
similarity index 100%
rename from src/components/NotificationPanel.module.scss
rename to src/components/notification/NotificationPanel.module.scss
diff --git a/src/components/notification/NotificationPanel.tsx b/src/components/notification/NotificationPanel.tsx
new file mode 100644
index 00000000..0314c9e9
--- /dev/null
+++ b/src/components/notification/NotificationPanel.tsx
@@ -0,0 +1,242 @@
+"use client";
+
+import React, { useState, useEffect } from "react";
+import { Badge, Button, List, Modal, message, Spin, Empty } from "antd";
+import { CheckOutlined } from "@ant-design/icons";
+import { useTransClient } from "@/app/i18n/client";
+import { useUserStore } from "@/store/user";
+import {
+ getNotificationList,
+ markNotificationAsRead,
+ markAllNotificationsAsRead,
+ getUnreadCount,
+ type NotificationItem
+} from "@/api/notification";
+import styles from "./NotificationPanel.module.scss";
+
+interface NotificationPanelProps {
+ visible: boolean;
+ onClose: () => void;
+}
+
+const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose }) => {
+ const { t } = useTransClient("common");
+ const token = useUserStore((state) => state.token);
+ const [notifications, setNotifications] = useState<NotificationItem[]>([]);
+ const [loading, setLoading] = useState(false);
+ const [unreadCount, setUnreadCount] = useState(0);
+ const [selectedNotification, setSelectedNotification] = useState<NotificationItem | null>(null);
+ const [detailModalVisible, setDetailModalVisible] = useState(false);
+
+ // 获取通知列表
+ const fetchNotifications = async () => {
+ // 如果没有登录信息,不发送请求
+ if (!token) {
+ setNotifications([]);
+ return;
+ }
+
+ try {
+ setLoading(true);
+ const response = await getNotificationList({ page: 1, pageSize: 20 });
+ if (response && response.data) {
+ setNotifications(response.data.list || []);
+ }
+ } catch (error) {
+ message.error("获取通知列表失败");
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ // 获取未读数量
+ const fetchUnreadCount = async () => {
+ // 如果没有登录信息,不发送请求
+ if (!token) {
+ setUnreadCount(0);
+ return;
+ }
+
+ try {
+ const response = await getUnreadCount();
+ if (response && response.data) {
+ setUnreadCount(response.data.count || 0);
+ }
+ } catch (error) {
+ console.error("获取未读数量失败:", error);
+ }
+ };
+
+ // 标记单个通知为已读
+ const handleMarkAsRead = async (id: string) => {
+ try {
+ await markNotificationAsRead(id);
+ message.success("标记成功");
+ fetchNotifications();
+ fetchUnreadCount();
+ } catch (error) {
+ message.error("标记失败");
+ }
+ };
+
+ // 全部标记为已读
+ const handleMarkAllAsRead = async () => {
+ try {
+ await markAllNotificationsAsRead();
+ message.success("全部标记成功");
+ fetchNotifications();
+ fetchUnreadCount();
+ } catch (error) {
+ message.error("标记失败");
+ }
+ };
+
+ // 查看通知详情
+ const handleViewDetail = (notification: NotificationItem) => {
+ setSelectedNotification(notification);
+ setDetailModalVisible(true);
+ if (!notification.isRead) {
+ handleMarkAsRead(notification.id);
+ }
+ };
+
+ // 格式化时间
+ const formatTime = (timeString: string) => {
+ const date = new Date(timeString);
+ 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 < 1) return "刚刚";
+ if (minutes < 60) return `${minutes}分钟前`;
+ if (hours < 24) return `${hours}小时前`;
+ if (days < 7) return `${days}天前`;
+ return date.toLocaleDateString();
+ };
+
+ // 获取通知类型文本
+ const getNotificationTypeText = (type: string) => {
+ const typeMap: Record<string, string> = {
+ system: "系统通知",
+ user: "用户通知",
+ material: "素材通知",
+ other: "其他通知"
+ };
+ return typeMap[type] || type;
+ };
+
+ useEffect(() => {
+ if (visible) {
+ fetchNotifications();
+ fetchUnreadCount();
+ }
+ }, [visible, token]);
+
+ return (
+ <>
+ <Modal
+ title="消息通知"
+ open={visible}
+ onCancel={onClose}
+ footer={[
+ <Button key="markAll" onClick={handleMarkAllAsRead} disabled={unreadCount === 0}>
+ 全部标记为已读
+ </Button>,
+ <Button key="close" onClick={onClose}>
+ 关闭
+ </Button>
+ ]}
+ width={600}
+ destroyOnClose
+ >
+ <Spin spinning={loading}>
+ {notifications.length > 0 ? (
+ <List
+ dataSource={notifications}
+ renderItem={(item) => (
+ <List.Item
+ className={`${styles.notificationItem} ${!item.isRead ? styles.unread : ""}`}
+ actions={[
+ !item.isRead && (
+ <Button
+ key="mark"
+ type="text"
+ size="small"
+ icon={<CheckOutlined />}
+ onClick={() => handleMarkAsRead(item.id)}
+ >
+ 标记为已读
+ </Button>
+ )
+ ]}
+ >
+ <List.Item.Meta
+ title={
+ <div className={styles.notificationTitle}>
+ <span>{item.title}</span>
+ {!item.isRead && <Badge status="processing" />}
+ </div>
+ }
+ description={
+ <div className={styles.notificationContent}>
+ <div className={styles.notificationMeta}>
+ <span className={styles.type}>{getNotificationTypeText(item.type)}</span>
+ <span className={styles.time}>{formatTime(item.createdAt)}</span>
+ </div>
+ <div className={styles.content}>
+ {item.content.length > 100
+ ? `${item.content.substring(0, 100)}...`
+ : item.content
+ }
+ </div>
+ <Button
+ type="link"
+ size="small"
+ onClick={() => handleViewDetail(item)}
+ >
+ 查看详情
+ </Button>
+ </div>
+ }
+ />
+ </List.Item>
+ )}
+ />
+ ) : (
+ <Empty description="暂无消息" />
+ )}
+ </Spin>
+ </Modal>
+
+ {/* 通知详情弹窗 */}
+ <Modal
+ title="通知详情"
+ open={detailModalVisible}
+ onCancel={() => setDetailModalVisible(false)}
+ footer={[
+ <Button key="close" onClick={() => setDetailModalVisible(false)}>
+ 关闭
+ </Button>
+ ]}
+ width={500}
+ >
+ {selectedNotification && (
+ <div className={styles.notificationDetail}>
+ <h3>{selectedNotification.title}</h3>
+ <div className={styles.meta}>
+ <span>类型: {getNotificationTypeText(selectedNotification.type)}</span>
+ <span>时间: {formatTime(selectedNotification.createdAt)}</span>
+ </div>
+ <div className={styles.content}>
+ {selectedNotification.content}
+ </div>
+ </div>
+ )}
+ </Modal>
+ </>
+ );
+};
+
+export default NotificationPanel;
\ No newline at end of file