Files
hms/apps/web/src/api/health/alerts.ts
iven 27c32e5561
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled
feat(web): 实时告警仪表盘页面 + SSE Hook + 告警详情面板
- 新增 AlertDashboard 页面:实时告警列表 + 统计摘要 + 详情面板
- 新增 useAlertSSE Hook:封装 SSE 连接、自动重连、事件分发
- 新增 AlertDetailPanel 组件:告警详情展示 + 确认/忽略/恢复操作
- alertApi.list 添加 doctor_id 参数支持
- 注册 /health/alert-dashboard 路由 + 面包屑映射
2026-04-28 19:59:51 +08:00

88 lines
2.6 KiB
TypeScript

import client from '../client';
import type { PaginatedResponse } from '../types';
// --- Types ---
export interface Alert {
id: string;
patient_id: string;
rule_id: string;
severity: string;
title: string;
detail?: Record<string, unknown>;
status: string;
acknowledged_by?: string;
acknowledged_at?: string;
resolved_at?: string;
created_at: string;
version: number;
}
export interface AlertRule {
id: string;
name: string;
description?: string;
device_type: string;
condition_type: string;
condition_params: Record<string, unknown>;
severity: string;
is_active: boolean;
apply_tags?: Record<string, unknown>;
notify_roles: unknown[];
cooldown_minutes: number;
created_at: string;
updated_at: string;
version: number;
}
export interface CreateAlertRuleReq {
name: string;
description?: string;
device_type: string;
condition_type: string;
condition_params: Record<string, unknown>;
severity?: string;
apply_tags?: Record<string, unknown>;
notify_roles?: unknown[];
cooldown_minutes?: number;
}
export interface UpdateAlertRuleReq {
name?: string;
description?: string;
condition_params?: Record<string, unknown>;
severity?: string;
apply_tags?: Record<string, unknown>;
notify_roles?: unknown[];
cooldown_minutes?: number;
version: number;
}
// --- API ---
export const alertApi = {
list: (params?: { patient_id?: string; doctor_id?: string; status?: string; page?: number; page_size?: number }) =>
client.get('/health/alerts', { params }).then((r) => r.data.data as PaginatedResponse<Alert>),
acknowledge: (id: string, version: number) =>
client.put(`/health/alerts/${id}/acknowledge`, { version }).then((r) => r.data.data as Alert),
dismiss: (id: string, version: number) =>
client.put(`/health/alerts/${id}/dismiss`, { version }).then((r) => r.data.data as Alert),
resolve: (id: string, version: number) =>
client.put(`/health/alerts/${id}/resolve`, { version }).then((r) => r.data.data as Alert),
};
export const alertRuleApi = {
list: (params?: { device_type?: string; page?: number; page_size?: number }) =>
client.get('/health/alert-rules', { params }).then((r) => r.data.data as PaginatedResponse<AlertRule>),
create: (data: CreateAlertRuleReq) =>
client.post('/health/alert-rules', data).then((r) => r.data.data as AlertRule),
update: (id: string, data: UpdateAlertRuleReq) =>
client.put(`/health/alert-rules/${id}`, data).then((r) => r.data.data as AlertRule),
deactivate: (id: string, version: number) =>
client.put(`/health/alert-rules/${id}/deactivate`, { version }).then((r) => r.data.data as AlertRule),
};