You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

474 lines
15 KiB

2 years ago
<template>
<div id="videoWrapper">
2 years ago
<!-- <video ref="videoPlayer" id="videoPlayer" disablePictureInPicture autoplay muted
@loadedmetadata="changeVideoCanvasSize" @mouseover="mouseOverVideo" @mouseout="mouseOutVideo"
@mousedown="mouseDownVideo">
2 years ago
</video> -->
<div id="videoPlayer" @mousedown="mouseDownVideo"></div>
2 years ago
<div v-for="item in labelList" :class="`labels ${item.groupName == '视频标签' ? 'lavels-video' : 'lavels-build'}`"
2 years ago
:key="item.id" :id="item.id"
2 years ago
:style="`top:${canvasHeight * item.canvasTopRatio}px;left:${canvasWidth * item.canvasLeftRatio}px`">
<a-dropdown :trigger="['contextmenu']">
2 years ago
<div class="labels-item" v-if="item.groupName == '视频标签'">
<!-- <div class="labels-item" v-if="item.inFlag"> -->
<div>
<img src="@/assets/images/dialog.png" alt="">
<div class="label-content">{{ item.name }}</div>
</div>
</div>
2 years ago
<div class="labels-item" alt="" v-else>
<img src="@/assets/images/buildLabelLine.png">
<div>
<img src="@/assets/images/buildLabelBg.png">
2 years ago
<div class="label-content">{{ item.name }}</div>
2 years ago
</div>
</div>
<template #overlay>
2 years ago
<a-menu @click="({ key: menuKey }) => onContextMenuClick(item, menuKey)">
<a-menu-item key="edit">编辑</a-menu-item>
<a-menu-item key="delete">删除</a-menu-item>
</a-menu>
</template>
</a-dropdown>
2 years ago
</div>
2 years ago
<div class="labels lavels-build" v-if="addLabel.isAddLabel && addLabel.labelType == '建筑标签'"
:style="` pointer-events: none;top:${addLabelTop}px;left:${addLabelLeft}px`">
<div class="labels-item" alt="">
<img src="@/assets/images/buildLabelLine.png">
<div>
<img src="@/assets/images/buildLabelBg.png">
<div class="label-content">{{ addLabel.labelType }}</div>
</div>
</div>
</div>
2 years ago
<div class="labels lavels-video" v-if="addLabel.isAddLabel && addLabel.labelType == '视频标签'"
:style="`top:${addLabelTop}px;left:${addLabelLeft}px`">
<div class="labels-item">
<!-- <div class="labels-item" v-if="item.inFlag"> -->
<div>
<img src="@/assets/images/dialog.png" alt="">
<div class="label-content">{{ addLabel.labelType }}</div>
</div>
2 years ago
</div>
</div>
<CameraLeftMenu></CameraLeftMenu>
<CameraRightMenu></CameraRightMenu>
2 years ago
<!-- 云台控制 -->
2 years ago
<VideoControlSimple></VideoControlSimple>
2 years ago
</div>
</template>
<script setup lang='ts'>
////@ts-nocheck
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal } from 'ant-design-vue';
import { ref, h, onMounted, getCurrentInstance, ComponentInternalInstance, onUnmounted, watch, createVNode } from "vue";
2 years ago
import * as markLabelApi from '@/axios/cameraMark/markLabelApi';
import * as markSearchApi from '@/axios/core/markSearchApi';
import { useStore } from '@/store/index';
import { apiUrl } from "@/axios";
2 years ago
import { storeToRefs } from 'pinia';
2 years ago
import Msg from "@/utils/message";
import CameraLeftMenu from '@/views/page/Aside/cameraLeftMenu.vue'
import CameraRightMenu from '@/views/page/Aside/cameraRightMenu.vue'
import LabelEditModel from '@/views/page/Model/LabelEditModel.vue'
import popup from "@/utils/popup";
2 years ago
import VideoControlSimple from './VideoControl/VideoControlSimple.vue';
2 years ago
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
let piniaStore = useStore();
let player = <HTMLVideoElement>document.querySelector('#videoPlayer')
let canvasWidth = ref(0)
let canvasHeight = ref(0)
let curSelectKey = storeToRefs(piniaStore).curSelectKey
let closeVideoKey = storeToRefs(piniaStore).closeVideoKey
2 years ago
let cameraMap = storeToRefs(piniaStore).cameraMap
let isActiveChoose = ref(false)
2 years ago
let labelList = ref<any[]>([])
let addLabel = storeToRefs(piniaStore).addLabel
let addLabelLeft = ref(0);
let addLabelTop = ref(0);
2 years ago
var jessibuca = ref();
const curVideoKey = ref()
2 years ago
onMounted(() => {
{
player = <HTMLVideoElement>document.querySelector('#videoPlayer');
loadVideoPlayer();
loadVideoCanvas();
2 years ago
changeVideoCanvasSize();
create()
}
})
watch(curSelectKey, (newVal, oldVal) => {
switchCamera(newVal)
})
watch(closeVideoKey, (newVal, oldVal) => {
if (curVideoKey.value == newVal) {
destroyVideo()
piniaStore.updateCloseVideoKey("")
piniaStore.updateCurSelectKey("")
}
})
watch(addLabel, (newVal, oldVal) => {
if (newVal.isAddLabel) {
isActiveChoose.value = true
document.body.onmousemove = (e) => {
addLabelTop.value = e.clientY
addLabelLeft.value = e.clientX
}
}
})
function destroyVideo() {
jessibuca.value.destroy();
create()
labelList.value = []
}
//创建流媒体
function create() {
var showOperateBtns = false; // 是否显示按钮
var forceNoOffscreen = true; //
jessibuca.value = new Jessibuca({
container: player,
videoBuffer: 1, // 缓存时长
isResize: false,
text: "",
loadingText: "",
useMSE: false,
debug: false,
showBandwidth: showOperateBtns, // 显示网速
operateBtns: {
fullscreen: showOperateBtns,
screenshot: showOperateBtns,
play: showOperateBtns,
audio: false,
recorder: false
},
forceNoOffscreen: forceNoOffscreen,
isNotMute: false,
},);
jessibuca.value.onLog = (msg: any) => console.error(msg);
jessibuca.value.onRecord = (status: any) => console.log('onRecord', status);
jessibuca.value.onPause = () => console.log('onPause');
jessibuca.value.onPlay = () => console.log('onPlay');
jessibuca.value.onFullscreen = (msg: any) => console.log('onFullscreen', msg);
jessibuca.value.onMute = (msg: any) => console.log('onMute', msg);
}
//删除标签
function deleteLabel(id: number) {
2 years ago
markLabelApi.Delete({ id }).then((res: any) => {
2 years ago
console.log(res.data);
2 years ago
if (res.data.code == 200) {
let msg = res.data.data == true ? "删除成功" : "删除失败"
if (res.data.data) {
labelList.value = labelList.value.filter((element: any) => {
return element.id != id
2 years ago
});
Msg.success("删除成功")
return
}
}
Msg.error("删除失败")
})
}
2 years ago
function loadVideoPlayer() {
let elmId = 'videoPlayer';
let url = apiUrl.WebRtcUrl;
2 years ago
// webRtcServer.value = new WebRtcStreamer(elmId, url);
2 years ago
}
function loadVideoCanvas() {
window.addEventListener('resize', () => {
changeVideoCanvasSize();
});
}
2 years ago
const onContextMenuClick = (item: any, menuKey: string,) => {
console.log(`labelId: ${item.id}, menuKey: ${menuKey}`);
// console.log(`item: ${item}`);
2 years ago
// console.log(item);
//防止添加多个key值,再次点击不能关闭。数组去重
if (menuKey == "edit") {
popup("编辑标签", [h(LabelEditModel, { modelData: item })], "editLabel");
} else if (menuKey == "delete") {
Modal.confirm({
zIndex: 10000,
title: () => "警示",
icon: () => createVNode(ExclamationCircleOutlined),
content: () =>
h(
"span",
{ style: { color: "black" } },
"是否确认删除该标签?"
),
okText:
// () => h('span', { style: { color: 'black' } }, '确定'),
"确定",
// okType: 'primary',
cancelText: () => "取消",
cancelButtonProps: {
type: "default",
danger: true,
},
okButtonProps: {
type: "primary",
danger: true,
},
onOk() {
2 years ago
deleteLabel(parseInt(item.id))
},
style: "top: 250px",
});
}
};
2 years ago
function changeVideoCanvasSize() {
canvasWidth.value = player.clientWidth;
canvasHeight.value = player.clientHeight;
}
function mouseDownVideo(e: MouseEvent) {
2 years ago
if (!isActiveChoose.value) return;
//鼠标左键 e.buttons == 1
if (e.buttons == 1) {
let cameraId = cameraMap.value.get(curSelectKey.value).id;
let name = addLabel.value.labelType;
let videoWidth = player.videoWidth | 1920;
let videoHeight = player.videoHeight | 1080;
let canvasWidth = player.clientWidth;
let canvasHeight = player.clientHeight;
2 years ago
let canvasLeft = addLabelLeft.value;
let canvasTop = addLabelTop.value;
let canvasLeftRatio = canvasLeft / canvasWidth;
let canvasTopRatio = canvasTop / canvasHeight;
let entity = {
CbCameraId: cameraId,
Name: name,
VideoWidth: videoWidth,
VideoHeight: videoHeight,
CanvasLeftRatio: canvasLeftRatio,
CanvasTopRatio: canvasTopRatio,
2 years ago
CmMarkGroupId: addLabel.value.cmMarkGroupId
}
markLabelApi.AddReturnId({
'entity': entity
2 years ago
}).then((res: any) => {
let markLabelId: number = res.data.data;
console.log(markLabelId);
2 years ago
if (markLabelId <= 0) return;
markSearchApi.ActivateMarkLabel({
'cameraId': cameraId,
'markLabelId': markLabelId
}).then((res: any) => {
let ret: boolean = res.data.data;
console.log(ret, 'ret');
if (ret) {
let obj = {
cbCameraId: cameraId,
videoWidth: videoWidth,
videoHeight: videoHeight,
canvasLeftRatio: canvasLeftRatio,
canvasTopRatio: canvasTopRatio,
id: markLabelId,
isDelete: false,
inFlag: true,
name: name,
2 years ago
groupName: name
}
labelList.value.push(obj)
isActiveChoose.value = false
2 years ago
piniaStore.updateIsAddLabel({ cmMarkGroupId: 0, labelType: "", isAddLabel: false })
}
});
})
} else {
//右键取消
isActiveChoose.value = false
2 years ago
piniaStore.updateIsAddLabel({ cmMarkGroupId: 0, labelType: "", isAddLabel: false })
}
2 years ago
}
2 years ago
function switchCamera(cameraId: string) {
console.log('camera switch.', cameraId, typeof cameraId);
2 years ago
// step1, get camera obj.
console.log('get camera obj.', cameraMap.value);
2 years ago
let cameraObj = cameraMap.value.get(cameraId);
console.log(cameraObj, 'cameraObj');
2 years ago
if (!cameraObj) {
console.log('camera obj not found.');
2 years ago
return;
}
destroyVideo()
2 years ago
console.log('connect webrtc-steamer.');
jessibuca.value.play("ws://192.168.1.117:8080/jessica/live/test.flv")
curVideoKey.value = cameraId
2 years ago
// step4, active camera searcher.
markSearchApi.IsExistsSearcher({
'cameraId': cameraObj.id
}).then((res: any) => {
let flag: boolean = res.data.data;
if (!flag) {
console.log('not exist searcher.');
markSearchApi.ActiveSearcher({
'cameraId': cameraObj.id
}).then((res: any) => {
let flag: boolean = res.data.data;
console.log('activate searcher : ', flag);
if (flag) {
console.log('load camera labels');
getLabel(cameraObj.id)
loadMarkLabelsByLoop(cameraObj);
2 years ago
2 years ago
}
});
} else {
console.log('load camera labels');
getLabel(cameraObj.id)
loadMarkLabelsByLoop(cameraObj);
}
})
// step5, load camera labels.
}
2 years ago
function getLabel(cbCameraId: string | number) {
2 years ago
let str = JSON.stringify({ cbCameraId })
markLabelApi.GetList({ queryJson: str }).then((res: any) => {
2 years ago
if (res.data.code == 200) {
console.log(res, 'res');
labelList.value = res.data.data
2 years ago
labelList.value = labelList.value.map((item: any) => {
let labelGroupList = piniaStore.labelGroupList
labelGroupList.forEach((element: any) => {
if (element.id == item.cmMarkGroupId) {
item.groupName = element.name
}
});
return item
})
console.log(labelList.value, 'labelList.value');
2 years ago
}
})
}
function loadMarkLabelsByLoop(cameraObj: any, ms: number = 1000) {
if (curSelectKey.value !== cameraObj.id) {
console.log('load camera labels end.');
return;
}
loadMarkLabels(cameraObj);
let timer = setTimeout(() => {
2 years ago
loadMarkLabelsByLoop(cameraObj, ms);
clearTimeout(timer)
2 years ago
}, ms);
}
function loadMarkLabels(cameraObj: any) {
markSearchApi.GetMarkLabelCalcResultList({
'cameraId': cameraObj.id
}).then((res: any) => {
let list: Array<any> = res.data.data;
console.log(list);
2 years ago
list.forEach((element: any) => {
labelList.value.forEach((item: any, index: number) => {
if (element.id == item.id) {
labelList.value[index].canvasLeftRatio = element.canvasLeftRatio
labelList.value[index].canvasTopRatio = element.canvasTopRatio
labelList.value[index].inFlag = element.inFlag
2 years ago
}
2 years ago
2 years ago
});
});
2 years ago
2 years ago
});
}
//刷新页面
window.onbeforeunload = () => {
jessibuca.value.destroy()
};
2 years ago
onUnmounted(() => {
{
jessibuca.value.destroy()
2 years ago
}
})
</script>
<style scoped lang='less'>
#videoWrapper {
height: 100vh;
position: relative;
overflow: hidden;
2 years ago
#videoPlayer {
height: 100%;
width: 100%;
object-fit: fill;
2 years ago
2 years ago
}
2 years ago
.labels {
2 years ago
position: absolute;
top: 0;
left: 0;
z-index: 2;
2 years ago
.labels-item {
2 years ago
position: relative;
2 years ago
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
2 years ago
>div {
position: relative;
}
.label-content {
2 years ago
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -55%);
}
img {
width: 120px;
height: 50px;
2 years ago
}
}
}
2 years ago
.lavels-video {
position: fixed;
transform: translate(-50%, -100%);
}
2 years ago
.lavels-build {
2 years ago
2 years ago
transform: translate(-10px, -10px);
position: fixed;
}
}
:deep(.ant-dropdown-menu-title-content) {
color: #000 !important;
}
</style>