diff --git a/apps/web-antd/src/views/aiot/device/roi/components/RoiAlgorithmBind.vue b/apps/web-antd/src/views/aiot/device/roi/components/RoiAlgorithmBind.vue index f2d382322..85abb9b9f 100644 --- a/apps/web-antd/src/views/aiot/device/roi/components/RoiAlgorithmBind.vue +++ b/apps/web-antd/src/views/aiot/device/roi/components/RoiAlgorithmBind.vue @@ -22,6 +22,22 @@ import { import AlgorithmParamEditor from './AlgorithmParamEditor.vue'; +/** 告警等级选项 */ +const ALARM_LEVEL_OPTIONS = [ + { value: 0, label: '紧急', color: '#f5222d' }, + { value: 1, label: '重要', color: '#fa8c16' }, + { value: 2, label: '普通', color: '#1677ff' }, + { value: 3, label: '轻微', color: '#8c8c8c' }, +]; + +/** 算法默认告警等级 */ +const DEFAULT_ALARM_LEVELS: Record = { + intrusion: 1, + leave_post: 2, + illegal_parking: 1, + vehicle_congestion: 2, +}; + interface Props { roiId: string; bindings: AiotDeviceApi.RoiAlgoBinding[]; @@ -141,6 +157,35 @@ function getAlgoFrameRate(algoCode: string): string { }; return frameRates[algoCode] || '5帧/秒'; } + +/** 从 params JSON 中读取告警等级 */ +function getAlarmLevel(item: AiotDeviceApi.RoiAlgoBinding): number { + try { + const params = JSON.parse(item.bind.params || '{}'); + if (params.alarm_level !== undefined) return params.alarm_level; + } catch { /* empty */ } + return DEFAULT_ALARM_LEVELS[item.bind.algoCode || ''] ?? 2; +} + +/** 修改告警等级 */ +async function onAlarmLevelChange(item: AiotDeviceApi.RoiAlgoBinding, level: number) { + try { + let params: Record = {}; + try { + params = JSON.parse(item.bind.params || '{}'); + } catch { /* empty */ } + params.alarm_level = level; + await updateAlgoParams({ + bindId: item.bind.bindId!, + params: JSON.stringify(params), + }); + // 更新本地数据 + item.bind.params = JSON.stringify(params); + message.success('告警等级已更新'); + } catch { + message.error('更新告警等级失败'); + } +}