diff --git a/frontend/src/components/CameraLayoutCanvas.vue b/frontend/src/components/CameraLayoutCanvas.vue index c97a2c8..0eaa1bc 100644 --- a/frontend/src/components/CameraLayoutCanvas.vue +++ b/frontend/src/components/CameraLayoutCanvas.vue @@ -14,7 +14,8 @@ import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'; import { updateWorkstationCameraLayout } from '@/api/videoApi'; import { fetchNvrCredential } from '@/api/videoApi'; -import { localWs, waitForLocalWs, wakeLocalSoftware } from '@/api/localWs'; +import { localWs } from '@/api/localWs'; +import LocalServiceGate from '@/components/LocalServiceGate.vue'; import type { WorkstationCameraLink, WorkstationDetail } from '@/api/video'; const props = withDefaults(defineProps<{ @@ -49,6 +50,8 @@ const selectedId = ref(null); const saving = ref(false); const message = ref(''); const error = ref(''); +/** 连不上本机软件 → 弹统一提示窗 */ +const gateOpen = ref(false); /** 预览会话:cameraId → { sid, src, stop, url }(帧走 WS,object URL 每次置换) */ const previews = reactive void; url: string }>>({}); @@ -181,13 +184,8 @@ async function syncPreviews() { const message = err instanceof Error ? err.message : '预览失败'; if (/超时|无法连接|未连接|断开/.test(message)) { - // 本机软件没启动 → 叫起来再试(只试一次,避免刷屏) - wakeLocalSoftware(); - if (await waitForLocalWs(8000)) { - void syncPreviews(); - return; - } - error.value = '本机软件未运行,画面无法加载'; + // 本机软件没启动 → 弹统一提示窗(启动 / 下载),就绪后重新拉 + gateOpen.value = true; } else { error.value = message; } @@ -415,6 +413,15 @@ const selected = computed(() => (selectedId.value ? tileById(selectedId.value) :

拖动画面移动位置,拖右下角调整大小;点选后可改宽高 / 码流。默认画布 {{ canvasW }}×{{ canvasH }}。

