refactor(web): alerts + deviceReadings API 迁移为对象风格导出
- alerts.ts: listAlerts → alertApi.list, acknowledgeAlert → alertApi.acknowledge 等 - deviceReadings.ts: batchCreateReadings → deviceReadingApi.batchCreate 等 - AlertList/AlertRuleList 引用处同步更新 - 其余 19 个函数式 API 文件记为待迁移(旧文件不强制迁移)
This commit is contained in:
@@ -57,53 +57,31 @@ export interface UpdateAlertRuleReq {
|
|||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Alert API ---
|
// --- API ---
|
||||||
export async function listAlerts(params?: {
|
export const alertApi = {
|
||||||
patient_id?: string;
|
list: (params?: { patient_id?: string; status?: string; page?: number; page_size?: number }) =>
|
||||||
status?: string;
|
client.get('/health/alerts', { params }).then((r) => r.data.data as PaginatedResponse<Alert>),
|
||||||
page?: number;
|
|
||||||
page_size?: number;
|
|
||||||
}) {
|
|
||||||
const res = await client.get('/health/alerts', { params });
|
|
||||||
return res.data.data as PaginatedResponse<Alert>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function acknowledgeAlert(id: string, version: number) {
|
acknowledge: (id: string, version: number) =>
|
||||||
const res = await client.put(`/health/alerts/${id}/acknowledge`, { version });
|
client.put(`/health/alerts/${id}/acknowledge`, { version }).then((r) => r.data.data as Alert),
|
||||||
return res.data.data as Alert;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function dismissAlert(id: string, version: number) {
|
dismiss: (id: string, version: number) =>
|
||||||
const res = await client.put(`/health/alerts/${id}/dismiss`, { version });
|
client.put(`/health/alerts/${id}/dismiss`, { version }).then((r) => r.data.data as Alert),
|
||||||
return res.data.data as Alert;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function resolveAlert(id: string, version: number) {
|
resolve: (id: string, version: number) =>
|
||||||
const res = await client.put(`/health/alerts/${id}/resolve`, { version });
|
client.put(`/health/alerts/${id}/resolve`, { version }).then((r) => r.data.data as Alert),
|
||||||
return res.data.data as Alert;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// --- Alert Rule API ---
|
export const alertRuleApi = {
|
||||||
export async function listAlertRules(params?: {
|
list: (params?: { device_type?: string; page?: number; page_size?: number }) =>
|
||||||
device_type?: string;
|
client.get('/health/alert-rules', { params }).then((r) => r.data.data as PaginatedResponse<AlertRule>),
|
||||||
page?: number;
|
|
||||||
page_size?: number;
|
|
||||||
}) {
|
|
||||||
const res = await client.get('/health/alert-rules', { params });
|
|
||||||
return res.data.data as PaginatedResponse<AlertRule>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createAlertRule(data: CreateAlertRuleReq) {
|
create: (data: CreateAlertRuleReq) =>
|
||||||
const res = await client.post('/health/alert-rules', data);
|
client.post('/health/alert-rules', data).then((r) => r.data.data as AlertRule),
|
||||||
return res.data.data as AlertRule;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateAlertRule(id: string, data: UpdateAlertRuleReq) {
|
update: (id: string, data: UpdateAlertRuleReq) =>
|
||||||
const res = await client.put(`/health/alert-rules/${id}`, data);
|
client.put(`/health/alert-rules/${id}`, data).then((r) => r.data.data as AlertRule),
|
||||||
return res.data.data as AlertRule;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deactivateAlertRule(id: string, version: number) {
|
deactivate: (id: string, version: number) =>
|
||||||
const res = await client.put(`/health/alert-rules/${id}/deactivate`, { version });
|
client.put(`/health/alert-rules/${id}/deactivate`, { version }).then((r) => r.data.data as AlertRule),
|
||||||
return res.data.data as AlertRule;
|
};
|
||||||
}
|
|
||||||
|
|||||||
@@ -40,31 +40,17 @@ export interface BatchResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- API ---
|
// --- API ---
|
||||||
export async function batchCreateReadings(patientId: string, data: BatchReadingRequest) {
|
export const deviceReadingApi = {
|
||||||
const res = await client.post(`/health/patients/${patientId}/device-readings/batch`, data);
|
batchCreate: (patientId: string, data: BatchReadingRequest) =>
|
||||||
return res.data.data as BatchResult;
|
client.post(`/health/patients/${patientId}/device-readings/batch`, data).then((r) => r.data.data as BatchResult),
|
||||||
}
|
|
||||||
|
|
||||||
export async function queryReadings(params: {
|
query: (params: { patient_id: string; device_type?: string; hours?: number; page?: number; page_size?: number }) => {
|
||||||
patient_id: string;
|
const { patient_id, ...query } = params;
|
||||||
device_type?: string;
|
return client.get(`/health/patients/${patient_id}/device-readings`, { params: query }).then((r) => r.data.data as PaginatedResponse<DeviceReading>);
|
||||||
hours?: number;
|
},
|
||||||
page?: number;
|
|
||||||
page_size?: number;
|
|
||||||
}) {
|
|
||||||
const { patient_id, ...query } = params;
|
|
||||||
const res = await client.get(`/health/patients/${patient_id}/device-readings`, { params: query });
|
|
||||||
return res.data.data as PaginatedResponse<DeviceReading>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function queryHourlyReadings(params: {
|
queryHourly: (params: { patient_id: string; device_type: string; days?: number; page?: number; page_size?: number }) => {
|
||||||
patient_id: string;
|
const { patient_id, ...query } = params;
|
||||||
device_type: string;
|
return client.get(`/health/patients/${patient_id}/device-readings/hourly`, { params: query }).then((r) => r.data.data as PaginatedResponse<HourlyReading>);
|
||||||
days?: number;
|
},
|
||||||
page?: number;
|
};
|
||||||
page_size?: number;
|
|
||||||
}) {
|
|
||||||
const { patient_id, ...query } = params;
|
|
||||||
const res = await client.get(`/health/patients/${patient_id}/device-readings/hourly`, { params: query });
|
|
||||||
return res.data.data as PaginatedResponse<HourlyReading>;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ import {
|
|||||||
import { CheckOutlined, StopOutlined } from '@ant-design/icons';
|
import { CheckOutlined, StopOutlined } from '@ant-design/icons';
|
||||||
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
|
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
|
||||||
import {
|
import {
|
||||||
listAlerts,
|
alertApi,
|
||||||
acknowledgeAlert,
|
|
||||||
dismissAlert,
|
|
||||||
type Alert,
|
type Alert,
|
||||||
} from '../../api/health/alerts';
|
} from '../../api/health/alerts';
|
||||||
import { AuthButton } from '../../components/AuthButton';
|
import { AuthButton } from '../../components/AuthButton';
|
||||||
@@ -110,7 +108,7 @@ export default function AlertList() {
|
|||||||
refresh,
|
refresh,
|
||||||
} = usePaginatedData<Alert, AlertFilters>(
|
} = usePaginatedData<Alert, AlertFilters>(
|
||||||
async (p, pageSize, f) => {
|
async (p, pageSize, f) => {
|
||||||
const result = await listAlerts({
|
const result = await alertApi.list({
|
||||||
page: p,
|
page: p,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
status: f.status || undefined,
|
status: f.status || undefined,
|
||||||
@@ -146,7 +144,7 @@ export default function AlertList() {
|
|||||||
const handleAcknowledge = async (record: Alert) => {
|
const handleAcknowledge = async (record: Alert) => {
|
||||||
setActionLoading(record.id);
|
setActionLoading(record.id);
|
||||||
try {
|
try {
|
||||||
await acknowledgeAlert(record.id, record.version);
|
await alertApi.acknowledge(record.id, record.version);
|
||||||
message.success('告警已确认');
|
message.success('告警已确认');
|
||||||
refresh();
|
refresh();
|
||||||
} catch {
|
} catch {
|
||||||
@@ -159,7 +157,7 @@ export default function AlertList() {
|
|||||||
const handleDismiss = async (record: Alert) => {
|
const handleDismiss = async (record: Alert) => {
|
||||||
setActionLoading(record.id);
|
setActionLoading(record.id);
|
||||||
try {
|
try {
|
||||||
await dismissAlert(record.id, record.version);
|
await alertApi.dismiss(record.id, record.version);
|
||||||
message.success('告警已忽略');
|
message.success('告警已忽略');
|
||||||
refresh();
|
refresh();
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ import { Button, Form, Input, InputNumber, message, Modal, Select, Space, Switch
|
|||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createAlertRule,
|
alertRuleApi,
|
||||||
deactivateAlertRule,
|
|
||||||
listAlertRules,
|
|
||||||
updateAlertRule,
|
|
||||||
type AlertRule,
|
type AlertRule,
|
||||||
type CreateAlertRuleReq,
|
type CreateAlertRuleReq,
|
||||||
type UpdateAlertRuleReq,
|
type UpdateAlertRuleReq,
|
||||||
@@ -53,7 +50,7 @@ export default function AlertRuleList() {
|
|||||||
const fetchRules = useCallback(async () => {
|
const fetchRules = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await listAlertRules({ page, page_size: 20 });
|
const res = await alertRuleApi.list({ page, page_size: 20 });
|
||||||
setData(res.data);
|
setData(res.data);
|
||||||
setTotal(res.total);
|
setTotal(res.total);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -105,7 +102,7 @@ export default function AlertRuleList() {
|
|||||||
cooldown_minutes: values.cooldown_minutes,
|
cooldown_minutes: values.cooldown_minutes,
|
||||||
version: editingRule.version,
|
version: editingRule.version,
|
||||||
};
|
};
|
||||||
await updateAlertRule(editingRule.id, req);
|
await alertRuleApi.update(editingRule.id, req);
|
||||||
message.success('规则已更新');
|
message.success('规则已更新');
|
||||||
} else {
|
} else {
|
||||||
const req: CreateAlertRuleReq = {
|
const req: CreateAlertRuleReq = {
|
||||||
@@ -117,7 +114,7 @@ export default function AlertRuleList() {
|
|||||||
severity: values.severity,
|
severity: values.severity,
|
||||||
cooldown_minutes: values.cooldown_minutes,
|
cooldown_minutes: values.cooldown_minutes,
|
||||||
};
|
};
|
||||||
await createAlertRule(req);
|
await alertRuleApi.create(req);
|
||||||
message.success('规则已创建');
|
message.success('规则已创建');
|
||||||
}
|
}
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
@@ -132,7 +129,7 @@ export default function AlertRuleList() {
|
|||||||
const handleToggle = async (rule: AlertRule, active: boolean) => {
|
const handleToggle = async (rule: AlertRule, active: boolean) => {
|
||||||
try {
|
try {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
await deactivateAlertRule(rule.id, rule.version);
|
await alertRuleApi.deactivate(rule.id, rule.version);
|
||||||
message.success('规则已禁用');
|
message.success('规则已禁用');
|
||||||
}
|
}
|
||||||
fetchRules();
|
fetchRules();
|
||||||
|
|||||||
Reference in New Issue
Block a user