diff --git a/src/pages/Notifications/NotificationPublish.tsx b/src/pages/Notifications/NotificationPublish.tsx index aa8852a..861d27e 100644 --- a/src/pages/Notifications/NotificationPublish.tsx +++ b/src/pages/Notifications/NotificationPublish.tsx @@ -1,15 +1,44 @@ -import React, { useState } from 'react'; -import { Form, Input, Select, Button, message, Card, Alert, Row, Col } from 'antd'; +import React, { useState, useEffect } from 'react'; +import { Form, Input, Select, Button, message, Card, Alert, Row, Col, Empty, Spin } from 'antd'; import { Icon } from '@iconify/react'; import request from '../../utils/request'; const { TextArea } = Input; const { Option } = Select; +interface Announcement { + id: number; + title: string; + content: string; + type: string; + sent_count: number; + created_at: string; +} + const NotificationPublish: React.FC = () => { const [loading, setLoading] = useState(false); + const [historyLoading, setHistoryLoading] = useState(false); + const [history, setHistory] = useState([]); const [form] = Form.useForm(); + const fetchHistory = async () => { + setHistoryLoading(true); + try { + const res: any = await request.get('/notifications/announcements?limit=5'); + if (res && res.announcements) { + setHistory(res.announcements); + } + } catch (error) { + console.error('获取历史记录失败:', error); + } finally { + setHistoryLoading(false); + } + }; + + useEffect(() => { + fetchHistory(); + }, []); + const onFinish = async (values: any) => { setLoading(true); try { @@ -19,6 +48,7 @@ const NotificationPublish: React.FC = () => { style: { marginTop: '10vh' } }); form.resetFields(); + fetchHistory(); // Refresh history after publish } catch (error) { console.error('发布失败:', error); } finally { @@ -26,6 +56,16 @@ const NotificationPublish: React.FC = () => { } }; + const formatTime = (timeStr: string) => { + const date = new Date(timeStr); + return date.toLocaleString('zh-CN', { + month: 'numeric', + day: 'numeric', + hour: '2-digit', + minute: '2-digit' + }); + }; + return (
@@ -113,7 +153,7 @@ const NotificationPublish: React.FC = () => { } @@ -127,36 +167,43 @@ const NotificationPublish: React.FC = () => { 最近发布历史
} + extra={} variant="borderless" > - {[ - { title: '系统性能优化完成', time: '1小时前', type: 'info' }, - { title: '夜间数据库升级', time: '昨天', type: 'alert' }, - { title: '欢迎新用户加入', time: '3天前', type: 'system' } - ].map((item, idx) => ( -
-
-
{item.title}
-
{item.time}
-
-
- {item.type.toUpperCase()} -
-
- ))} - + + {history.length === 0 ? ( + + ) : ( + history.map((item, idx) => ( +
+
+
+ {item.title} +
+
+ {formatTime(item.created_at)} · 推送 {item.sent_count} 人 +
+
+
+ {item.type.toUpperCase()} +
+
+ )) + )} +