1
This commit is contained in:
@@ -38,12 +38,16 @@ const AdminNotificationManager: React.FC = () => {
|
||||
const [readModal, setReadModal] = useState<{ open: boolean; notifId: string; title: string }>({ open: false, notifId: '', title: '' });
|
||||
const [readUsers, setReadUsers] = useState<ReadUser[]>([]);
|
||||
const [readLoading, setReadLoading] = useState(false);
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
const [total, setTotal] = useState(0);
|
||||
|
||||
const load = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await getAdminNotifications();
|
||||
const userList = await getAdminUsers();
|
||||
const res = await getAdminNotifications(page, pageSize);
|
||||
const userRes = await getAdminUsers(1, 1000);
|
||||
const userList = userRes.items || [];
|
||||
const userMap: Record<string, string> = {};
|
||||
userList.forEach((u: any) => { userMap[u.id] = u.username; });
|
||||
const items = (res.items || []).map((n: any) => ({
|
||||
@@ -56,6 +60,7 @@ const AdminNotificationManager: React.FC = () => {
|
||||
createdAt: n.createdAt,
|
||||
}));
|
||||
setNotifications(items);
|
||||
setTotal(res.total || 0);
|
||||
setUsers(userList.map((u: any) => ({ id: u.id, username: u.username })));
|
||||
} catch {
|
||||
message.error('加载通知列表失败');
|
||||
@@ -64,7 +69,12 @@ const AdminNotificationManager: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => { load(); }, []);
|
||||
useEffect(() => { load(); }, [page, pageSize]);
|
||||
|
||||
const handlePageChange = (p: number, ps: number) => {
|
||||
setPage(p);
|
||||
setPageSize(ps);
|
||||
};
|
||||
|
||||
const handleSend = async () => {
|
||||
try {
|
||||
@@ -161,7 +171,7 @@ const AdminNotificationManager: React.FC = () => {
|
||||
<Space>
|
||||
<BellOutlined style={{ fontSize: 18, color: '#6366f1' }} />
|
||||
<Typography.Text strong style={{ fontSize: 16 }}>消息推送管理</Typography.Text>
|
||||
<Tag color="purple">{notifications.length} 条消息</Tag>
|
||||
<Tag color="purple">共 {total} 条消息</Tag>
|
||||
</Space>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={() => setModalOpen(true)}
|
||||
style={{ borderRadius: 8 }}>
|
||||
@@ -174,7 +184,14 @@ const AdminNotificationManager: React.FC = () => {
|
||||
dataSource={notifications}
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
pagination={{ pageSize: 10, showTotal: (t) => `共 ${t} 条消息` }}
|
||||
pagination={{
|
||||
current: page,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
onChange: handlePageChange,
|
||||
showSizeChanger: true,
|
||||
showTotal: (t) => `共 ${t} 条消息`,
|
||||
}}
|
||||
scroll={{ x: 900 }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user