管理页的弹窗基本都是表单(套餐 / NVR / 摄像头 / 工作台 / 主体 / 文档 / 成员…),
原来 ModalBox 的遮罩无条件 `@click.self="emit('close')"`,手一滑点到外面整屏输入就没了。
- ModalBox 新增 maskClosable,默认 false:点遮罩不关闭,只能用 × 或底部按钮;
- 纯展示类弹窗(实时预览 / 合并输出预览)显式加 mask-closable,保留点击外面关闭的习惯。
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1041 lines
33 KiB
Vue
1041 lines
33 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* 摄像头列表(NVR 通道)
|
||
*
|
||
* 摄像头只能在 NVR 页「拉取通道 → 勾选导入」产生;这里负责查看 / 改名 / 启停 / 删除。
|
||
*/
|
||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
|
||
import type { ComponentPublicInstance } from 'vue';
|
||
import AppLayout from '@/components/AppLayout.vue';
|
||
import DataPager from '@/components/DataPager.vue';
|
||
import ModalBox from '@/components/ModalBox.vue';
|
||
import { ApiError } from '@/api/client';
|
||
import {
|
||
batchDeleteCameras,
|
||
deleteCamera,
|
||
fetchCameras,
|
||
fetchNvrCredential,
|
||
fetchNvrs,
|
||
updateCamera,
|
||
} from '@/api/videoApi';
|
||
import type { Camera, Nvr } from '@/api/video';
|
||
import { localWs, type WsPtzCommand } from '@/api/localWs';
|
||
import { createFramePainter, type FramePainter } from '@/utils/frameCanvas';
|
||
import LocalServiceGate from '@/components/LocalServiceGate.vue';
|
||
|
||
const list = ref<Camera[]>([]);
|
||
const nvrs = ref<Nvr[]>([]);
|
||
const total = ref(0);
|
||
const page = ref(1);
|
||
const pageSize = ref(10);
|
||
const keyword = ref('');
|
||
const nvrFilter = ref<number | ''>('');
|
||
const loading = ref(false);
|
||
const error = ref('');
|
||
const okMsg = ref('');
|
||
|
||
const editOpen = ref(false);
|
||
const saving = ref(false);
|
||
const editing = ref<Camera | null>(null);
|
||
const form = reactive({ name: '', status: 1, remark: '' });
|
||
|
||
// 多选 / 批量删除
|
||
const selectedIds = ref<Set<number>>(new Set());
|
||
const allChecked = computed(() => list.value.length > 0 && list.value.every(item => selectedIds.value.has(item.id)));
|
||
|
||
function toggleOne(id: number) {
|
||
const next = new Set(selectedIds.value);
|
||
if (next.has(id)) next.delete(id);
|
||
else next.add(id);
|
||
selectedIds.value = next;
|
||
}
|
||
|
||
function toggleAll() {
|
||
selectedIds.value = allChecked.value ? new Set() : new Set(list.value.map(item => item.id));
|
||
}
|
||
|
||
async function doBatchDelete() {
|
||
const ids = [ ...selectedIds.value ];
|
||
if (!ids.length) return;
|
||
if (!window.confirm(`确认删除选中的 ${ids.length} 个摄像头?\n会同时从工作台解绑。`)) return;
|
||
|
||
error.value = '';
|
||
okMsg.value = '';
|
||
try {
|
||
const data = await batchDeleteCameras(ids);
|
||
okMsg.value = `已删除 ${data.removed} 个摄像头${data.skipped ? `(${data.skipped} 个无权/不存在已跳过)` : ''}`;
|
||
selectedIds.value = new Set();
|
||
await load();
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '批量删除失败';
|
||
}
|
||
}
|
||
|
||
async function load(targetPage = page.value) {
|
||
loading.value = true;
|
||
error.value = '';
|
||
try {
|
||
const data = await fetchCameras({
|
||
page: targetPage,
|
||
pageSize: pageSize.value,
|
||
keyword: keyword.value.trim(),
|
||
nvrId: nvrFilter.value,
|
||
});
|
||
list.value = data.list;
|
||
total.value = data.total;
|
||
page.value = data.page;
|
||
selectedIds.value = new Set();
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '加载失败';
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
async function loadNvrs() {
|
||
try {
|
||
const data = await fetchNvrs({ page: 1, pageSize: 100 });
|
||
nvrs.value = data.list;
|
||
} catch {
|
||
// 下拉框失败不影响列表
|
||
}
|
||
}
|
||
|
||
function search() {
|
||
load(1);
|
||
}
|
||
|
||
function openEdit(camera: Camera) {
|
||
editing.value = camera;
|
||
Object.assign(form, {
|
||
name: camera.name || '',
|
||
status: camera.status,
|
||
remark: camera.remark || '',
|
||
});
|
||
editOpen.value = true;
|
||
}
|
||
|
||
async function save() {
|
||
if (!editing.value) return;
|
||
saving.value = true;
|
||
error.value = '';
|
||
try {
|
||
await updateCamera(editing.value.id, {
|
||
name: form.name,
|
||
status: Number(form.status),
|
||
remark: form.remark,
|
||
});
|
||
okMsg.value = '摄像头已更新';
|
||
editOpen.value = false;
|
||
await load();
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '保存失败';
|
||
} finally {
|
||
saving.value = false;
|
||
}
|
||
}
|
||
|
||
async function doDelete(camera: Camera) {
|
||
if (!window.confirm(`确认删除摄像头「${camera.name}」(通道 ${camera.channelNo})?\n会同时从工作台解绑。`)) return;
|
||
error.value = '';
|
||
try {
|
||
await deleteCamera(camera.id);
|
||
okMsg.value = '摄像头已删除';
|
||
await load();
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '删除失败';
|
||
}
|
||
}
|
||
|
||
async function toggleStatus(camera: Camera) {
|
||
error.value = '';
|
||
try {
|
||
await updateCamera(camera.id, { status: camera.status === 1 ? 0 : 1 });
|
||
await load();
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '操作失败';
|
||
}
|
||
}
|
||
|
||
// ---------------- 列表内双击改名 ----------------
|
||
/** 正在改名的摄像头 id(null = 没有在改名) */
|
||
const inlineId = ref<number | null>(null);
|
||
const inlineName = ref('');
|
||
const inlineSaving = ref(false);
|
||
const inlineInput = ref<HTMLInputElement | null>(null);
|
||
|
||
/** v-for 里的 ref 会变成数组,这里用函数 ref 只留当前那个 input */
|
||
function bindInlineInput(el: Element | ComponentPublicInstance | null) {
|
||
inlineInput.value = el instanceof HTMLInputElement ? el : null;
|
||
}
|
||
|
||
function startRename(camera: Camera) {
|
||
if (inlineSaving.value) return;
|
||
inlineId.value = camera.id;
|
||
inlineName.value = camera.name || '';
|
||
void nextTick(() => {
|
||
inlineInput.value?.focus();
|
||
inlineInput.value?.select();
|
||
});
|
||
}
|
||
|
||
function cancelRename() {
|
||
if (inlineSaving.value) return;
|
||
inlineId.value = null;
|
||
inlineName.value = '';
|
||
}
|
||
|
||
/** 提交改名:回车 / 失焦都走这里;名称没变或为空就只是取消 */
|
||
async function commitRename(camera: Camera) {
|
||
if (inlineId.value !== camera.id || inlineSaving.value) return;
|
||
|
||
const next = inlineName.value.trim();
|
||
const previous = (camera.name || '').trim();
|
||
|
||
if (!next) {
|
||
error.value = '摄像头名称不能为空';
|
||
cancelRename();
|
||
return;
|
||
}
|
||
if (next === previous) {
|
||
cancelRename();
|
||
return;
|
||
}
|
||
|
||
inlineSaving.value = true;
|
||
error.value = '';
|
||
okMsg.value = '';
|
||
try {
|
||
await updateCamera(camera.id, { name: next });
|
||
// 就地更新,避免为了一个名字整表重载(会丢滚动位置和当前页)
|
||
camera.name = next;
|
||
okMsg.value = `已改名:${next}`;
|
||
inlineId.value = null;
|
||
inlineName.value = '';
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '改名失败';
|
||
} finally {
|
||
inlineSaving.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 页面关闭/刷新/切走时释放预览
|
||
*
|
||
* WS 会随页面一起断开(本机侧会自动清理会话与原生窗口),这里再显式发一次更稳。
|
||
*/
|
||
function releasePreviewOnUnload() {
|
||
if (wsSid) {
|
||
void localWs.stopPreview(wsSid);
|
||
wsSid = '';
|
||
}
|
||
if (previewWinId.value) {
|
||
void localWs.closeWindow(previewWinId.value);
|
||
previewWinId.value = '';
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
load(1);
|
||
loadNvrs();
|
||
window.addEventListener('pagehide', releasePreviewOnUnload);
|
||
window.addEventListener('beforeunload', releasePreviewOnUnload);
|
||
});
|
||
|
||
// ---------------- 实时预览 ----------------
|
||
const previewOpen = ref(false);
|
||
const previewCamera = ref<Camera | null>(null);
|
||
const previewLoading = ref(false);
|
||
const previewError = ref('');
|
||
|
||
/** 预览会话信息(全部来自 WS;密码不进任何 URL) */
|
||
interface PreviewData {
|
||
sid: string;
|
||
host: string;
|
||
port: number;
|
||
channel: number;
|
||
logicalChannel: number;
|
||
streamId: string;
|
||
fps: number;
|
||
mode: string;
|
||
streamType: number;
|
||
warning?: string | null;
|
||
rtspUrl: string;
|
||
}
|
||
|
||
const previewData = ref<PreviewData | null>(null);
|
||
const previewFps = ref(25);
|
||
/** 0-主码流(默认) 1-子码流 */
|
||
const previewStreamType = ref(0);
|
||
/** 实时画面画布(帧直接画上来,不再每帧换 object URL) */
|
||
const previewCanvas = ref<HTMLCanvasElement | null>(null);
|
||
/** 是否已经收到过帧(决定显示「正在连接」还是「暂无画面」) */
|
||
const previewHasFrame = ref(false);
|
||
/** 当前会话的帧绘制器 */
|
||
let previewPainter: FramePainter | null = null;
|
||
/** WS 预览会话 sid(空 = 当前没有会话) */
|
||
let wsSid = '';
|
||
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 previewModeLabel = computed(() => {
|
||
const mode = previewData.value?.mode;
|
||
if (mode === 'ffmpeg') return 'ffmpeg 转码(主码流,约 25fps)';
|
||
if (mode === 'capture') return '设备抓帧(约 5fps)';
|
||
return '码流解码(最高 25fps)';
|
||
});
|
||
|
||
/** 停掉 WS 预览:取消订阅 + 通知本机释放会话 + 停用帧绘制器 */
|
||
function stopWsPreview() {
|
||
wsUnsubscribe?.();
|
||
wsUnsubscribe = null;
|
||
|
||
if (wsSid) {
|
||
void localWs.stopPreview(wsSid);
|
||
wsSid = '';
|
||
}
|
||
|
||
// 先作废再擦画布:避免解码中的那一帧在擦完后才落地
|
||
previewPainter?.dispose();
|
||
previewPainter?.clear();
|
||
previewPainter = null;
|
||
previewHasFrame.value = false;
|
||
}
|
||
|
||
/** RTSP 展示用:遮掉密码,避免截图/录像时泄露 */
|
||
function maskedRtsp(url: string): string {
|
||
return url.replace(/\/\/[^:/@]+:[^@]+@/, '//***:***@');
|
||
}
|
||
|
||
async function openPreview(camera: Camera, streamType = previewStreamType.value) {
|
||
previewCamera.value = camera;
|
||
previewStreamType.value = streamType;
|
||
previewOpen.value = true;
|
||
previewData.value = null;
|
||
previewHasFrame.value = false;
|
||
previewError.value = '';
|
||
previewLoading.value = true;
|
||
previewOffline.value = false;
|
||
|
||
try {
|
||
const nvrId = camera.nvrId ?? camera.nvr?.id;
|
||
if (!nvrId) {
|
||
previewError.value = '该摄像头没有关联 NVR,无法预览';
|
||
return;
|
||
}
|
||
|
||
// 先放掉旧会话(旧会话不释放会占住设备码流,切过去的那路就拿不到帧)
|
||
stopWsPreview();
|
||
|
||
// 设备凭据在后端加密保存,这里取一次明文交给本机软件(浏览器不落盘)
|
||
const cred = await fetchNvrCredential(nvrId);
|
||
previewCred = cred;
|
||
|
||
// 主码流(2560×1440)PlayM4 转不出 JPEG → 用 **ffmpeg** 转码(缩到 1280 宽,约 25fps);
|
||
// 子码流走 SDK 取流 + PlayM4 解码(640×360、25fps)。
|
||
const mode = streamType === 0 ? 'ffmpeg' : 'stream';
|
||
|
||
// 预览**只走本机 WebSocket(17301)**:二进制 JPEG 帧,一条连接可同时推多路。
|
||
try {
|
||
await localWs.connect(2500);
|
||
} catch {
|
||
// 连不上:**立即**弹统一提示窗(启动 / 下载),由用户自己点(不在此处干等12 秒)
|
||
previewOffline.value = true;
|
||
return;
|
||
}
|
||
|
||
const info = await localWs.startPreview({
|
||
host: cred.host,
|
||
port: cred.port,
|
||
user: cred.username,
|
||
password: cred.password,
|
||
channel: camera.channelNo,
|
||
fps: previewFps.value,
|
||
streamType,
|
||
mode,
|
||
name: camera.name || undefined,
|
||
});
|
||
|
||
wsSid = info.sid;
|
||
previewData.value = {
|
||
sid: info.sid,
|
||
host: cred.host,
|
||
port: cred.port,
|
||
channel: info.channel,
|
||
logicalChannel: info.logicalChannel,
|
||
streamId: info.streamId,
|
||
fps: info.fps,
|
||
mode: info.mode,
|
||
streamType: info.streamType,
|
||
warning: info.warning || undefined,
|
||
rtspUrl: `rtsp://${cred.username}:${cred.password}@${cred.host}:554/Streaming/Channels/${info.streamId}`,
|
||
};
|
||
|
||
wsUnsubscribe = localWs.onFrame(info.sid, blob => {
|
||
if (!previewPainter) previewPainter = createFramePainter(() => previewCanvas.value, 'contain');
|
||
previewPainter.push(blob);
|
||
previewHasFrame.value = true;
|
||
});
|
||
|
||
if (info.warning) previewError.value = info.warning;
|
||
} catch (err) {
|
||
const message = err instanceof Error ? err.message : '预览失败';
|
||
// 连不上本机软件(软件没启动 / 没安装 / WS 被拦)→ 弹统一提示窗
|
||
if (/超时|无法连接|未连接|断开/.test(message)) {
|
||
previewOffline.value = true;
|
||
} else {
|
||
previewError.value = message;
|
||
}
|
||
} finally {
|
||
previewLoading.value = false;
|
||
}
|
||
}
|
||
|
||
/** 本机软件就绪(提示窗里唤起成功)→ 重新打开预览 */
|
||
function retryPreview() {
|
||
const camera = previewCamera.value;
|
||
if (camera) void openPreview(camera, previewStreamType.value);
|
||
}
|
||
|
||
async function closePreview() {
|
||
const wid = previewWinId.value;
|
||
|
||
// 关窗前先停云台,避免摄像机一直转
|
||
if (ptzActiveCommand) await ptzHoldStop();
|
||
if (ptzAuto.value) {
|
||
ptzAuto.value = false;
|
||
await sendPtz('auto', true).catch(() => undefined);
|
||
}
|
||
ptzError.value = '';
|
||
previewOpen.value = false;
|
||
stopWsPreview();
|
||
previewData.value = null;
|
||
previewCamera.value = null;
|
||
previewError.value = '';
|
||
previewWinMsg.value = '';
|
||
previewCred = null;
|
||
previewOffline.value = false;
|
||
|
||
// 满帧率原生窗口是本机软件的独立窗口,网页关预览时一并关掉
|
||
if (wid) {
|
||
await localWs.closeWindow(wid);
|
||
}
|
||
}
|
||
|
||
/** 打开满帧率原生窗口(25fps,PlayM4 直接渲染) */
|
||
async function openFullRateWindow() {
|
||
const camera = previewCamera.value;
|
||
if (!camera) return;
|
||
|
||
previewWinMsg.value = '';
|
||
try {
|
||
let cred = previewCred;
|
||
if (!cred) {
|
||
const nvrId = camera.nvrId ?? camera.nvr?.id;
|
||
if (!nvrId) {
|
||
previewError.value = '该摄像头没有关联 NVR';
|
||
return;
|
||
}
|
||
cred = await fetchNvrCredential(nvrId);
|
||
previewCred = cred;
|
||
}
|
||
|
||
const info = await localWs.openWindow({
|
||
host: cred.host,
|
||
port: cred.port,
|
||
user: cred.username,
|
||
password: cred.password,
|
||
channel: camera.channelNo,
|
||
streamType: previewStreamType.value,
|
||
name: camera.name || camera.channelName || undefined,
|
||
});
|
||
|
||
previewWinId.value = info.wid;
|
||
previewWinMsg.value = `${info.message || '已在本机软件里打开满帧率预览窗口'}(请在本机任务栏切换到预览窗口)`;
|
||
} catch (err) {
|
||
previewError.value = err instanceof Error ? err.message : '打开满帧率窗口失败';
|
||
}
|
||
}
|
||
|
||
function setPreviewFps(value: number) {
|
||
previewFps.value = value;
|
||
|
||
// WS 模式的帧率固定在会话里,需要重建一路
|
||
const camera = previewCamera.value;
|
||
if (wsSid && camera) void openPreview(camera, previewStreamType.value);
|
||
}
|
||
|
||
/**
|
||
* 「画面」切换码流:**先释放旧会话再建新的**,否则两路抢设备流会拿不到帧
|
||
*/
|
||
function switchStreamType(value: number) {
|
||
previewStreamType.value = value === 1 ? 1 : 0;
|
||
const camera = previewCamera.value;
|
||
if (camera) void openPreview(camera, previewStreamType.value);
|
||
}
|
||
|
||
async function copyRtsp() {
|
||
if (!previewData.value) return;
|
||
try {
|
||
await navigator.clipboard.writeText(previewData.value.rtspUrl);
|
||
okMsg.value = 'RTSP 地址已复制(可贴到 VLC 播放)';
|
||
} catch {
|
||
previewError.value = '复制失败,请手动选择地址复制';
|
||
}
|
||
}
|
||
|
||
onBeforeUnmount(() => {
|
||
window.removeEventListener('pagehide', releasePreviewOnUnload);
|
||
window.removeEventListener('beforeunload', releasePreviewOnUnload);
|
||
releasePreviewOnUnload();
|
||
stopWsPreview();
|
||
localWs.close();
|
||
void closePreview();
|
||
});
|
||
|
||
// ---------------- 云台(PTZ) ----------------
|
||
const ptzSpeed = ref(4);
|
||
const ptzError = ref('');
|
||
const ptzBusy = ref(false);
|
||
const ptzPresetNo = ref(1);
|
||
const ptzAuto = ref(false);
|
||
/** 正在进行中的连续动作(松开时要发对应 stop) */
|
||
let ptzActiveCommand: string | null = null;
|
||
|
||
/** 取设备凭据(预览已经取过就直接用) */
|
||
async function ensureCred() {
|
||
if (previewCred) return previewCred;
|
||
const camera = previewCamera.value;
|
||
const nvrId = camera?.nvrId ?? camera?.nvr?.id;
|
||
if (!nvrId) return null;
|
||
const cred = await fetchNvrCredential(nvrId);
|
||
previewCred = cred;
|
||
return cred;
|
||
}
|
||
|
||
/** 发一条云台命令(非云台通道会回设备错误码) */
|
||
async function sendPtz(command: string, stop: boolean) {
|
||
const camera = previewCamera.value;
|
||
if (!camera) return;
|
||
|
||
try {
|
||
const cred = await ensureCred();
|
||
if (!cred) return;
|
||
|
||
await localWs.ptz({
|
||
host: cred.host,
|
||
port: cred.port,
|
||
user: cred.username,
|
||
password: cred.password,
|
||
channel: camera.channelNo,
|
||
command,
|
||
stop,
|
||
speed: ptzSpeed.value,
|
||
});
|
||
|
||
ptzError.value = '';
|
||
} catch (err) {
|
||
ptzError.value = err instanceof Error ? err.message : '云台操作失败';
|
||
}
|
||
}
|
||
|
||
/** 按下(方向/变倍/聚焦/光圈):开始连续动作 */
|
||
function ptzHoldStart(command: WsPtzCommand) {
|
||
if (ptzActiveCommand || !previewCamera.value) return;
|
||
ptzActiveCommand = command;
|
||
void sendPtz(command, false);
|
||
}
|
||
|
||
/** 松开:停止当前动作(不 stop 会一直转) */
|
||
async function ptzHoldStop() {
|
||
const command = ptzActiveCommand;
|
||
if (!command) return;
|
||
ptzActiveCommand = null;
|
||
await sendPtz(command, true);
|
||
}
|
||
|
||
/** 自动扫描(点一下开始,再点一下停) */
|
||
async function togglePtzAuto() {
|
||
if (ptzAuto.value) {
|
||
ptzAuto.value = false;
|
||
await sendPtz('auto', true);
|
||
} else {
|
||
ptzAuto.value = true;
|
||
await sendPtz('auto', false);
|
||
}
|
||
}
|
||
|
||
/** 预置点:设置 / 调用 / 删除 */
|
||
async function doPreset(action: 'set' | 'goto' | 'clear') {
|
||
const camera = previewCamera.value;
|
||
if (!camera || ptzBusy.value) return;
|
||
|
||
ptzBusy.value = true;
|
||
try {
|
||
const cred = await ensureCred();
|
||
if (!cred) return;
|
||
|
||
await localWs.ptzPreset({
|
||
host: cred.host,
|
||
port: cred.port,
|
||
user: cred.username,
|
||
password: cred.password,
|
||
channel: camera.channelNo,
|
||
presetAction: action,
|
||
preset: Number(ptzPresetNo.value) || 1,
|
||
});
|
||
|
||
ptzError.value = '';
|
||
okMsg.value = action === 'goto'
|
||
? `已转到预置点 ${ptzPresetNo.value}`
|
||
: action === 'set' ? `已把当前位置存为预置点 ${ptzPresetNo.value}` : `已删除预置点 ${ptzPresetNo.value}`;
|
||
} catch (err) {
|
||
ptzError.value = err instanceof Error ? err.message : '预置点操作失败';
|
||
} finally {
|
||
ptzBusy.value = false;
|
||
}
|
||
}
|
||
|
||
</script>
|
||
|
||
<template>
|
||
<AppLayout fill>
|
||
<template #title>摄像头</template>
|
||
|
||
<div v-if="error" class="alert alert-error">{{ error }}</div>
|
||
<div v-if="okMsg" class="alert alert-ok">{{ okMsg }}</div>
|
||
|
||
<div class="card">
|
||
<div class="toolbar">
|
||
<select v-model="nvrFilter" @change="search">
|
||
<option value="">全部 NVR</option>
|
||
<option v-for="nvr in nvrs" :key="nvr.id" :value="nvr.id">
|
||
{{ nvr.name || nvr.host }}
|
||
</option>
|
||
</select>
|
||
<input v-model="keyword" placeholder="搜索 名称 / IP / 通道号" @keyup.enter="search" />
|
||
<button class="btn" :disabled="loading" @click="search">搜索</button>
|
||
<button class="btn btn-danger" :disabled="!selectedIds.size" @click="doBatchDelete">
|
||
批量删除{{ selectedIds.size ? `(${selectedIds.size})` : '' }}
|
||
</button>
|
||
<span class="hint">新增请到「NVR 录像机 → 拉取通道」;双击名称可直接改名</span>
|
||
</div>
|
||
|
||
<div class="table-wrap">
|
||
<table class="table table-list">
|
||
<thead>
|
||
<tr>
|
||
<th style="width: 36px">
|
||
<input type="checkbox" :checked="allChecked" @change="toggleAll" />
|
||
</th>
|
||
<th>名称</th>
|
||
<th>通道名</th>
|
||
<th>所属 NVR</th>
|
||
<th>通道号</th>
|
||
<th>类型</th>
|
||
<th>前端设备</th>
|
||
<th>状态</th>
|
||
<th style="width: 250px">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="camera in list" :key="camera.id" :class="{ 'row-selected': selectedIds.has(camera.id) }">
|
||
<td>
|
||
<input type="checkbox" :checked="selectedIds.has(camera.id)" @change="toggleOne(camera.id)" />
|
||
</td>
|
||
<td class="name-cell" :title="inlineId === camera.id ? '' : '双击可改名'" @dblclick="startRename(camera)">
|
||
<input v-if="inlineId === camera.id"
|
||
:ref="bindInlineInput"
|
||
v-model="inlineName"
|
||
class="inline-name-input"
|
||
:disabled="inlineSaving"
|
||
maxlength="64"
|
||
placeholder="输入名称后回车"
|
||
@keyup.enter="commitRename(camera)"
|
||
@keyup.esc="cancelRename"
|
||
@blur="commitRename(camera)" />
|
||
<span v-else :class="{ muted: !camera.name }">{{ camera.name || '—' }}</span>
|
||
</td>
|
||
<td :class="{ muted: !camera.channelName }">{{ camera.channelName || '未命名' }}</td>
|
||
<td>{{ camera.nvr ? (camera.nvr.name || camera.nvr.host) : '—' }}</td>
|
||
<td>{{ camera.channelNo }}</td>
|
||
<td>{{ camera.type === 'analog' ? '模拟' : '数字' }}</td>
|
||
<td class="mono-sm">{{ camera.ip ? `${camera.ip}${camera.port ? ':' + camera.port : ''}` : '—' }}</td>
|
||
<td>
|
||
<span :class="['badge', camera.status === 1 ? 'badge-ok' : 'badge-off']">
|
||
{{ camera.status === 1 ? '启用' : '停用' }}
|
||
</span>
|
||
</td>
|
||
<td>
|
||
<button class="btn btn-sm btn-primary" @click="openPreview(camera)">预览</button>
|
||
<button class="btn btn-sm btn-ghost" @click="openEdit(camera)">编辑</button>
|
||
<button class="btn btn-sm btn-ghost" @click="toggleStatus(camera)">
|
||
{{ camera.status === 1 ? '停用' : '启用' }}
|
||
</button>
|
||
<button class="btn btn-sm btn-danger" @click="doDelete(camera)">删除</button>
|
||
</td>
|
||
</tr>
|
||
<tr v-if="!list.length && !loading">
|
||
<td colspan="9" class="empty">还没有摄像头。请到「NVR 录像机」里拉取通道并勾选导入。</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<DataPager :page="page" :page-size="pageSize" :total="total" :loading="loading"
|
||
unit="个" @update:page="load" @update:page-size="size => (pageSize = size)" />
|
||
</div>
|
||
|
||
<ModalBox :open="editOpen" title="编辑摄像头" @close="editOpen = false">
|
||
<label class="field"><span>名称</span>
|
||
<input v-model="form.name" placeholder="例如:1号工作台正面" />
|
||
</label>
|
||
<label class="field"><span>状态</span>
|
||
<select v-model.number="form.status">
|
||
<option :value="1">启用</option>
|
||
<option :value="0">停用</option>
|
||
</select>
|
||
</label>
|
||
<label class="field"><span>备注</span>
|
||
<input v-model="form.remark" placeholder="可选" />
|
||
</label>
|
||
<p v-if="editing" class="hint">
|
||
所属 NVR:{{ editing.nvr?.name || editing.nvr?.host }} | 通道号:{{ editing.channelNo }}
|
||
| 设备通道名:{{ editing.channelName || '未命名' }}
|
||
</p>
|
||
<template #footer>
|
||
<button class="btn btn-ghost" @click="editOpen = false">取消</button>
|
||
<button class="btn" :disabled="saving" @click="save">{{ saving ? '保存中…' : '保存' }}</button>
|
||
</template>
|
||
</ModalBox>
|
||
|
||
<ModalBox :open="previewOpen" title="实时预览" width="820px" mask-closable @close="closePreview">
|
||
<div class="preview-head">
|
||
<strong>{{ previewCamera?.name || '通道 ' + previewCamera?.channelNo }}</strong>
|
||
<span class="hint">
|
||
{{ previewCamera?.nvr?.name || previewCamera?.nvr?.host }} | 通道 {{ previewCamera?.channelNo }}
|
||
<template v-if="previewData">| 码流 {{ previewData.streamId }} | 序号 {{ previewData.logicalChannel }}</template>
|
||
</span>
|
||
<span v-if="previewData" class="badge" :class="previewData.mode === 'capture' ? 'badge-off' : 'badge-ok'">
|
||
{{ previewModeLabel }}
|
||
</span>
|
||
</div>
|
||
|
||
<div v-if="previewError" class="alert alert-error">{{ previewError }}</div>
|
||
|
||
<div class="preview-stage">
|
||
<canvas ref="previewCanvas" class="preview-canvas" aria-label="实时画面" />
|
||
<div v-if="previewLoading" class="preview-tip">正在连接设备…</div>
|
||
<div v-else-if="!previewHasFrame" class="preview-tip">暂无画面</div>
|
||
</div>
|
||
|
||
<div class="preview-toolbar">
|
||
<label>
|
||
画面
|
||
<select :value="previewStreamType" @change="switchStreamType(Number(($event.target as HTMLSelectElement).value))">
|
||
<option :value="0">主码流(高清)</option>
|
||
<option :value="1">子码流(流畅)</option>
|
||
</select>
|
||
</label>
|
||
<label>
|
||
内嵌帧率
|
||
<select :value="previewFps" @change="setPreviewFps(Number(($event.target as HTMLSelectElement).value))">
|
||
<option :value="5">5 fps</option>
|
||
<option :value="10">10 fps</option>
|
||
<option :value="15">15 fps</option>
|
||
<option :value="25">25 fps(满帧)</option>
|
||
</select>
|
||
</label>
|
||
<button class="btn btn-sm btn-primary" @click="openFullRateWindow">满帧率窗口(25fps)</button>
|
||
<span v-if="previewData" class="preview-rtsp mono-sm" :title="maskedRtsp(previewData.rtspUrl)">
|
||
{{ maskedRtsp(previewData.rtspUrl) }}
|
||
</span>
|
||
<button v-if="previewData" class="btn btn-sm btn-ghost" @click="copyRtsp">复制 RTSP</button>
|
||
</div>
|
||
|
||
<p class="hint preview-note">
|
||
主码流:ffmpeg 转码后经 WebSocket 推流(缩到 1280 宽,约 25fps);子码流:SDK 取流解码(640×360,25fps)。
|
||
想要主码流原生分辨率且不经转码,用「满帧率窗口」。
|
||
</p>
|
||
|
||
<!-- 云台:所有摄像头都显示方向盘;不支持云台的通道点击无效也属正常 -->
|
||
<div v-if="previewCamera" class="ptz">
|
||
<div class="ptz-pad">
|
||
<button class="ptz-btn" title="左上" @pointerdown.prevent="ptzHoldStart('up-left')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">↖</button>
|
||
<button class="ptz-btn" title="上" @pointerdown.prevent="ptzHoldStart('up')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">↑</button>
|
||
<button class="ptz-btn" title="右上" @pointerdown.prevent="ptzHoldStart('up-right')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">↗</button>
|
||
<button class="ptz-btn" title="左" @pointerdown.prevent="ptzHoldStart('left')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">←</button>
|
||
<button class="ptz-btn ptz-stop" title="停止" @click="ptzHoldStop">停</button>
|
||
<button class="ptz-btn" title="右" @pointerdown.prevent="ptzHoldStart('right')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">→</button>
|
||
<button class="ptz-btn" title="左下" @pointerdown.prevent="ptzHoldStart('down-left')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">↙</button>
|
||
<button class="ptz-btn" title="下" @pointerdown.prevent="ptzHoldStart('down')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">↓</button>
|
||
<button class="ptz-btn" title="右下" @pointerdown.prevent="ptzHoldStart('down-right')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">↘</button>
|
||
</div>
|
||
|
||
<div class="ptz-side">
|
||
<div class="ptz-row">
|
||
<span class="ptz-label">变倍</span>
|
||
<button class="btn btn-sm" @pointerdown.prevent="ptzHoldStart('zoom-in')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">+</button>
|
||
<button class="btn btn-sm" @pointerdown.prevent="ptzHoldStart('zoom-out')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">-</button>
|
||
</div>
|
||
<div class="ptz-row">
|
||
<span class="ptz-label">聚焦</span>
|
||
<button class="btn btn-sm" @pointerdown.prevent="ptzHoldStart('focus-near')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">近</button>
|
||
<button class="btn btn-sm" @pointerdown.prevent="ptzHoldStart('focus-far')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">远</button>
|
||
</div>
|
||
<div class="ptz-row">
|
||
<span class="ptz-label">光圈</span>
|
||
<button class="btn btn-sm" @pointerdown.prevent="ptzHoldStart('iris-open')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">开</button>
|
||
<button class="btn btn-sm" @pointerdown.prevent="ptzHoldStart('iris-close')" @pointerup="ptzHoldStop" @pointerleave="ptzHoldStop" @pointercancel="ptzHoldStop">关</button>
|
||
<button class="btn btn-sm" :class="ptzAuto ? 'btn-primary' : ''" @click="togglePtzAuto">
|
||
{{ ptzAuto ? '停止巡航' : '自动扫描' }}
|
||
</button>
|
||
</div>
|
||
<div class="ptz-row">
|
||
<span class="ptz-label">速度</span>
|
||
<select v-model.number="ptzSpeed">
|
||
<option v-for="n in 7" :key="n" :value="n">{{ n }}</option>
|
||
</select>
|
||
</div>
|
||
<div class="ptz-row">
|
||
<span class="ptz-label">预置点</span>
|
||
<input v-model.number="ptzPresetNo" type="number" min="1" max="256" class="ptz-preset" />
|
||
<button class="btn btn-sm" :disabled="ptzBusy" @click="doPreset('goto')">调用</button>
|
||
<button class="btn btn-sm btn-ghost" :disabled="ptzBusy" @click="doPreset('set')">设置</button>
|
||
<button class="btn btn-sm btn-ghost" :disabled="ptzBusy" @click="doPreset('clear')">删除</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p v-if="ptzError" class="hint warn">{{ ptzError }}</p>
|
||
<p v-else-if="previewCamera" class="hint tiny">
|
||
按暂停住方向键转动,松开即停;没有云台的通道点击无效属正常现象。
|
||
</p>
|
||
<p v-if="previewWinMsg" class="hint preview-win">{{ previewWinMsg }}</p>
|
||
|
||
<template #footer>
|
||
<button class="btn btn-ghost" @click="closePreview">关闭</button>
|
||
</template>
|
||
</ModalBox>
|
||
|
||
<!-- 连不上本机软件:统一的「启动 / 下载」提示窗,就绪后自动重开预览 -->
|
||
<LocalServiceGate
|
||
:open="previewOffline"
|
||
title="实时预览需要本机软件"
|
||
message="实时画面由本机软件从设备 8000 端口取流并推送,浏览器无法直连。"
|
||
@close="previewOffline = false"
|
||
@ready="retryPreview"
|
||
/>
|
||
</AppLayout>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.mono-sm {
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.empty {
|
||
text-align: center;
|
||
color: #94a3b8;
|
||
padding: 28px 0;
|
||
}
|
||
|
||
.row-selected {
|
||
background: #f1f5f9;
|
||
}
|
||
|
||
.muted {
|
||
color: #cbd5e1;
|
||
}
|
||
|
||
/* 列表内改名:名称列双击变成输入框(同一行的 td 高度稳定,不跳动) */
|
||
.name-cell {
|
||
cursor: text;
|
||
min-width: 140px;
|
||
}
|
||
|
||
.inline-name-input {
|
||
width: 100%;
|
||
min-width: 120px;
|
||
padding: 3px 6px;
|
||
font-size: 13px;
|
||
line-height: 1.4;
|
||
border: 1px solid #2563eb;
|
||
border-radius: 4px;
|
||
outline: none;
|
||
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
|
||
}
|
||
|
||
.preview-head {
|
||
display: flex;
|
||
align-items: baseline;
|
||
gap: 10px;
|
||
flex-wrap: wrap;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.preview-stage {
|
||
position: relative;
|
||
background: #0f172a;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
aspect-ratio: 16 / 9;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.preview-canvas {
|
||
width: 100%;
|
||
height: 100%;
|
||
display: block;
|
||
}
|
||
|
||
/* 提示浮在画布上:画布始终挂着(只画不重建),有无画面靠提示层说明 */
|
||
.preview-tip {
|
||
position: absolute;
|
||
inset: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #94a3b8;
|
||
font-size: 13px;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.preview-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
margin-top: 10px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.preview-toolbar label {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
font-size: 13px;
|
||
color: #475569;
|
||
}
|
||
|
||
.preview-rtsp {
|
||
flex: 1;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
color: #64748b;
|
||
}
|
||
|
||
.preview-note {
|
||
margin: 6px 0 0;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.preview-win {
|
||
margin: 4px 0 0;
|
||
color: #15803d;
|
||
}
|
||
|
||
.hint.warn {
|
||
color: #b45309;
|
||
}
|
||
|
||
.hint.tiny {
|
||
font-size: 12px;
|
||
color: #94a3b8;
|
||
}
|
||
|
||
.field-check {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.field-check span {
|
||
color: #475569;
|
||
font-size: 13px;
|
||
}
|
||
|
||
/* ---- 云台方向盘 ---- */
|
||
.ptz {
|
||
display: flex;
|
||
gap: 16px;
|
||
flex-wrap: wrap;
|
||
margin-top: 12px;
|
||
padding: 12px;
|
||
background: #f8fafc;
|
||
border: 1px solid #e2e8f0;
|
||
border-radius: 8px;
|
||
}
|
||
|
||
.ptz-pad {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 40px);
|
||
grid-template-rows: repeat(3, 40px);
|
||
gap: 6px;
|
||
}
|
||
|
||
.ptz-btn {
|
||
border: 1px solid #cbd5e1;
|
||
background: #fff;
|
||
border-radius: 6px;
|
||
font-size: 16px;
|
||
line-height: 1;
|
||
cursor: pointer;
|
||
color: #334155;
|
||
user-select: none;
|
||
}
|
||
|
||
.ptz-btn:hover {
|
||
background: #eef2ff;
|
||
border-color: #a5b4fc;
|
||
}
|
||
|
||
.ptz-btn:active {
|
||
background: #e0e7ff;
|
||
}
|
||
|
||
.ptz-stop {
|
||
font-size: 13px;
|
||
color: #b91c1c;
|
||
border-color: #fecaca;
|
||
background: #fff5f5;
|
||
}
|
||
|
||
.ptz-side {
|
||
flex: 1;
|
||
min-width: 260px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.ptz-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
|
||
.ptz-label {
|
||
width: 44px;
|
||
font-size: 12px;
|
||
color: #64748b;
|
||
}
|
||
|
||
.ptz-preset {
|
||
width: 70px;
|
||
}
|
||
|
||
.ptz-row select {
|
||
padding: 2px 6px;
|
||
}
|
||
</style>
|