- 从服务器拉取完整代码 - 按框架规范整理项目结构 - 配置 Drone CI 测试环境部署 - 包含后端(FastAPI)、前端(Vue3)、管理端 技术栈: Vue3 + TypeScript + FastAPI + MySQL
145 lines
2.9 KiB
TypeScript
145 lines
2.9 KiB
TypeScript
/**
|
||
* 站内消息通知 API
|
||
* 提供通知的查询、标记已读、删除等功能
|
||
*/
|
||
import { request } from './request'
|
||
|
||
/**
|
||
* 通知类型枚举
|
||
*/
|
||
export type NotificationType =
|
||
| 'position_assign' // 岗位分配
|
||
| 'course_assign' // 课程分配
|
||
| 'exam_remind' // 考试提醒
|
||
| 'task_assign' // 任务分配
|
||
| 'system' // 系统通知
|
||
|
||
/**
|
||
* 通知响应接口
|
||
*/
|
||
export interface Notification {
|
||
id: number
|
||
user_id: number
|
||
title: string
|
||
content?: string
|
||
type: NotificationType
|
||
is_read: boolean
|
||
related_id?: number
|
||
related_type?: string
|
||
sender_id?: number
|
||
sender_name?: string
|
||
created_at: string
|
||
updated_at: string
|
||
}
|
||
|
||
/**
|
||
* 通知列表响应接口
|
||
*/
|
||
export interface NotificationListResponse {
|
||
items: Notification[]
|
||
total: number
|
||
unread_count: number
|
||
}
|
||
|
||
/**
|
||
* 未读数量响应接口
|
||
*/
|
||
export interface NotificationCountResponse {
|
||
unread_count: number
|
||
total: number
|
||
}
|
||
|
||
/**
|
||
* 创建通知请求接口(管理员使用)
|
||
*/
|
||
export interface NotificationCreateRequest {
|
||
user_id: number
|
||
title: string
|
||
content?: string
|
||
type?: NotificationType
|
||
related_id?: number
|
||
related_type?: string
|
||
}
|
||
|
||
/**
|
||
* 批量创建通知请求接口(管理员使用)
|
||
*/
|
||
export interface NotificationBatchCreateRequest {
|
||
user_ids: number[]
|
||
title: string
|
||
content?: string
|
||
type?: NotificationType
|
||
related_id?: number
|
||
related_type?: string
|
||
}
|
||
|
||
/**
|
||
* 标记已读请求接口
|
||
*/
|
||
export interface MarkReadRequest {
|
||
notification_ids?: number[]
|
||
}
|
||
|
||
/**
|
||
* 通知 API
|
||
*/
|
||
export const notificationApi = {
|
||
/**
|
||
* 获取当前用户的通知列表
|
||
* @param params 查询参数
|
||
*/
|
||
getNotifications(params?: {
|
||
is_read?: boolean
|
||
type?: NotificationType
|
||
page?: number
|
||
page_size?: number
|
||
}) {
|
||
return request.get<NotificationListResponse>('/api/v1/notifications', { params })
|
||
},
|
||
|
||
/**
|
||
* 获取未读通知数量
|
||
*/
|
||
getUnreadCount() {
|
||
return request.get<NotificationCountResponse>('/api/v1/notifications/unread-count')
|
||
},
|
||
|
||
/**
|
||
* 标记通知为已读
|
||
* @param notification_ids 通知ID列表,不传则标记全部
|
||
*/
|
||
markAsRead(notification_ids?: number[]) {
|
||
return request.post('/api/v1/notifications/mark-read', { notification_ids })
|
||
},
|
||
|
||
/**
|
||
* 删除单条通知
|
||
* @param notificationId 通知ID
|
||
*/
|
||
deleteNotification(notificationId: number) {
|
||
return request.delete(`/api/v1/notifications/${notificationId}`)
|
||
},
|
||
|
||
/**
|
||
* 发送单条通知(管理员接口)
|
||
* @param data 通知数据
|
||
*/
|
||
sendNotification(data: NotificationCreateRequest) {
|
||
return request.post<Notification>('/api/v1/notifications/send', data)
|
||
},
|
||
|
||
/**
|
||
* 批量发送通知(管理员接口)
|
||
* @param data 批量通知数据
|
||
*/
|
||
sendBatchNotifications(data: NotificationBatchCreateRequest) {
|
||
return request.post('/api/v1/notifications/send-batch', data)
|
||
}
|
||
}
|
||
|
||
export default notificationApi
|
||
|
||
|
||
|
||
|