前端:本机软件连不上时统一提示窗(启动 / 下载)
- 新增 components/LocalServiceGate.vue:标题 + 场景说明 + 两条处理路径 「启动本机软件」(yuncang:// 唤起后等 WS 17301 连上,成功 emit ready 让调用方重试) 与「立即下载」(读取 /download/version.json,显示版本号与体积) - NvrsView:拉通道遇到 WS 连不上 → 弹该窗,就绪后自动重试(不再只给一行红字) - CamerasView:预览弹窗内的旧 offline 区块换成该窗,就绪后自动重开预览; 删除 launchSoftware / launchHint / release / downloadUrl 等重复状态 - CameraLayoutCanvas:合成画面连不上时同样弹该窗,就绪后重新拉 4 路画面 实测(7301,注入 WebSocket 构造抛错模拟离线):点「拉取通道」→ 弹出 「拉取通道需要本机软件 / 最新安装包:1.0.75 · 103.6 MB / 稍后 · 立即下载 · 启动本机软件」, 下载链接指向 http://127.0.0.1:7300/download/YuncangTraceSetup-1.0.75.msi
This commit is contained in:
parent
c68ec63e91
commit
cec0254d38
@ -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<number | null>(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<Record<number, { sid: string; src: string; stop: () => 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) :
|
||||
<p v-if="editable" class="hint">
|
||||
拖动画面移动位置,拖右下角调整大小;点选后可改宽高 / 码流。默认画布 {{ canvasW }}×{{ canvasH }}。
|
||||
</p>
|
||||
|
||||
<!-- 连不上本机软件:统一提示窗,就绪后自动重新拉画面 -->
|
||||
<LocalServiceGate
|
||||
:open="gateOpen"
|
||||
title="合成画面需要本机软件"
|
||||
:message="`@${canvasW}×${canvasH} 的实时画面由本机软件取流后推送,浏览器无法直连。`"
|
||||
@close="gateOpen = false"
|
||||
@ready="syncPreviews"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
138
frontend/src/components/LocalServiceGate.vue
Normal file
138
frontend/src/components/LocalServiceGate.vue
Normal file
@ -0,0 +1,138 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 「连接不上本机软件」统一提示窗
|
||||
*
|
||||
* 网页的拉通道 / 实时预览 / 云台都依赖本机软件(HTTP 17300 + WebSocket 17301),
|
||||
* 浏览器没法判断到底是「没安装」还是「装了没启动」,所以统一弹这个:
|
||||
* - **启动本机软件**:用 `yuncang://` 协议唤起,再等 WS 连上(连上就 emit `ready` 让调用方重试);
|
||||
* - **立即下载**:后端 `version.json` 里的最新安装包(拿不到就退回环境变量兜底地址)。
|
||||
*
|
||||
* 用法:
|
||||
* ```vue
|
||||
* <LocalServiceGate :open="gateOpen" @close="gateOpen = false" @ready="retry" />
|
||||
* ```
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import ModalBox from '@/components/ModalBox.vue';
|
||||
import { waitForLocalWs, wakeLocalSoftware } from '@/api/localWs';
|
||||
import { fetchSoftwareRelease, softwareDownloadUrl, type SoftwareRelease } from '@/utils/localSoftware';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
open: boolean;
|
||||
title?: string;
|
||||
/** 场景说明(预览 / 拉通道 / 大屏 各自不同) */
|
||||
message?: string;
|
||||
/** 唤起后最多等多久(毫秒) */
|
||||
waitMs?: number;
|
||||
}>(), {
|
||||
title: '连接不上本机软件',
|
||||
message: '',
|
||||
waitMs: 12000,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{ (e: 'close'): void; (e: 'ready'): void }>();
|
||||
|
||||
const release = ref<SoftwareRelease | null>(null);
|
||||
const launching = ref(false);
|
||||
const hint = ref('');
|
||||
|
||||
const downloadUrl = computed(() => softwareDownloadUrl(release.value));
|
||||
const sizeText = computed(() => {
|
||||
const size = release.value?.size;
|
||||
return size ? ` · ${(size / 1048576).toFixed(1)} MB` : '';
|
||||
});
|
||||
|
||||
watch(() => props.open, async open => {
|
||||
if (!open) return;
|
||||
|
||||
hint.value = '';
|
||||
// 版本信息每次都取一次(后端更新后能立刻看到新版本号)
|
||||
release.value = await fetchSoftwareRelease();
|
||||
});
|
||||
|
||||
async function launch() {
|
||||
if (launching.value) return;
|
||||
|
||||
launching.value = true;
|
||||
hint.value = '已请求唤起本机软件,正在等待它启动…';
|
||||
|
||||
// 必须在用户点击的调用栈里触发协议(浏览器会拦自动唤起)
|
||||
wakeLocalSoftware();
|
||||
|
||||
const ok = await waitForLocalWs(props.waitMs);
|
||||
launching.value = false;
|
||||
|
||||
if (ok) {
|
||||
hint.value = '';
|
||||
emit('ready');
|
||||
emit('close');
|
||||
return;
|
||||
}
|
||||
|
||||
hint.value = '没有检测到软件启动:可能还没安装,或安装时没有注册启动协议。请点「立即下载」安装后重试。';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ModalBox :open="open" :title="title" width="480px" @close="emit('close')">
|
||||
<p class="gate-text">
|
||||
{{ message || '这个功能需要「云仓视频溯源软件」在本机运行(浏览器无法直接访问设备与录像机)。' }}
|
||||
</p>
|
||||
|
||||
<ul class="gate-list">
|
||||
<li>软件要装、并在<b>这台电脑</b>上运行(关窗口会缩到托盘,服务不会停)。</li>
|
||||
<li>已安装但没反应:点「启动本机软件」,浏览器会问「要打开吗」,请点允许。</li>
|
||||
</ul>
|
||||
|
||||
<p v-if="downloadUrl" class="gate-release">
|
||||
最新安装包:{{ release?.version || '(未标注版本)' }}{{ sizeText }}
|
||||
</p>
|
||||
|
||||
<p v-if="hint" class="gate-hint">{{ hint }}</p>
|
||||
|
||||
<template #footer>
|
||||
<button class="btn btn-ghost" type="button" @click="emit('close')">稍后</button>
|
||||
<a
|
||||
v-if="downloadUrl"
|
||||
class="btn"
|
||||
:href="downloadUrl"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>立即下载</a>
|
||||
<button class="btn btn-primary" type="button" :disabled="launching" @click="launch">
|
||||
{{ launching ? '正在启动…' : '启动本机软件' }}
|
||||
</button>
|
||||
</template>
|
||||
</ModalBox>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.gate-text {
|
||||
margin: 0 0 10px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.gate-list {
|
||||
margin: 0 0 12px;
|
||||
padding-left: 20px;
|
||||
color: #4b5563;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.gate-release {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.gate-hint {
|
||||
margin: 10px 0 0;
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
background: #fff7ed;
|
||||
color: #b45309;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
</style>
|
||||
@ -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<Camera[]>([]);
|
||||
const nvrs = ref<Nvr[]>([]);
|
||||
@ -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<SoftwareRelease | null>(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') {
|
||||
|
||||
<div v-if="previewError" class="alert alert-error">{{ previewError }}</div>
|
||||
|
||||
<!-- 连不上本机软件:给「启动 / 下载」两条路(浏览器无法直接解码设备码流) -->
|
||||
<div v-if="previewOffline" class="preview-offline">
|
||||
<p class="offline-title">连接不上本机软件</p>
|
||||
<p class="hint">
|
||||
实时预览依赖本机软件走设备 8000 端口取流,浏览器无法直连。
|
||||
若已安装但没启动,点「启动本机软件」;没安装则点「下载安装包」。
|
||||
</p>
|
||||
<div class="offline-actions">
|
||||
<button class="btn btn-primary" :disabled="launching" @click="launchSoftware">
|
||||
{{ launching ? '正在启动…' : '启动本机软件(已安装)' }}
|
||||
</button>
|
||||
<a class="btn btn-ghost" :href="downloadUrl || '#'" target="_blank" rel="noopener">
|
||||
下载安装包{{ release?.version ? ` v${release.version}` : '' }}
|
||||
</a>
|
||||
</div>
|
||||
<p v-if="launchHint" class="hint warn">{{ launchHint }}</p>
|
||||
<p class="hint tiny">
|
||||
启动时会弹出「要打开 xxx 吗?」请点允许;没反应也可以直接双击桌面/托盘图标。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="preview-stage">
|
||||
<div v-if="previewLoading" class="preview-tip">正在连接设备…</div>
|
||||
<img v-else-if="previewSrc" :src="previewSrc" alt="实时画面" @error="onPreviewImgError" />
|
||||
@ -811,6 +759,15 @@ async function doPreset(action: 'set' | 'goto' | 'clear') {
|
||||
<button class="btn btn-ghost" @click="closePreview">关闭</button>
|
||||
</template>
|
||||
</ModalBox>
|
||||
|
||||
<!-- 连不上本机软件:统一的「启动 / 下载」提示窗,就绪后自动重开预览 -->
|
||||
<LocalServiceGate
|
||||
:open="previewOffline"
|
||||
title="实时预览需要本机软件"
|
||||
message="实时画面由本机软件从设备 8000 端口取流并推送,浏览器无法直连。"
|
||||
@close="previewOffline = false"
|
||||
@ready="retryPreview"
|
||||
/>
|
||||
</AppLayout>
|
||||
</template>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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<Nvr[]>([]);
|
||||
@ -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));
|
||||
</button>
|
||||
</template>
|
||||
</ModalBox>
|
||||
|
||||
<!-- 连不上本机软件:统一的「启动 / 下载」提示窗,就绪后自动重新拉取 -->
|
||||
<LocalServiceGate
|
||||
:open="gateOpen"
|
||||
title="拉取通道需要本机软件"
|
||||
message="读取录像机通道要走设备 8000 私有协议,浏览器无法直连,必须由本机软件代取。"
|
||||
@close="gateOpen = false"
|
||||
@ready="pull"
|
||||
/>
|
||||
</AppLayout>
|
||||
</template>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user