Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 717832aa4f | |||
| e0983a693a | |||
| 6eea4e81cd | |||
| a82ccbd145 |
@@ -86,6 +86,7 @@ export namespace AiotDeviceApi {
|
|||||||
description?: string;
|
description?: string;
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
paramSchema?: string;
|
paramSchema?: string;
|
||||||
|
globalParams?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 媒体服务器 */
|
/** 媒体服务器 */
|
||||||
@@ -231,9 +232,26 @@ export async function getSnapUrl(cameraCode: string, force = false): Promise<str
|
|||||||
// ==================== 算法管理 ====================
|
// ==================== 算法管理 ====================
|
||||||
|
|
||||||
/** 算法列表 */
|
/** 算法列表 */
|
||||||
export function getAlgorithmList() {
|
export function getAlgorithmList(deviceId?: string) {
|
||||||
return wvpRequestClient.get<AiotDeviceApi.Algorithm[]>(
|
return wvpRequestClient.get<AiotDeviceApi.Algorithm[]>(
|
||||||
'/aiot/device/algorithm/list',
|
'/aiot/device/algorithm/list',
|
||||||
|
{ params: deviceId ? { deviceId } : {} },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 保存算法全局参数 */
|
||||||
|
export function saveAlgoGlobalParams(algoCode: string, globalParams: string) {
|
||||||
|
return wvpRequestClient.post(
|
||||||
|
`/aiot/device/algorithm/global-params/${algoCode}`,
|
||||||
|
{ globalParams },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量更新设备算法参数 */
|
||||||
|
export function updateDeviceAlgoParams(deviceId: string, algoCode: string, params: string) {
|
||||||
|
return wvpRequestClient.post(
|
||||||
|
`/aiot/device/algorithm/device-binds/${deviceId}/${algoCode}`,
|
||||||
|
{ params },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const ALERT_TYPE_OPTIONS = [
|
|||||||
{ label: '周界入侵', value: 'intrusion' },
|
{ label: '周界入侵', value: 'intrusion' },
|
||||||
{ label: '车辆违停', value: 'illegal_parking' },
|
{ label: '车辆违停', value: 'illegal_parking' },
|
||||||
{ label: '车辆拥堵', value: 'vehicle_congestion' },
|
{ label: '车辆拥堵', value: 'vehicle_congestion' },
|
||||||
|
{ label: '非机动车违停', value: 'non_motor_vehicle_parking' },
|
||||||
];
|
];
|
||||||
|
|
||||||
/** 告警状态选项 */
|
/** 告警状态选项 */
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ function getAlertTypeColor(type?: string) {
|
|||||||
fire_detection: 'volcano',
|
fire_detection: 'volcano',
|
||||||
smoke_detection: 'magenta',
|
smoke_detection: 'magenta',
|
||||||
fall_detection: 'cyan',
|
fall_detection: 'cyan',
|
||||||
|
illegal_parking: 'blue',
|
||||||
|
vehicle_congestion: 'geekblue',
|
||||||
|
non_motor_vehicle_parking: 'green',
|
||||||
};
|
};
|
||||||
return type ? colorMap[type] || 'default' : 'default';
|
return type ? colorMap[type] || 'default' : 'default';
|
||||||
}
|
}
|
||||||
@@ -301,14 +304,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
type: 'link',
|
type: 'link',
|
||||||
icon: ACTION_ICON.EDIT,
|
icon: ACTION_ICON.EDIT,
|
||||||
onClick: openHandleModal.bind(null, row),
|
onClick: openHandleModal.bind(null, row),
|
||||||
ifShow: row.status === 'pending',
|
ifShow: row.status === 'pending' || row.status === 'processing',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '误报',
|
label: '误报',
|
||||||
type: 'link',
|
type: 'link',
|
||||||
danger: true,
|
danger: true,
|
||||||
onClick: handleFalseAlarm.bind(null, row),
|
onClick: handleFalseAlarm.bind(null, row),
|
||||||
ifShow: row.status === 'pending',
|
ifShow: row.status === 'pending' || row.status === 'processing',
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
|
|||||||
524
apps/web-antd/src/views/aiot/device/algorithm/index.vue
Normal file
524
apps/web-antd/src/views/aiot/device/algorithm/index.vue
Normal file
@@ -0,0 +1,524 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { AiotDeviceApi } from '#/api/aiot/device';
|
||||||
|
import type { AiotEdgeApi } from '#/api/aiot/edge';
|
||||||
|
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Form,
|
||||||
|
InputNumber,
|
||||||
|
message,
|
||||||
|
Select,
|
||||||
|
SelectOption,
|
||||||
|
Spin,
|
||||||
|
Tabs,
|
||||||
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getAlgorithmList,
|
||||||
|
saveAlgoGlobalParams,
|
||||||
|
updateDeviceAlgoParams,
|
||||||
|
} from '#/api/aiot/device';
|
||||||
|
import { getDeviceList } from '#/api/aiot/edge';
|
||||||
|
|
||||||
|
// 参数名中英文映射(与 AlgorithmParamEditor 保持一致)
|
||||||
|
const paramNameMap: Record<string, string> = {
|
||||||
|
leave_countdown_sec: '离岗倒计时(秒)',
|
||||||
|
working_hours: '工作时间段',
|
||||||
|
cooldown_seconds: '告警冷却期(秒)',
|
||||||
|
confirm_seconds: '确认时间(秒)',
|
||||||
|
confirm_intrusion_seconds: '入侵确认时间(秒)',
|
||||||
|
confirm_clear_seconds: '消失确认时间(秒)',
|
||||||
|
min_confidence: '最小置信度',
|
||||||
|
max_targets: '最大目标数',
|
||||||
|
detection_interval: '检测间隔(秒)',
|
||||||
|
enable_tracking: '启用跟踪',
|
||||||
|
tracking_timeout: '跟踪超时(秒)',
|
||||||
|
confirm_vehicle_sec: '车辆确认时间(秒)',
|
||||||
|
parking_countdown_sec: '违停倒计时(秒)',
|
||||||
|
confirm_clear_sec: '消失确认时间(秒)',
|
||||||
|
cooldown_sec: '告警冷却期(秒)',
|
||||||
|
count_threshold: '车辆数量阈值',
|
||||||
|
confirm_congestion_sec: '拥堵确认时间(秒)',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 参数说明映射
|
||||||
|
const paramDescMap: Record<string, string> = {
|
||||||
|
leave_countdown_sec: '人员离开后,倒计时多少秒才触发离岗告警',
|
||||||
|
working_hours: '仅在指定时间段内进行监控,留空表示24小时监控',
|
||||||
|
cooldown_seconds: '触发告警后,多少秒内不再重复告警(用于周界入侵等算法)',
|
||||||
|
confirm_seconds: '持续检测到人达到该时间后触发告警',
|
||||||
|
confirm_intrusion_seconds: '入侵确认:持续检测到人达到该时间后触发告警',
|
||||||
|
confirm_clear_seconds: '消失确认:持续无人达到该时间后自动结束告警',
|
||||||
|
confirm_vehicle_sec: '确认车辆停留的时间,超过该时间开始违停倒计时',
|
||||||
|
parking_countdown_sec: '确认有车后的违停等待时间,超过该时间触发违停告警',
|
||||||
|
confirm_clear_sec: '车辆离开后,持续无车达到该时间后自动结束告警',
|
||||||
|
cooldown_sec: '触发告警后,多少秒内不再重复告警',
|
||||||
|
count_threshold: '区域内车辆数量达到该值时判定为拥堵',
|
||||||
|
confirm_congestion_sec: '车辆数持续超过阈值达到该时间后触发拥堵告警',
|
||||||
|
};
|
||||||
|
|
||||||
|
// ==================== 设备选择器 ====================
|
||||||
|
const selectedDeviceId = ref<string>('');
|
||||||
|
const deviceList = ref<AiotEdgeApi.Device[]>([]);
|
||||||
|
|
||||||
|
const isDeviceMode = computed(() => selectedDeviceId.value !== '');
|
||||||
|
|
||||||
|
const saveButtonText = computed(() => {
|
||||||
|
if (!isDeviceMode.value) return '保存全局默认';
|
||||||
|
const device = deviceList.value.find(
|
||||||
|
(d) => d.deviceId === selectedDeviceId.value,
|
||||||
|
);
|
||||||
|
const name = device?.deviceName || device?.deviceId || selectedDeviceId.value;
|
||||||
|
return `保存到 ${name}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// ==================== 算法数据 ====================
|
||||||
|
const algorithms = ref<AiotDeviceApi.Algorithm[]>([]);
|
||||||
|
const activeTab = ref<string>('');
|
||||||
|
const loading = ref(false);
|
||||||
|
const saving = ref(false);
|
||||||
|
|
||||||
|
// 每个算法的表单数据: { algoCode: { paramKey: value } }
|
||||||
|
const formDataMap = ref<Record<string, Record<string, any>>>({});
|
||||||
|
// 记录用户修改过的字段
|
||||||
|
const dirtyFieldsMap = ref<Record<string, Set<string>>>({});
|
||||||
|
// 设备模式下缓存的全局默认参数: { algoCode: { paramKey: value } }
|
||||||
|
const originalGlobalParamsMap = ref<Record<string, Record<string, any>>>({});
|
||||||
|
// 防竞态:loadAlgorithms 请求版本计数器
|
||||||
|
let loadRequestId = 0;
|
||||||
|
|
||||||
|
const currentAlgo = computed(() => {
|
||||||
|
return algorithms.value.find((a) => a.algoCode === activeTab.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentSchema = computed(() => {
|
||||||
|
const algo = currentAlgo.value;
|
||||||
|
if (!algo?.paramSchema) return {};
|
||||||
|
try {
|
||||||
|
return JSON.parse(algo.paramSchema);
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentFormData = computed(() => {
|
||||||
|
return formDataMap.value[activeTab.value] || {};
|
||||||
|
});
|
||||||
|
|
||||||
|
function getParamLabel(key: string): string {
|
||||||
|
return paramNameMap[key] || key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getParamDesc(key: string): string | undefined {
|
||||||
|
return paramDescMap[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await Promise.all([loadDevices(), loadAlgorithms()]);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadDevices() {
|
||||||
|
try {
|
||||||
|
const list = await getDeviceList();
|
||||||
|
deviceList.value = Array.isArray(list) ? list : [];
|
||||||
|
} catch {
|
||||||
|
deviceList.value = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onDeviceChange() {
|
||||||
|
await loadAlgorithms();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadAlgorithms() {
|
||||||
|
loading.value = true;
|
||||||
|
const currentRequestId = ++loadRequestId;
|
||||||
|
try {
|
||||||
|
// 设备模式下,先请求全局默认参数作为比较基准
|
||||||
|
if (isDeviceMode.value) {
|
||||||
|
try {
|
||||||
|
const globalData = await getAlgorithmList(undefined);
|
||||||
|
if (currentRequestId !== loadRequestId) return;
|
||||||
|
if (Array.isArray(globalData)) {
|
||||||
|
for (const algo of globalData) {
|
||||||
|
try {
|
||||||
|
const gp = JSON.parse(algo.globalParams || '{}');
|
||||||
|
const schema = JSON.parse(algo.paramSchema || '{}');
|
||||||
|
const baseline: Record<string, any> = {};
|
||||||
|
for (const k of Object.keys(schema)) {
|
||||||
|
baseline[k] = gp[k] !== undefined ? gp[k] : schema[k]?.default;
|
||||||
|
}
|
||||||
|
originalGlobalParamsMap.value[algo.algoCode] = baseline;
|
||||||
|
} catch { /* empty */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { /* empty */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
const deviceId = selectedDeviceId.value || undefined;
|
||||||
|
const data = await getAlgorithmList(deviceId);
|
||||||
|
|
||||||
|
// 防竞态:请求期间设备已切换,丢弃本次响应
|
||||||
|
if (currentRequestId !== loadRequestId) return;
|
||||||
|
|
||||||
|
algorithms.value = Array.isArray(data) ? data : [];
|
||||||
|
if (algorithms.value.length > 0) {
|
||||||
|
// 保持当前 tab,如果不存在则切到第一个
|
||||||
|
const codes = algorithms.value.map((a) => a.algoCode);
|
||||||
|
if (!codes.includes(activeTab.value)) {
|
||||||
|
activeTab.value = algorithms.value[0]!.algoCode || '';
|
||||||
|
}
|
||||||
|
// 初始化所有算法的表单数据
|
||||||
|
for (const algo of algorithms.value) {
|
||||||
|
initFormData(algo);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
activeTab.value = '';
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
if (currentRequestId === loadRequestId) {
|
||||||
|
message.error('加载算法列表失败');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (currentRequestId === loadRequestId) {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initFormData(algo: AiotDeviceApi.Algorithm) {
|
||||||
|
const code = algo.algoCode || '';
|
||||||
|
let schema: Record<string, any> = {};
|
||||||
|
let globalParams: Record<string, any> = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
schema = JSON.parse(algo.paramSchema || '{}');
|
||||||
|
} catch { /* empty */ }
|
||||||
|
try {
|
||||||
|
globalParams = JSON.parse(algo.globalParams || '{}');
|
||||||
|
} catch { /* empty */ }
|
||||||
|
|
||||||
|
const form: Record<string, any> = {};
|
||||||
|
for (const key of Object.keys(schema)) {
|
||||||
|
// 优先用已保存的 globalParams 值,否则用 schema default
|
||||||
|
if (globalParams[key] !== undefined) {
|
||||||
|
form[key] = globalParams[key];
|
||||||
|
} else {
|
||||||
|
form[key] = schema[key]?.type === 'list'
|
||||||
|
? (schema[key]?.default || [])
|
||||||
|
: schema[key]?.default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formDataMap.value[code] = form;
|
||||||
|
dirtyFieldsMap.value[code] = new Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFieldChange(key: string) {
|
||||||
|
const code = activeTab.value;
|
||||||
|
if (!dirtyFieldsMap.value[code]) {
|
||||||
|
dirtyFieldsMap.value[code] = new Set();
|
||||||
|
}
|
||||||
|
dirtyFieldsMap.value[code]!.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSchemaDefault(key: string): any {
|
||||||
|
return currentSchema.value[key]?.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取比较基准值:设备模式用全局默认,全局模式用 schema default */
|
||||||
|
function getBaselineValue(key: string): any {
|
||||||
|
if (isDeviceMode.value) {
|
||||||
|
const algo = currentAlgo.value;
|
||||||
|
if (algo) {
|
||||||
|
const ogp = originalGlobalParamsMap.value[algo.algoCode];
|
||||||
|
if (ogp && ogp[key] !== undefined) return ogp[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getSchemaDefault(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isModified(key: string): boolean {
|
||||||
|
return currentFormData.value[key] !== getBaselineValue(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSave() {
|
||||||
|
const algo = currentAlgo.value;
|
||||||
|
if (!algo?.algoCode) return;
|
||||||
|
|
||||||
|
saving.value = true;
|
||||||
|
try {
|
||||||
|
const form = currentFormData.value;
|
||||||
|
const schema = currentSchema.value;
|
||||||
|
|
||||||
|
// 只保存与基准值不同的字段(设备模式对比全局默认,全局模式对比 schema default)
|
||||||
|
const toSave: Record<string, any> = {};
|
||||||
|
for (const key of Object.keys(schema)) {
|
||||||
|
const baselineVal = getBaselineValue(key);
|
||||||
|
if (form[key] !== baselineVal) {
|
||||||
|
toSave[key] = form[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDeviceMode.value) {
|
||||||
|
// 设备模式:保存到设备绑定
|
||||||
|
await updateDeviceAlgoParams(
|
||||||
|
selectedDeviceId.value,
|
||||||
|
algo.algoCode,
|
||||||
|
JSON.stringify(toSave),
|
||||||
|
);
|
||||||
|
message.success('设备参数保存成功');
|
||||||
|
} else {
|
||||||
|
// 全局模式:保存全局参数
|
||||||
|
await saveAlgoGlobalParams(algo.algoCode, JSON.stringify(toSave));
|
||||||
|
message.success('全局参数保存成功');
|
||||||
|
}
|
||||||
|
// 更新本地算法数据
|
||||||
|
algo.globalParams = JSON.stringify(toSave);
|
||||||
|
dirtyFieldsMap.value[algo.algoCode] = new Set();
|
||||||
|
} catch (err: any) {
|
||||||
|
const errorMsg =
|
||||||
|
err?.response?.data?.msg ||
|
||||||
|
err?.response?.data?.message ||
|
||||||
|
err?.message ||
|
||||||
|
'保存失败';
|
||||||
|
message.error(errorMsg);
|
||||||
|
} finally {
|
||||||
|
saving.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetToDefault(key: string) {
|
||||||
|
const code = activeTab.value;
|
||||||
|
const baselineVal = getBaselineValue(key);
|
||||||
|
if (formDataMap.value[code]) {
|
||||||
|
formDataMap.value[code]![key] = baselineVal;
|
||||||
|
onFieldChange(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 判断字段是否为不适合在全局配置中编辑的类型 */
|
||||||
|
function isSkippedField(key: string, schema: any): boolean {
|
||||||
|
// working_hours 和 list 类型在全局配置中跳过(场景差异大,不适合全局设置)
|
||||||
|
return key === 'working_hours' || schema.type === 'list';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="algo-global-config">
|
||||||
|
<Card title="算法参数配置">
|
||||||
|
<template #extra>
|
||||||
|
<div class="card-extra">
|
||||||
|
<Select
|
||||||
|
v-model:value="selectedDeviceId"
|
||||||
|
style="width: 240px"
|
||||||
|
placeholder="选择设备"
|
||||||
|
@change="onDeviceChange"
|
||||||
|
>
|
||||||
|
<SelectOption value="">全局默认</SelectOption>
|
||||||
|
<SelectOption
|
||||||
|
v-for="d in deviceList"
|
||||||
|
:key="d.deviceId"
|
||||||
|
:value="d.deviceId"
|
||||||
|
>
|
||||||
|
{{ d.deviceName || d.deviceId }}
|
||||||
|
</SelectOption>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<Spin :spinning="loading">
|
||||||
|
<div v-if="algorithms.length === 0 && !loading" class="empty-state">
|
||||||
|
暂无可用算法
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Tabs
|
||||||
|
v-if="algorithms.length > 0"
|
||||||
|
v-model:activeKey="activeTab"
|
||||||
|
type="card"
|
||||||
|
>
|
||||||
|
<Tabs.TabPane
|
||||||
|
v-for="algo in algorithms"
|
||||||
|
:key="algo.algoCode"
|
||||||
|
:tab="algo.algoName || algo.algoCode"
|
||||||
|
>
|
||||||
|
<div class="algo-desc" v-if="algo.description">
|
||||||
|
{{ algo.description }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
layout="horizontal"
|
||||||
|
:label-col="{ span: 6 }"
|
||||||
|
:wrapper-col="{ span: 14 }"
|
||||||
|
class="param-form"
|
||||||
|
>
|
||||||
|
<template
|
||||||
|
v-for="(schema, key) in currentSchema"
|
||||||
|
:key="key"
|
||||||
|
>
|
||||||
|
<Form.Item
|
||||||
|
v-if="!isSkippedField(String(key), schema)"
|
||||||
|
:label="getParamLabel(String(key))"
|
||||||
|
>
|
||||||
|
<!-- 整数类型 -->
|
||||||
|
<template v-if="schema.type === 'int'">
|
||||||
|
<div class="field-row">
|
||||||
|
<InputNumber
|
||||||
|
v-model:value="currentFormData[String(key)]"
|
||||||
|
:min="schema.min"
|
||||||
|
:placeholder="`默认: ${schema.default}`"
|
||||||
|
style="width: 200px"
|
||||||
|
@change="onFieldChange(String(key))"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
v-if="isModified(String(key))"
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
@click="resetToDefault(String(key))"
|
||||||
|
>
|
||||||
|
恢复默认
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div v-if="getParamDesc(String(key))" class="param-desc">
|
||||||
|
{{ getParamDesc(String(key)) }}
|
||||||
|
</div>
|
||||||
|
<div class="schema-default">
|
||||||
|
Schema 默认值: {{ schema.default }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 浮点数类型 -->
|
||||||
|
<template v-else-if="schema.type === 'float'">
|
||||||
|
<div class="field-row">
|
||||||
|
<InputNumber
|
||||||
|
v-model:value="currentFormData[String(key)]"
|
||||||
|
:min="schema.min"
|
||||||
|
:max="schema.max"
|
||||||
|
:step="0.01"
|
||||||
|
:placeholder="`默认: ${schema.default}`"
|
||||||
|
style="width: 200px"
|
||||||
|
@change="onFieldChange(String(key))"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
v-if="isModified(String(key))"
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
@click="resetToDefault(String(key))"
|
||||||
|
>
|
||||||
|
恢复默认
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div v-if="getParamDesc(String(key))" class="param-desc">
|
||||||
|
{{ getParamDesc(String(key)) }}
|
||||||
|
</div>
|
||||||
|
<div class="schema-default">
|
||||||
|
Schema 默认值: {{ schema.default }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Form.Item>
|
||||||
|
</template>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<div class="form-footer">
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
:loading="saving"
|
||||||
|
@click="handleSave"
|
||||||
|
>
|
||||||
|
{{ saveButtonText }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Tabs.TabPane>
|
||||||
|
</Tabs>
|
||||||
|
</Spin>
|
||||||
|
|
||||||
|
<!-- 帮助说明 -->
|
||||||
|
<div class="help-tip">
|
||||||
|
<span class="help-text">
|
||||||
|
<template v-if="isDeviceMode">
|
||||||
|
当前查看的是该设备各 ROI 绑定的实际参数。修改后将更新该设备所有 ROI 绑定中对应算法的参数,需重新推送配置到边缘端才能生效。
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
全局参数为各算法的默认配置,当 ROI 绑定算法时未单独设置参数,将使用此处的全局默认值。修改后需重新推送配置到边缘端才能生效。
|
||||||
|
</template>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.algo-global-config {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-extra {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px 0;
|
||||||
|
color: #999;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.algo-desc {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
background: #fafafa;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.param-form {
|
||||||
|
max-width: 700px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.param-desc {
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #8c8c8c;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.schema-default {
|
||||||
|
margin-top: 2px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: #bfbfbf;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-footer {
|
||||||
|
margin-top: 24px;
|
||||||
|
padding-top: 16px;
|
||||||
|
border-top: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.help-tip {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 12px;
|
||||||
|
background: #e6f4ff;
|
||||||
|
border: 1px solid #91caff;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #0958d9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.help-text {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -22,6 +22,7 @@ interface Props {
|
|||||||
bindId: string;
|
bindId: string;
|
||||||
priority?: number;
|
priority?: number;
|
||||||
enabled?: number;
|
enabled?: number;
|
||||||
|
globalParams?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
@@ -31,6 +32,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
bindId: '',
|
bindId: '',
|
||||||
priority: 0,
|
priority: 0,
|
||||||
enabled: 1,
|
enabled: 1,
|
||||||
|
globalParams: '{}',
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -94,6 +96,33 @@ function getParamDesc(key: string): string | undefined {
|
|||||||
return paramDescMap[key];
|
return paramDescMap[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解析全局参数
|
||||||
|
const parsedGlobalParams = computed(() => {
|
||||||
|
try {
|
||||||
|
return JSON.parse(props.globalParams);
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取全局默认值(如果有)
|
||||||
|
function getGlobalDefault(key: string): any {
|
||||||
|
return parsedGlobalParams.value[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否有全局默认值
|
||||||
|
function hasGlobalDefault(key: string): boolean {
|
||||||
|
return parsedGlobalParams.value[key] !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置为全局默认值
|
||||||
|
function resetToGlobalDefault(key: string) {
|
||||||
|
const globalVal = getGlobalDefault(key);
|
||||||
|
if (globalVal !== undefined) {
|
||||||
|
formData.value[key] = globalVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const parsedSchema = computed(() => {
|
const parsedSchema = computed(() => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(props.paramSchema);
|
return JSON.parse(props.paramSchema);
|
||||||
@@ -283,6 +312,17 @@ function validateParams(params: Record<string, any>): {
|
|||||||
<div v-if="getParamDesc(String(key))" class="param-desc">
|
<div v-if="getParamDesc(String(key))" class="param-desc">
|
||||||
{{ getParamDesc(String(key)) }}
|
{{ getParamDesc(String(key)) }}
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="hasGlobalDefault(String(key))" class="global-default-hint">
|
||||||
|
<span>全局默认: {{ getGlobalDefault(String(key)) }}</span>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
class="reset-btn"
|
||||||
|
@click="resetToGlobalDefault(String(key))"
|
||||||
|
>
|
||||||
|
重置为全局默认
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- 工作时间段(特殊处理) -->
|
<!-- 工作时间段(特殊处理) -->
|
||||||
@@ -325,11 +365,23 @@ function validateParams(params: Record<string, any>): {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 字符串类型 -->
|
<!-- 字符串类型 -->
|
||||||
<Input
|
<template v-else>
|
||||||
v-else
|
<Input
|
||||||
v-model:value="formData[String(key)]"
|
v-model:value="formData[String(key)]"
|
||||||
:placeholder="`默认: ${schema.default}`"
|
:placeholder="`默认: ${schema.default}`"
|
||||||
/>
|
/>
|
||||||
|
<div v-if="hasGlobalDefault(String(key))" class="global-default-hint">
|
||||||
|
<span>全局默认: {{ getGlobalDefault(String(key)) }}</span>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
class="reset-btn"
|
||||||
|
@click="resetToGlobalDefault(String(key))"
|
||||||
|
>
|
||||||
|
重置为全局默认
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
@@ -371,4 +423,20 @@ function validateParams(params: Record<string, any>): {
|
|||||||
color: #8c8c8c;
|
color: #8c8c8c;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.global-default-hint {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
margin-top: 2px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #bfbfbf;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reset-btn {
|
||||||
|
padding: 0 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
height: auto;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ const currentParams = ref('{}');
|
|||||||
const currentBindId = ref('');
|
const currentBindId = ref('');
|
||||||
const currentPriority = ref(0);
|
const currentPriority = ref(0);
|
||||||
const currentEnabled = ref(1);
|
const currentEnabled = ref(1);
|
||||||
|
const currentGlobalParams = ref('{}');
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.roiId,
|
() => props.roiId,
|
||||||
@@ -128,6 +129,11 @@ function openParamEditor(item: AiotDeviceApi.RoiAlgoBinding) {
|
|||||||
currentParamSchema.value = item.algorithm?.paramSchema || '{}';
|
currentParamSchema.value = item.algorithm?.paramSchema || '{}';
|
||||||
currentPriority.value = item.bind.priority ?? 0;
|
currentPriority.value = item.bind.priority ?? 0;
|
||||||
currentEnabled.value = item.bind.enabled ?? 1;
|
currentEnabled.value = item.bind.enabled ?? 1;
|
||||||
|
// 查找该算法的全局参数
|
||||||
|
const algo = availableAlgorithms.value.find(
|
||||||
|
(a) => a.algoCode === item.bind.algoCode,
|
||||||
|
);
|
||||||
|
currentGlobalParams.value = algo?.globalParams || '{}';
|
||||||
paramEditorOpen.value = true;
|
paramEditorOpen.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,6 +313,7 @@ async function onAlarmLevelChange(item: AiotDeviceApi.RoiAlgoBinding, level: num
|
|||||||
:bind-id="currentBindId"
|
:bind-id="currentBindId"
|
||||||
:priority="currentPriority"
|
:priority="currentPriority"
|
||||||
:enabled="currentEnabled"
|
:enabled="currentEnabled"
|
||||||
|
:global-params="currentGlobalParams"
|
||||||
@saved="onParamSaved"
|
@saved="onParamSaved"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user