From 46c7d4f359783f70f4e18a61d21ab00728a0105b Mon Sep 17 00:00:00 2001 From: liufumingren Date: Wed, 21 Oct 2026 14:39:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=89=E5=8F=96=E9=80=9A=E9=81=93=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=EF=BC=9A=E4=B8=80=E9=80=9A=E9=81=93=E4=B8=80=E8=A1=8C?= =?UTF-8?q?=20+=20=E6=89=93=E5=BC=80=E5=8D=B3=E6=8B=89=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 通道列表由三列网格改为单列(一行一个):通道号 / 通道名 / IP:端口 都完整显示, 名字不再被 120px 的 max-width 截断(名字与地址都补了 title,窄窗时仍可悬停看全) - 点表格里的「拉取通道」直接拉取:并行取「已导入通道 + 库里存的设备密码」, 拿到密码立刻 pull 一次,不用再点第二次按钮;弹窗里的按钮改为「重新拉取」(换密码用) - 没有存密码时给出提示并自动聚焦密码框,回车即拉 - 拉取中/关闭弹窗/切换 NVR 都有保护,不会把旧结果写进新窗口 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- frontend/src/views/NvrsView.vue | 90 ++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/frontend/src/views/NvrsView.vue b/frontend/src/views/NvrsView.vue index 4045b2e..edb82ce 100644 --- a/frontend/src/views/NvrsView.vue +++ b/frontend/src/views/NvrsView.vue @@ -3,14 +3,14 @@ * NVR 录像机管理 * * 两段式添加摄像头: - * 1. 填地址/账号 → 「拉取通道」:**页面直接调本机软件**(WebSocket 17301 的 `get_channels`), - * 走 8000 私有协议登录设备拿到通道列表; + * 1. 点「拉取通道」:**页面直接调本机软件**(WebSocket 17301 的 `get_channels`), + * 走 8000 私有协议登录设备拿到通道列表;已存过密码的直接就拉,不用再点一次按钮; * 2. 勾选通道 → 提交到后端 `/api/web/nvrs/:id/channels` 落库成摄像头。 * * 设备在用户内网,所以拉取只能由本机软件做;后端只存结果。 - * 密码在后端只存密文、接口不返回,因此**每次拉取需要重新输入密码**。 + * 密码在后端只存密文、接口不返回,因此**每次拉取需要重新输入密码**(库里有时自动带出)。 */ -import { onMounted, reactive, ref } from 'vue'; +import { nextTick, onMounted, reactive, ref } from 'vue'; import AppLayout from '@/components/AppLayout.vue'; import DataPager from '@/components/DataPager.vue'; import ModalBox from '@/components/ModalBox.vue'; @@ -127,6 +127,7 @@ const payload = ref(null); const channelError = ref(''); const selected = ref>(new Set()); const existingChannels = ref>(new Set()); +const passwordInput = ref(null); async function openChannels(nvr: Nvr) { channelNvr.value = nvr; @@ -135,24 +136,33 @@ async function openChannels(nvr: Nvr) { channelError.value = ''; selected.value = new Set(); existingChannels.value = new Set(); - - try { - const data = await fetchNvrCameras(nvr.id); - existingChannels.value = new Set(data.list.map(item => item.channelNo)); - } catch { - // 已有通道读取失败不影响拉取 - } - channelOpen.value = true; - // 库里已有密码时自动带出(密文存储 → 后端解密 → 直接给本机软件), - // 用户不用每次手输;想用其他密码也可以在输入框里覆盖。 - try { - const cred = await fetchNvrCredential(nvr.id); - if (cred.hasPassword && cred.password) channelPassword.value = cred.password; - } catch { - // 取不到就保持为空,让用户手填 + // 已导入的通道 + 库里存的密码一起取:拿到密码就直接拉,用户不用再点一次「拉取通道」 + const [, cred] = await Promise.all([ + fetchNvrCameras(nvr.id) + .then(data => { + existingChannels.value = new Set(data.list.map(item => item.channelNo)); + }) + .catch(() => { + // 已有通道读取失败不影响拉取 + }), + // 密文存储 → 后端解密 → 直接给本机软件;想换密码可以在输入框里覆盖 + fetchNvrCredential(nvr.id).catch(() => null), + ]); + + // 期间用户可能已经关窗/换了另一台,别把结果写乱 + if (!channelOpen.value || channelNvr.value !== nvr) return; + + if (cred?.hasPassword && cred.password) { + channelPassword.value = cred.password; + await pull(); + return; } + + channelError.value = '这台录像机还没有保存密码,请填写设备密码后回车(或点「拉取通道」)。'; + await nextTick(); + passwordInput.value?.focus(); } /** 拉一次通道并把返回值写进弹窗状态(失败直接抛,由 pull() 统一处理) */ @@ -364,7 +374,7 @@ onMounted(() => load(1)); - +
{{ channelNvr.name || channelNvr.host }} @@ -372,8 +382,9 @@ onMounted(() => load(1)); 账号 {{ channelNvr.username }}
- - + +
@@ -393,7 +404,7 @@ onMounted(() => load(1)); 已选 {{ selected.size }} 个 -
+
@@ -483,11 +495,12 @@ onMounted(() => load(1)); margin: 10px 0; } -.channel-grid { - display: grid; - grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); - gap: 8px; - max-height: 320px; +/* 一个通道一行:名字/地址完整显示,不再挤成三列被省略 */ +.channel-list { + display: flex; + flex-direction: column; + gap: 6px; + max-height: 360px; overflow: auto; padding: 2px; } @@ -495,14 +508,19 @@ onMounted(() => load(1)); .channel-item { display: flex; align-items: center; - gap: 8px; - padding: 7px 10px; + gap: 10px; + padding: 8px 12px; border: 1px solid #e5e7eb; border-radius: 8px; font-size: 13px; cursor: pointer; } +.channel-item:hover { + border-color: #cbd5e1; + background: #f8fafc; +} + .channel-item.added { background: #f8fafc; color: #94a3b8; @@ -515,19 +533,23 @@ onMounted(() => load(1)); .ch-no { font-weight: 600; + flex: 0 0 72px; + font-variant-numeric: tabular-nums; } .ch-ip { color: #64748b; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; + flex: 0 0 auto; margin-left: auto; } .ch-name { + flex: 1 1 auto; + min-width: 0; color: #334155; - font-size: 12px; - max-width: 120px; + font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;