增加新接口定义

This commit is contained in:
2025-10-25 15:27:27 +08:00
parent ab8ea6977f
commit ea44c9caea
3 changed files with 429 additions and 0 deletions

View File

@@ -121,6 +121,49 @@ import http from '../utils/http';
* @property {number} [operator_id]
*/
/**
* @typedef {('邮件'|'企业微信'|'飞书'|'日志')} NotifierType
*/
/**
* @typedef {('发送成功'|'发送失败'|'已跳过')} NotificationStatus
*/
/**
* @typedef {object} NotificationDTO
* @property {number} id
* @property {number} user_id
* @property {NotifierType} notifier_type
* @property {string} to_address
* @property {string} title
* @property {string} message
* @property {number} level - 日志级别, 见 ZapcoreLevel 枚举
* @property {string} alarm_timestamp
* @property {NotificationStatus} status
* @property {string} error_message
* @property {string} created_at
* @property {string} updated_at
*/
/**
* @typedef {object} ListNotificationResponse
* @property {Array<NotificationDTO>} list
* @property {PaginationDTO} pagination
*/
/**
* @typedef {object} NotificationsParams
* @property {number} [page]
* @property {number} [pageSize]
* @property {string} [order_by]
* @property {string} [start_time]
* @property {string} [end_time]
* @property {number} [level] - 日志级别, 见 ZapcoreLevel 枚举
* @property {NotifierType} [notifier_type]
* @property {NotificationStatus} [status]
* @property {number} [user_id]
*/
/**
* @typedef {('等待中'|'已完成'|'已超时')} PendingCollectionStatus
*/
@@ -606,6 +649,22 @@ import http from '../utils/http';
* @property {number} [operator_id]
*/
// --- Enums ---
/**
* 日志级别, 对应后端的 zapcore.Level
* @enum {number}
*/
export const ZapcoreLevel = {
Debug: -1,
Info: 0,
Warn: 1,
Error: 2,
DPanic: 3,
Panic: 4,
Fatal: 5,
Invalid: 6,
};
// --- Functions ---
@@ -647,6 +706,16 @@ export const getMedicationLogs = async (params) => {
return processResponse(responseData);
};
/**
* 批量查询通知
* @param {NotificationsParams} params - 查询参数
* @returns {Promise<{list: Array<NotificationDTO>, total: number}>}
*/
export const getNotifications = async (params) => {
const responseData = await http.get('/api/v1/monitor/notifications', { params });
return processResponse(responseData);
};
/**
* 获取待采集请求列表
* @param {PendingCollectionsParams} params - 查询参数

View File

@@ -71,6 +71,15 @@ import http from '../utils/http';
* @property {string} [username]
*/
/**
* @typedef {('邮件'|'企业微信'|'飞书'|'日志')} NotifierType
*/
/**
* @typedef {object} SendTestNotificationRequest
* @property {NotifierType} type - Type 指定要测试的通知渠道
*/
/**
* 创建一个新用户
* @param {CreateUserRequest} userData - 用户信息
@@ -99,8 +108,19 @@ const getUserHistory = (id, params) => {
return http.get(`/api/v1/users/${id}/history`, { params });
};
/**
* 发送测试通知
* @param {number} id - 用户ID
* @param {SendTestNotificationRequest} data - 请求体
* @returns {Promise<string>}
*/
const sendTestNotification = (id, data) => {
return http.post(`/api/v1/users/${id}/notifications/test`, data);
};
export const UserApi = {
createUser,
login,
getUserHistory,
sendTestNotification,
};