feat: 添加通知功能,包括UI页面、状态管理Hook和API服务集成。
This commit is contained in:
52
src/services/notificationService.ts
Normal file
52
src/services/notificationService.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import api from './api';
|
||||
|
||||
export interface Notification {
|
||||
id: number;
|
||||
user_id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
type: string;
|
||||
is_read: boolean;
|
||||
link?: string;
|
||||
read_at?: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface NotificationListResponse {
|
||||
success: boolean;
|
||||
data: {
|
||||
notifications: Notification[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface UnreadCountResponse {
|
||||
success: boolean;
|
||||
data: {
|
||||
count: number;
|
||||
};
|
||||
}
|
||||
|
||||
export const notificationService = {
|
||||
getNotifications: (page: number = 1, limit: number = 10, isRead?: boolean) => {
|
||||
const params: Record<string, string | number | boolean> = { page, limit };
|
||||
if (isRead !== undefined) {
|
||||
params.is_read = isRead;
|
||||
}
|
||||
return api.get<NotificationListResponse>('/notifications', params);
|
||||
},
|
||||
|
||||
getUnreadCount: () => {
|
||||
return api.get<UnreadCountResponse>('/notifications/unread-count');
|
||||
},
|
||||
|
||||
markAsRead: (id: number) => {
|
||||
return api.put<{ success: boolean }>(`/notifications/${id}/read`);
|
||||
},
|
||||
|
||||
markAllAsRead: () => {
|
||||
return api.put<{ success: boolean }>('/notifications/read-all');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user