功能:算法绑定页增加告警等级选择器
支持在 ROI 算法绑定中配置告警等级(紧急/重要/普通/轻微), 等级保存在 params JSON 中,各算法有默认等级。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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<string, number> = {
|
||||
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<string, any> = {};
|
||||
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('更新告警等级失败');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -194,9 +239,22 @@ function getAlgoFrameRate(algoCode: string): string {
|
||||
<Tag color="green" style="font-size: 11px">
|
||||
{{ getAlgoFrameRate(item.bind.algoCode) }}
|
||||
</Tag>
|
||||
<span style="color: #999; font-size: 12px">
|
||||
{{ item.bind.algoCode }}
|
||||
</span>
|
||||
<Select
|
||||
:value="getAlarmLevel(item)"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
@change="(val: any) => onAlarmLevelChange(item, val as number)"
|
||||
>
|
||||
<Select.Option
|
||||
v-for="opt in ALARM_LEVEL_OPTIONS"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
<span :style="{ color: opt.color, fontWeight: 500 }">
|
||||
{{ opt.label }}
|
||||
</span>
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</div>
|
||||
<div style="display: flex; align-items: center; gap: 8px">
|
||||
<Switch
|
||||
|
||||
Reference in New Issue
Block a user