fix: refactor notification display logic and add format function

This commit is contained in:
xyx
2026-07-13 14:52:03 +08:00
parent 6d42241918
commit 910a4263f6
4 changed files with 39 additions and 16 deletions

View File

@@ -3,6 +3,7 @@ import { Badge, Popover, Button, List, Typography, Empty } from 'antd';
import { BellOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
import api from '../api';
import { formatNotificationText, notificationTypeLabels } from '../utils/notification-display';
interface NotificationItem {
id: number;
@@ -14,18 +15,6 @@ interface NotificationItem {
createdAt: string;
}
const typeLabels: Record<string, string> = {
bill_generated: '账单',
bill_paid: '账单',
check_in: '入住',
check_out: '退宿',
deposit_due: '押金',
deposit_refunded: '押金',
class_change: '班级',
schedule_conflict: '排课',
announcement: '公告',
};
function timeAgo(dateStr: string): string {
const diff = Date.now() - new Date(dateStr).getTime();
const mins = Math.floor(diff / 60000);
@@ -163,7 +152,7 @@ const NotificationBell: React.FC = () => {
strong={!item.isRead}
style={{ fontSize: 14 }}
>
[{typeLabels[item.type] || item.type}] {item.title}
[{notificationTypeLabels[item.type] || item.type}] {formatNotificationText(item.title)}
</Typography.Text>
}
description={