diff --git a/apps/web-antd/src/views/aiot/device/camera/index.vue b/apps/web-antd/src/views/aiot/device/camera/index.vue index e1b967f6f..c42f2055d 100644 --- a/apps/web-antd/src/views/aiot/device/camera/index.vue +++ b/apps/web-antd/src/views/aiot/device/camera/index.vue @@ -7,7 +7,7 @@ */ import type { AiotDeviceApi } from '#/api/aiot/device'; -import { onMounted, reactive, ref } from 'vue'; +import { onMounted, reactive, ref, watch } from 'vue'; import { useRouter } from 'vue-router'; import { Page } from '@vben/common-ui'; @@ -157,11 +157,45 @@ function resetForm() { }); } +/** + * 自动填充流ID编号 + * 根据当前应用名,自动计算下一个可用的编号 + */ +function autoFillStreamId() { + const app = editForm.app; + if (!app || editForm.id) return; // 编辑模式不自动填充 + + // 过滤出同一应用下的摄像头 + const sameAppCameras = cameraList.value.filter((c) => c.app === app); + + // 获取已用的纯数字编号 + const usedNumbers = sameAppCameras + .map((c) => c.stream) + .filter((s) => /^\d+$/.test(s)) + .map((s) => parseInt(s, 10)) + .sort((a, b) => a - b); + + // 找到第一个未使用的编号 + let nextNum = 1; + for (const num of usedNumbers) { + if (num === nextNum) { + nextNum++; + } else { + break; + } + } + + // 自动填充(3位数字,前导零) + editForm.stream = String(nextNum).padStart(3, '0'); +} + function handleAdd() { resetForm(); editModalTitle.value = '添加摄像头'; editModalOpen.value = true; loadMediaServers(); + // 自动填充流ID + autoFillStreamId(); } function handleEdit(row: AiotDeviceApi.Camera) { @@ -311,6 +345,14 @@ function handlePageChange(p: number, size: number) { // ==================== 初始化 ==================== +// 监听应用名变化,自动填充流ID +watch( + () => editForm.app, + () => { + autoFillStreamId(); + }, +); + onMounted(() => { loadData(); }); @@ -446,16 +488,22 @@ onMounted(() => {