refactor(web): alerts + deviceReadings API 迁移为对象风格导出
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

- alerts.ts: listAlerts → alertApi.list, acknowledgeAlert → alertApi.acknowledge 等
- deviceReadings.ts: batchCreateReadings → deviceReadingApi.batchCreate 等
- AlertList/AlertRuleList 引用处同步更新
- 其余 19 个函数式 API 文件记为待迁移(旧文件不强制迁移)
This commit is contained in:
iven
2026-04-28 19:47:48 +08:00
parent 99093d8143
commit e5546efa41
4 changed files with 42 additions and 83 deletions

View File

@@ -14,9 +14,7 @@ import {
import { CheckOutlined, StopOutlined } from '@ant-design/icons';
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
import {
listAlerts,
acknowledgeAlert,
dismissAlert,
alertApi,
type Alert,
} from '../../api/health/alerts';
import { AuthButton } from '../../components/AuthButton';
@@ -110,7 +108,7 @@ export default function AlertList() {
refresh,
} = usePaginatedData<Alert, AlertFilters>(
async (p, pageSize, f) => {
const result = await listAlerts({
const result = await alertApi.list({
page: p,
page_size: pageSize,
status: f.status || undefined,
@@ -146,7 +144,7 @@ export default function AlertList() {
const handleAcknowledge = async (record: Alert) => {
setActionLoading(record.id);
try {
await acknowledgeAlert(record.id, record.version);
await alertApi.acknowledge(record.id, record.version);
message.success('告警已确认');
refresh();
} catch {
@@ -159,7 +157,7 @@ export default function AlertList() {
const handleDismiss = async (record: Alert) => {
setActionLoading(record.id);
try {
await dismissAlert(record.id, record.version);
await alertApi.dismiss(record.id, record.version);
message.success('告警已忽略');
refresh();
} catch {

View File

@@ -3,10 +3,7 @@ import { Button, Form, Input, InputNumber, message, Modal, Select, Space, Switch
import type { ColumnsType } from 'antd/es/table';
import {
createAlertRule,
deactivateAlertRule,
listAlertRules,
updateAlertRule,
alertRuleApi,
type AlertRule,
type CreateAlertRuleReq,
type UpdateAlertRuleReq,
@@ -53,7 +50,7 @@ export default function AlertRuleList() {
const fetchRules = useCallback(async () => {
setLoading(true);
try {
const res = await listAlertRules({ page, page_size: 20 });
const res = await alertRuleApi.list({ page, page_size: 20 });
setData(res.data);
setTotal(res.total);
} catch {
@@ -105,7 +102,7 @@ export default function AlertRuleList() {
cooldown_minutes: values.cooldown_minutes,
version: editingRule.version,
};
await updateAlertRule(editingRule.id, req);
await alertRuleApi.update(editingRule.id, req);
message.success('规则已更新');
} else {
const req: CreateAlertRuleReq = {
@@ -117,7 +114,7 @@ export default function AlertRuleList() {
severity: values.severity,
cooldown_minutes: values.cooldown_minutes,
};
await createAlertRule(req);
await alertRuleApi.create(req);
message.success('规则已创建');
}
setModalOpen(false);
@@ -132,7 +129,7 @@ export default function AlertRuleList() {
const handleToggle = async (rule: AlertRule, active: boolean) => {
try {
if (!active) {
await deactivateAlertRule(rule.id, rule.version);
await alertRuleApi.deactivate(rule.id, rule.version);
message.success('规则已禁用');
}
fetchRules();