/** * 通知管理服务 * 负责通知数据的API调用 */ import apiClient from '@/infrastructure/api/client'; import { API_ENDPOINTS } from '@/infrastructure/api/endpoints'; /** 通知类型 */ export type NotificationType = 'SYSTEM' | 'ACTIVITY' | 'REWARD' | 'UPGRADE' | 'ANNOUNCEMENT'; /** 通知优先级 */ export type NotificationPriority = 'LOW' | 'NORMAL' | 'HIGH' | 'URGENT'; /** 目标用户类型 */ export type TargetType = 'ALL' | 'NEW_USER' | 'VIP'; /** 通知项 */ export interface NotificationItem { id: string; title: string; content: string; type: NotificationType; priority: NotificationPriority; targetType: TargetType; imageUrl: string | null; linkUrl: string | null; isEnabled: boolean; publishedAt: string | null; expiresAt: string | null; createdAt: string; updatedAt: string; createdBy: string; } /** 创建通知请求 */ export interface CreateNotificationRequest { title: string; content: string; type: NotificationType; priority?: NotificationPriority; targetType?: TargetType; imageUrl?: string; linkUrl?: string; publishedAt?: string; expiresAt?: string; } /** 更新通知请求 */ export interface UpdateNotificationRequest { title?: string; content?: string; type?: NotificationType; priority?: NotificationPriority; targetType?: TargetType; imageUrl?: string | null; linkUrl?: string | null; isEnabled?: boolean; publishedAt?: string | null; expiresAt?: string | null; } /** 查询通知列表参数 */ export interface ListNotificationsParams { type?: NotificationType; limit?: number; offset?: number; } /** 通知类型选项 */ export const NOTIFICATION_TYPE_OPTIONS = [ { value: 'SYSTEM', label: '系统通知', color: 'blue' }, { value: 'ACTIVITY', label: '活动通知', color: 'green' }, { value: 'REWARD', label: '收益通知', color: 'yellow' }, { value: 'UPGRADE', label: '升级通知', color: 'purple' }, { value: 'ANNOUNCEMENT', label: '公告', color: 'orange' }, ] as const; /** 通知优先级选项 */ export const NOTIFICATION_PRIORITY_OPTIONS = [ { value: 'LOW', label: '低', color: 'gray' }, { value: 'NORMAL', label: '普通', color: 'blue' }, { value: 'HIGH', label: '高', color: 'orange' }, { value: 'URGENT', label: '紧急', color: 'red' }, ] as const; /** 目标用户类型选项 */ export const TARGET_TYPE_OPTIONS = [ { value: 'ALL', label: '全部用户' }, { value: 'NEW_USER', label: '新用户' }, { value: 'VIP', label: 'VIP用户' }, ] as const; /** * 通知管理服务 */ export const notificationService = { /** * 获取通知列表 */ async getNotifications(params: ListNotificationsParams = {}): Promise { return apiClient.get(API_ENDPOINTS.NOTIFICATIONS.LIST, { params }); }, /** * 获取通知详情 */ async getNotification(id: string): Promise { return apiClient.get(API_ENDPOINTS.NOTIFICATIONS.DETAIL(id)); }, /** * 创建通知 */ async createNotification(data: CreateNotificationRequest): Promise { return apiClient.post(API_ENDPOINTS.NOTIFICATIONS.CREATE, data); }, /** * 更新通知 */ async updateNotification(id: string, data: UpdateNotificationRequest): Promise { return apiClient.put(API_ENDPOINTS.NOTIFICATIONS.UPDATE(id), data); }, /** * 删除通知 */ async deleteNotification(id: string): Promise { return apiClient.delete(API_ENDPOINTS.NOTIFICATIONS.DELETE(id)); }, /** * 切换通知启用状态 */ async toggleNotification(id: string, isEnabled: boolean): Promise { return apiClient.put(API_ENDPOINTS.NOTIFICATIONS.UPDATE(id), { isEnabled }); }, }; export default notificationService;