+ + + diff --git a/frontend/src/components/LocalServiceGate.vue b/frontend/src/components/LocalServiceGate.vue new file mode 100644 index 0000000..b764332 --- /dev/null +++ b/frontend/src/components/LocalServiceGate.vue @@ -0,0 +1,138 @@ + + + + + diff --git a/frontend/src/views/CamerasView.vue b/frontend/src/views/CamerasView.vue index 89b9237..e40531f 100644 --- a/frontend/src/views/CamerasView.vue +++ b/frontend/src/views/CamerasView.vue @@ -18,13 +18,8 @@ import { updateCamera, } from '@/api/videoApi'; import type { Camera, Nvr } from '@/api/video'; -import { - fetchSoftwareRelease, - launchLocalSoftware, - softwareDownloadUrl, - type SoftwareRelease, -} from '@/utils/localSoftware'; import { localWs, waitForLocalWs, wakeLocalSoftware, type WsPtzCommand } from '@/api/localWs'; +import LocalServiceGate from '@/components/LocalServiceGate.vue'; const list = ref([]); const nvrs = ref([]); @@ -218,12 +213,8 @@ let wsUnsubscribe: (() => void) | null = null; let previewCred: { host: string; port: number; username: string; password: string } | null = null; const previewWinId = ref(''); const previewWinMsg = ref(''); -/** 连不上本机软件(没启动 / 没安装)*/ +/** 连不上本机软件(没启动 / 没安装):弹统一提示窗(启动 / 下载)*/ const previewOffline = ref(false); -const launching = ref(false); -const launchHint = ref(''); -const release = ref(null); -const downloadUrl = computed(() => softwareDownloadUrl(release.value)); /** 预览模式的中文说明 */ const previewModeLabel = computed(() => { @@ -263,7 +254,6 @@ async function openPreview(camera: Camera, streamType = previewStreamType.value) previewError.value = ''; previewLoading.value = true; previewOffline.value = false; - launchHint.value = ''; try { const nvrId = camera.nvrId ?? camera.nvr?.id; @@ -291,7 +281,6 @@ async function openPreview(camera: Camera, streamType = previewStreamType.value) wakeLocalSoftware(); if (!(await waitForLocalWs(12000))) { previewOffline.value = true; - void fetchSoftwareRelease().then(data => { release.value = data; }); return; } } @@ -335,10 +324,9 @@ async function openPreview(camera: Camera, streamType = previewStreamType.value) if (info.warning) previewError.value = info.warning; } catch (err) { const message = err instanceof Error ? err.message : '预览失败'; - // 连不上本机软件(软件没启动 / 没安装 / WS 被拦)→ 给「启动 / 下载」两条路 + // 连不上本机软件(软件没启动 / 没安装 / WS 被拦)→ 弹统一提示窗 if (/超时|无法连接|未连接|断开/.test(message)) { previewOffline.value = true; - void fetchSoftwareRelease().then(data => { release.value = data; }); } else { previewError.value = message; } @@ -347,28 +335,10 @@ async function openPreview(camera: Camera, streamType = previewStreamType.value) } } -/** - * 【启动本机软件】 - * - * 网页无法区分「没安装」和「装了没启动」,所以先叫一次: - * - 起来了 → 就是没启动,直接重新打开预览; - * - 等不到 → 按「可能没安装」处理,提示去下载安装包。 - */ -async function launchSoftware() { - launching.value = true; - launchHint.value = ''; - - launchLocalSoftware(); - const alive = await waitForLocalWs(12000); - launching.value = false; - - if (!alive) { - launchHint.value = '没有检测到本机软件启动:可能还没安装,或安装时没有注册启动协议。请点右侧下载安装包。'; - return; - } - +/** 本机软件就绪(提示窗里唤起成功)→ 重新打开预览 */ +function retryPreview() { const camera = previewCamera.value; - if (camera) await openPreview(camera, previewStreamType.value); + if (camera) void openPreview(camera, previewStreamType.value); } async function closePreview() { @@ -390,7 +360,6 @@ async function closePreview() { previewWinMsg.value = ''; previewCred = null; previewOffline.value = false; - launchHint.value = ''; // 满帧率原生窗口是本机软件的独立窗口,网页关预览时一并关掉 if (wid) { @@ -697,27 +666,6 @@ async function doPreset(action: 'set' | 'goto' | 'clear') {
{{ previewError }}
- -
-

连接不上本机软件

-

- 实时预览依赖本机软件走设备 8000 端口取流,浏览器无法直连。 - 若已安装但没启动,点「启动本机软件」;没安装则点「下载安装包」。 -

-
- - - 下载安装包{{ release?.version ? ` v${release.version}` : '' }} - -
-

{{ launchHint }}

-

- 启动时会弹出「要打开 xxx 吗?」请点允许;没反应也可以直接双击桌面/托盘图标。 -

-
-
正在连接设备…
实时画面 @@ -811,6 +759,15 @@ async function doPreset(action: 'set' | 'goto' | 'clear') { + + + @@ -900,26 +857,6 @@ async function doPreset(action: 'set' | 'goto' | 'clear') { color: #15803d; } -.preview-offline { - border: 1px solid #fed7aa; - background: #fff7ed; - border-radius: 8px; - padding: 14px 16px; -} - -.offline-title { - margin: 0 0 6px; - font-weight: 600; - color: #b45309; -} - -.offline-actions { - display: flex; - gap: 10px; - flex-wrap: wrap; - margin: 10px 0 6px; -} - .hint.warn { color: #b45309; } diff --git a/frontend/src/views/NvrsView.vue b/frontend/src/views/NvrsView.vue index 57f338b..4045b2e 100644 --- a/frontend/src/views/NvrsView.vue +++ b/frontend/src/views/NvrsView.vue @@ -26,7 +26,8 @@ import { } from '@/api/videoApi'; import type { Nvr } from '@/api/video'; import type { HikChannelsPayload } from '@/api/local'; -import { localWs, waitForLocalWs, wakeLocalSoftware } from '@/api/localWs'; +import { localWs } from '@/api/localWs'; +import LocalServiceGate from '@/components/LocalServiceGate.vue'; import { formatTime } from '@/utils/format'; const list = ref([]); @@ -37,6 +38,8 @@ const keyword = ref(''); const loading = ref(false); const error = ref(''); const okMsg = ref(''); +/** 连不上本机软件 → 弹统一提示窗(启动 / 下载) */ +const gateOpen = ref(false); // ---------------- 新增 / 编辑 ---------------- const formOpen = ref(false); @@ -185,24 +188,16 @@ async function pull() { payload.value = null; try { - try { - await pullOnce(); - } catch (err) { - const message = err instanceof Error ? err.message : '拉取失败'; - - // 连不上本机软件 → 唤起它,等起来后再试一次(按钮就在用户手上,可以等) - if (!OFFLINE_HINT.test(message)) throw err; - - wakeLocalSoftware(); - if (!(await waitForLocalWs(8000))) { - channelError.value = `连接不上本机软件(${message})。请先启动本机软件再重试。`; - return; - } - - await pullOnce(); - } + await pullOnce(); } catch (err) { const message = err instanceof Error ? err.message : '拉取失败'; + + // 连不上本机软件 → 弹统一提示窗(启动 / 下载 两条路),就绪后会自动重试 + if (OFFLINE_HINT.test(message)) { + gateOpen.value = true; + return; + } + channelError.value = message; } finally { pulling.value = false; @@ -421,6 +416,15 @@ onMounted(() => load(1)); + + +