From feaf0a9778879ef211c5587a513ba4cbdabb52d0 Mon Sep 17 00:00:00 2001
From: ZZJ <10913410+zzj2100@user.noreply.gitee.com>
Date: 星期四, 23 六月 2022 17:42:58 +0800
Subject: [PATCH] bug修复
---
src/components/player/index.vue | 419 ++++++++++++++++++++++++++---------------------------------
1 files changed, 188 insertions(+), 231 deletions(-)
diff --git a/src/components/player/index.vue b/src/components/player/index.vue
index 1d8e80b..93e9342 100644
--- a/src/components/player/index.vue
+++ b/src/components/player/index.vue
@@ -1,6 +1,12 @@
<template>
<div class="video-player">
- <canvas id="area-canvas" ref="areaCanvas" ></canvas>
+ <canvas
+ v-show="showArea"
+ id="area-canvas"
+ ref="areaCanvas"
+ width="960"
+ height="540"
+ ></canvas>
<video ref="videoPlayer" :poster="poster" preload="auto" muted></video>
<div class="controls">
<!-- 鍏ㄥ睆 -->
@@ -20,101 +26,121 @@
wsAddr: {
type: String,
// default: "ws://192.168.1.182:10101/ws"
- default: `${location.protocol === "https" ? "wss" : "ws"}://${location.host}/ws`
+ default: `${location.protocol === "https" ? "wss" : "ws"}://${
+ location.host
+ }/ws`,
},
cameraName: {
type: String,
- default: ""
+ default: "",
},
cameraID: {
type: String,
- default: "C4668FD0-3CAE-C31F-C21E-28B7001243C4"
+ default: "C4668FD0-3CAE-C31F-C21E-28B7001243C4",
},
rtspUrl: {
type: String,
- default: "rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream"
+ default:
+ "rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream",
},
isRunning: {
type: Boolean,
- default: false
+ default: false,
},
isGb: {
type: Boolean,
- default: false
- }
+ default: false,
+ },
+ showArea: {
+ type: Boolean,
+ default: false,
+ },
+ hasPoster: {
+ type: Boolean,
+ default: true,
+ },
},
-
- computed: {
- poster() {
- return "/images/player/player_poster.gif?t=" + Math.random()
- }
+ computed: {
+ // poster() {
+ // return "/images/player/player_poster.gif?t=" + Math.random()
+ // }
},
data() {
return {
wfs: {},
+ poster: "/images/player/player_poster.gif?t=" + Math.random(),
wfsId: 0,
- Camera: new VideoRuleData(),
+ Camera: new VideoRuleData(this.isGb),
showCanvas: true,
canvasData: {
line: [],
rect: [], // {id:'uuid', name: '鐭╁舰1', location: [{ x: 20, y: 30 }, { x: 20, y: 60 }, { x: 100, y: 60 }, { x: 100, y: 30 }] }
arrow: [],
- polygon: []
+ polygon: [],
},
- showProportion: 3.2,
- showProportionY: 3.58,
+ //showProportion: 3.2,
+ //showProportionY: 3.58,
+ // showProportion: 1.036,
+ // showProportionY: 1.039,
+ showProportion: 1,
+ showProportionY: 1,
canvas: null,
- ctx: null
+ ctx: null,
+ canvasWidth: 0,
+ canvasHeight: 0,
+ algoDataSocket: null,
};
},
watch: {
- // "TreeDataPool.selectedNode": async function(node){
- // if(node){
- // console.log('TreeDataPool.selectedNode')
- // console.log(node)
- // //this.Camera.cameraId = node.id;
- // const res = await getAllPolygon({cameraId: node.id});
-
- // this.canvasData.line = res.data.line;
- // this.canvasData.rect = res.data.rect;
- // this.canvasData.arrow = res.data.arrow;
- // this.canvasData.polygon = res.data.polygon;
- // console.log(this.canvasData)
- // this.clickSelect(this.canvasData);
- // }
- // },
-
rtspUrl: function (newVal, oldVal) {
+ console.log("new rstp: ", newVal);
if (newVal !== oldVal) {
if (this.wfs.config) {
this.wfs.destroy();
+ !!this.algoDataSocket && this.algoDataSocket.close();
}
this.$nextTick(() => {
this.clickStart();
+ this.poster = "/images/player/player_poster.gif?t=" + Math.random();
});
}
- }
+ },
+ },
+ mounted() {
+ this.clickStart();
+ this.$nextTick(() => {
+ this.canvas = this.$refs.areaCanvas;
+ this.ctx = this.canvas.getContext("2d");
+ this.ctx.lineWidth = 1;
+ this.initArea();
+ });
+ },
+ beforeDestroy() {
+ this.wfs.destroy();
+ this.wfsId = "";
+
+ !!this.algoDataSocket && this.algoDataSocket.close();
},
methods: {
checkConnect(id) {
// console.log(this.wfs)
if (id !== this.wfsId) {
- return
+ return;
}
if (this.wfs.websocketLoader && this.wfs.websocketLoader.client) {
if (this.wfs.websocketLoader.client.disconnected) {
this.clickStart();
- console.log("瀹炴椂瑙嗛宸叉柇寮�锛屾鍦ㄩ噸杩�")
- return
+ console.log("瀹炴椂瑙嗛宸叉柇寮�锛屾鍦ㄩ噸杩�");
+ return;
}
}
let _this = this;
setTimeout(() => {
- _this.checkConnect(id)
- }, 10000)
+ _this.checkConnect(id);
+ }, 10000);
},
clickStart() {
if (this.rtspUrl == "") {
@@ -125,14 +151,13 @@
if (cameraId == "") {
cameraId = this.getUuid();
}
-
if (Wfs.isSupported()) {
let wsAddr = this.wsAddr;
let cameraInfo = {
cameraID: cameraId,
rtspUrl: this.rtspUrl,
isRunning: this.isRunning,
- isGb28181: this.isGb
+ isGb28181: this.isGb,
};
// let camera = document.getElementById(this.cameraID);
@@ -142,7 +167,7 @@
this.wfsId = randomId;
this.wfs.attachMedia(camera, "chX", "H264Raw", wsAddr, cameraInfo);
- this.checkConnect(randomId)
+ this.checkConnect(randomId);
}
},
getUuid() {
@@ -168,80 +193,45 @@
_this.canvasData.line.forEach(function (v, i) {
_this.ctx.strokeStyle = "yellow";
_this.ctx.beginPath();
- _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion);
- _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion);
- _this.ctx.stroke();
- _this.showRemarks(
+ _this.ctx.moveTo(
v.location[0].x / _this.showProportion,
- v.location[0].y / _this.showProportion,
- v.name
+ v.location[0].y / _this.showProportion
);
+ _this.ctx.lineTo(
+ v.location[1].x / _this.showProportion,
+ v.location[1].y / _this.showProportion
+ );
+ _this.ctx.stroke();
_this.canvas.style.cursor = "default";
- if (e && _this.ctx.isPointInStroke(e.offsetX, e.offsetY)) {
- // 濡傛灉浼犲叆浜嗕簨浠跺潗鏍囷紝灏辩敤isPointInStroke鍒ゆ柇涓�涓�
- // 濡傛灉褰撳墠鐜瑕嗙洊浜嗚鍧愭爣锛屽氨灏嗗浘褰㈢殑index鏀惧埌鏁扮粍閲�
- // 褰撻紶鏍囩Щ鍏ヤ箣鍚庡皢褰撳墠鐨勬ā寮忓垏鎹负閫変腑妯″紡
- _this.type = "0";
- _this.delCursor.type = "1";
- _this.delCursor.index = i;
- // 灏嗗綋鍓嶅厓绱犳爣绾�
- _this.ctx.strokeStyle = "red";
- _this.ctx.beginPath();
- _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion);
- _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion);
- _this.ctx.stroke();
- _this.showRemarks(
- v.location[0].x / _this.showProportion,
- v.location[0].y / _this.showProportion,
- v.name
- );
- _this.canvas.style.cursor = "pointer";
- }
});
_this.canvasData.rect.forEach(function (v, i) {
_this.ctx.strokeStyle = "yellow";
_this.ctx.beginPath();
- _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion);
- _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion);
- _this.ctx.lineTo(v.location[2].x / _this.showProportion, v.location[2].y / _this.showProportion);
- _this.ctx.lineTo(v.location[3].x / _this.showProportion, v.location[3].y / _this.showProportion);
- _this.ctx.lineTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion);
- _this.ctx.stroke();
- _this.showRemarks(
+ _this.ctx.moveTo(
v.location[0].x / _this.showProportion,
- v.location[0].y / _this.showProportion,
- v.name
+ v.location[0].y / _this.showProportion
);
+ _this.ctx.lineTo(
+ v.location[1].x / _this.showProportion,
+ v.location[1].y / _this.showProportion
+ );
+ _this.ctx.lineTo(
+ v.location[2].x / _this.showProportion,
+ v.location[2].y / _this.showProportion
+ );
+ _this.ctx.lineTo(
+ v.location[3].x / _this.showProportion,
+ v.location[3].y / _this.showProportion
+ );
+ _this.ctx.lineTo(
+ v.location[0].x / _this.showProportion,
+ v.location[0].y / _this.showProportion
+ );
+ _this.ctx.stroke();
_this.canvas.style.cursor = "default";
- if (e && _this.ctx.isPointInPath(e.offsetX, e.offsetY)) {
- // 濡傛灉浼犲叆浜嗕簨浠跺潗鏍囷紝灏辩敤isPointInStroke鍒ゆ柇涓�涓�
- // 褰撻紶鏍囩Щ鍏ヤ箣鍚庡皢褰撳墠鐨勬ā寮忓垏鎹负閫変腑妯″紡
- _this.type = "0";
- _this.delCursor.type = "2";
- _this.delCursor.index = i;
- // 灏嗗綋鍓嶅厓绱犳爣绾�
- _this.ctx.strokeStyle = "red";
- _this.ctx.beginPath();
- _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion);
- _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion);
- _this.ctx.lineTo(v.location[2].x / _this.showProportion, v.location[2].y / _this.showProportion);
- _this.ctx.lineTo(v.location[3].x / _this.showProportion, v.location[3].y / _this.showProportion);
- _this.ctx.lineTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion);
- _this.ctx.stroke();
- _this.showRemarks(
- v.location[0].x / _this.showProportion,
- v.location[0].y / _this.showProportion,
- v.name
- );
- _this.canvas.style.cursor = "pointer";
- }
});
_this.canvasData.arrow.forEach(function (v, i) {
_this.ctx.strokeStyle = "yellow";
- // _this.ctx.beginPath()
- // _this.ctx.moveTo(v.location[0].x / 2, v.location[0].y / 2)
- // _this.ctx.lineTo(v.location[1].x / 2, v.location[1].y / 2)
- // _this.ctx.stroke()
_this.drawArrow(
_this.ctx,
v.location[0].x / _this.showProportion,
@@ -251,43 +241,8 @@
20,
30,
"yellow"
- ); // 缁樺埗鏂规硶
- _this.showRemarks(
- v.location[0].x / _this.showProportion,
- v.location[0].y / _this.showProportion,
- v.name
);
_this.canvas.style.cursor = "default";
- if (e && _this.ctx.isPointInStroke(e.offsetX, e.offsetY)) {
- // 濡傛灉浼犲叆浜嗕簨浠跺潗鏍囷紝灏辩敤isPointInStroke鍒ゆ柇涓�涓�
- // 濡傛灉褰撳墠鐜瑕嗙洊浜嗚鍧愭爣锛屽氨灏嗗浘褰㈢殑index鏀惧埌鏁扮粍閲�
- // 褰撻紶鏍囩Щ鍏ヤ箣鍚庡皢褰撳墠鐨勬ā寮忓垏鎹负閫変腑妯″紡
- _this.type = "0";
- _this.delCursor.type = "4";
- _this.delCursor.index = i;
- // 灏嗗綋鍓嶅厓绱犳爣绾�
- _this.ctx.strokeStyle = "red";
- // _this.ctx.beginPath()
- // _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion)
- // _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion)
- // _this.ctx.stroke()
- _this.drawArrow(
- _this.ctx,
- v.location[0].x / _this.showProportion,
- v.location[0].y / _this.showProportion,
- v.location[1].x / _this.showProportion,
- v.location[1].y / _this.showProportion,
- 20,
- 30,
- "red"
- ); // 缁樺埗鏂规硶
- _this.showRemarks(
- v.location[0].x / _this.showProportion,
- v.location[0].y / _this.showProportion,
- v.name
- );
- _this.canvas.style.cursor = "pointer";
- }
});
_this.canvasData.polygon.forEach(function (v, i) {
if (v.location.length === 0) {
@@ -295,43 +250,74 @@
}
_this.ctx.strokeStyle = "yellow";
_this.ctx.beginPath();
- _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportionY);
+ _this.ctx.moveTo(
+ v.location[0].x / _this.showProportion,
+ v.location[0].y / _this.showProportionY
+ );
for (let i = 1; i < v.location.length; i++) {
- _this.ctx.lineTo(v.location[i].x / _this.showProportion, v.location[i].y / _this.showProportionY);
+ _this.ctx.lineTo(
+ v.location[i].x / _this.showProportion,
+ v.location[i].y / _this.showProportionY
+ );
}
_this.ctx.closePath();
_this.ctx.stroke();
- _this.showRemarks(
- v.location[v.location.length - 1].x / _this.showProportion,
- v.location[v.location.length - 1].y / _this.showProportionY,
- v.name
- );
_this.canvas.style.cursor = "default";
- if (e && _this.ctx.isPointInPath(e.offsetX, e.offsetY)) {
- // 濡傛灉浼犲叆浜嗕簨浠跺潗鏍囷紝灏辩敤isPointInStroke鍒ゆ柇涓�涓�
- // 濡傛灉褰撳墠鐜瑕嗙洊浜嗚鍧愭爣锛屽氨灏嗗浘褰㈢殑index鏀惧埌鏁扮粍閲�
- // 褰撻紶鏍囩Щ鍏ヤ箣鍚庡皢褰撳墠鐨勬ā寮忓垏鎹负閫変腑妯″紡
- _this.type = "0";
- _this.delCursor.type = "5";
- _this.delCursor.index = i;
- // 灏嗗綋鍓嶅厓绱犳爣绾�
- _this.ctx.strokeStyle = "red";
- _this.ctx.beginPath();
- _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportionY);
- for (let i = 1; i < v.location.length; i++) {
- _this.ctx.lineTo(v.location[i].x / _this.showProportion, v.location[i].y / _this.showProportionY);
- }
- _this.ctx.closePath();
- _this.ctx.stroke();
- _this.showRemarks(
- v.location[v.location.length - 1].x / _this.showProportion,
- v.location[v.location.length - 1].y / _this.showProportionY,
- v.name
- );
- _this.canvas.style.cursor = "pointer";
- }
});
},
+
+ // 绠ご缁樺埗鍑芥暟
+ drawArrow(
+ ctx,
+ fromX,
+ fromY,
+ toX,
+ toY,
+ theta = 30,
+ headlen = 10,
+ width = 1,
+ color = "yellow"
+ ) {
+ // ctx锛欳anvas缁樺浘鐜
+ // fromX, fromY锛氳捣鐐瑰潗鏍囷紙涔熷彲浠ユ崲鎴恜1锛屽彧涓嶈繃瀹冩槸涓�涓暟缁勶級
+ // toX, toY锛氱粓鐐瑰潗鏍� (涔熷彲浠ユ崲鎴恜2锛屽彧涓嶈繃瀹冩槸涓�涓暟缁�)
+ // theta锛氫笁瑙掓枩杈逛竴鐩寸嚎澶硅
+ // headlen锛氫笁瑙掓枩杈归暱搴�
+ // width锛氱澶寸嚎瀹藉害
+ // color锛氱澶撮鑹�
+ // theta = typeof theta !== "undefined" ? theta : 30;
+ // headlen = typeof theta !== "undefined" ? headlen : 10;
+ // width = typeof width !== "undefined" ? width : 1;
+ // color = typeof color !== "undefined" ? color : "yellow";
+ // 璁$畻鍚勮搴﹀拰瀵瑰簲鐨凱2,P3鍧愭爣
+ let angle = (Math.atan2(fromY - toY, fromX - toX) * 180) / Math.PI;
+ let angle1 = ((angle + theta) * Math.PI) / 180;
+ let angle2 = ((angle - theta) * Math.PI) / 180;
+ let topX = headlen * Math.cos(angle1);
+ let topY = headlen * Math.sin(angle1);
+ let botX = headlen * Math.cos(angle2);
+ let botY = headlen * Math.sin(angle2);
+
+ ctx.save();
+ ctx.beginPath();
+ let arrowX = fromX - topX;
+ let arrowY = fromY - topY;
+ ctx.moveTo(arrowX, arrowY);
+ ctx.moveTo(fromX, fromY);
+ ctx.lineTo(toX, toY);
+ arrowX = toX + topX;
+ arrowY = toY + topY;
+ ctx.moveTo(arrowX, arrowY);
+ ctx.lineTo(toX, toY);
+ arrowX = toX + botX;
+ arrowY = toY + botY;
+ ctx.lineTo(arrowX, arrowY);
+ ctx.strokeStyle = color;
+ ctx.lineWidth = width;
+ ctx.stroke();
+ ctx.restore();
+ },
+
// 鍥炴樉鍥惧舰澶囨敞
showRemarks(x, y, remarks) {
this.ctx.moveTo(x, y - 10); // 鍥犱负鏀惧ぇ涔嬪悗鏄痽-20锛屾墍浠ョ缉灏忕増鐨勪负y-10
@@ -344,88 +330,59 @@
getCanvasData(data) {
let polyon = { ...data };
polyon.camera_id = this.Camera.cameraId;
- savePolygon(polyon).then(rsp => {
+ savePolygon(polyon).then((rsp) => {
this.Camera.getPolygon();
this.Camera.getCameraTask();
});
},
- async initCanvas(id){
-
- //this.canvas = document.querySelector("#area-canvas");
- this.canvas = this.$refs.areaCanvas;
- this.ctx = this.canvas.getContext("2d");
-
- // this.Camera.getPolygon();x:758,y:280
- // console.log(this.Camera.canvasData);
- const rsp = await getAllPolygon({ cameraId: id });
- debugger
- if (rsp && rsp.success) {
- this.canvasData = {
- line: rsp.data.line,
- arrow: rsp.data.arrow,
- polygon: [{id:'uuid', name: '澶氳竟褰�1', location: [{ x: 735, y: 155 }, { x: 830, y: 156 }, { x: 809, y: 351 }, { x: 809, y: 364 }, { x: 753, y: 396 }, { x: 755, y: 520 },{ x: 706, y: 524 },{ x: 722, y: 392 },{x:758,y:280},{ x: 735, y: 155 }] }],
- //rect: rsp.data.rect
- rect: [{id:'uuid', name: '鐭╁舰1', location: [{ x: 20, y: 30 }, { x: 20, y: 60 }, { x: 100, y: 60 }, { x: 100, y: 30 }] }]
- };
- }
- debugger
- this.clickSelect(this.canvasData);
+ setWidthHeight() {
+ this.canvasWidth = this.$refs.videoPlayer.offsetWidth;
+ this.canvasHeight = this.$refs.videoPlayer.offsetHeight;
+ console.log(this.canvasWidth, this.canvasHeight);
},
- async initArea(){
- console.log('init')
- const res = await getAllPolygon({cameraId: this.TreeDataPool.selectedNode.id});
+ async initArea() {
+ console.log("init");
+ const res = await getAllPolygon({
+ cameraId: this.TreeDataPool.selectedNode.id,
+ });
this.canvasData.line = res.data.line;
this.canvasData.rect = res.data.rect;
this.canvasData.arrow = res.data.arrow;
this.canvasData.polygon = res.data.polygon;
- console.log(this.canvasData)
- // this.canvasData = {
- // line: [],
- // arrow: [],
- // polygon: [{id:'uuid', name: '澶氳竟褰�1', location: [{ x: 735, y: 155 }, { x: 830, y: 156 }, { x: 809, y: 351 }, { x: 809, y: 364 }, { x: 753, y: 396 }, { x: 755, y: 520 },{ x: 706, y: 524 },{ x: 722, y: 392 },{x:758,y:280},{ x: 735, y: 155 }] }],
- // //rect: rsp.data.rect
- // rect: []
- // };
+ console.log(this.canvasData);
this.clickSelect(this.canvasData);
- }
+ },
+ initAlgoDataWebScoket() {
+ if (typeof WebSocket === "undefined") {
+ console.log("error,鎮ㄧ殑娴忚鍣ㄤ笉鏀寔socket");
+ } else {
+ this.algoDataSocket = new WebSocket();
+ this.algoDataSocket.onopen = () => {
+ console.log("socket杩炴帴鎴愬姛");
+ };
+ this.algoDataSocket.onerror = () => {
+ console.log("杩炴帴閿欒");
+ };
+ this.algoDataSocket.onmessage = (msg) => {
+ console.log(msg);
+ };
+ }
+ },
},
- mounted() {
- this.clickStart();
- this.$nextTick(()=>{
- this.canvas = this.$refs.areaCanvas;
- this.ctx = this.canvas.getContext("2d");
- this.ctx.lineWidth = 1;
-
- this.initArea()
-
- })
- },
- beforeDestroy() {
- this.wfs.destroy();
- this.wfsId = "";
- }
};
</script>
<style lang="scss">
-#area-canvas{
- width: 100%;
- height: 100%;
+#area-canvas {
background: transparent;
position: absolute;
top: 0;
left: 0;
+ padding: 0;
+ width: 100%;
+ height: 100%;
}
-// .cavas{
-// width: 100%;
-// height: 100%;
-// position: absolute;
-// top: 0;
-// left: 0;
-// canvas{
-// background: transparent!important;
-// }
-// }
+
video {
object-fit: fill;
width: 100%;
--
Gitblit v1.8.0