hanbaoshan
2020-09-08 35bc7a5d2c907d2d7ca35f518dd1f96b434068b3
src/components/player/index.vue
@@ -1,6 +1,6 @@
<template>
  <div class="video-player">
    <canvas id="area-canvas" ></canvas>
    <canvas id="area-canvas" ref="areaCanvas" ></canvas>
    <video ref="videoPlayer" :poster="poster" preload="auto" muted></video>
    <div class="controls">
      <!-- 全屏 -->
@@ -13,6 +13,7 @@
import VideoRuleData from "@/Pool/VideoRuleData";
import TreeDataPool from "@/Pool/TreeData";
import { getAllPolygon } from "@/api/polygon";
import polygonCanvas from "@/components/canvas";
export default {
  name: "CameraPlayer",
  props: {
@@ -42,7 +43,9 @@
      default: false
    }
  },
  computed: {
    poster() {
      return "/images/player/player_poster.gif?t=" + Math.random()
    }
@@ -52,23 +55,35 @@
      wfs: {},
      wfsId: 0,
      Camera: new VideoRuleData(),
      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: []
      },
      showProportion: 1.71,
      showProportion: 3.65,
      canvas: null,
      ctx: null
    };
  },
  watch: {
    "TreeDataPool.selectedNode": function(node){
      debugger;
      this.initCanvas(node);
    },
    // "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) {
      if (newVal !== oldVal) {
        if (this.wfs.config) {
@@ -325,13 +340,21 @@
      this.ctx.textAlign = "left"; // 设置字体对齐的方式
      this.ctx.fillText(remarks, x, y - 10); // 填充文字
    },
    getCanvasData(data) {
      let polyon = { ...data };
      polyon.camera_id = this.Camera.cameraId;
      savePolygon(polyon).then(rsp => {
        this.Camera.getPolygon();
        this.Camera.getCameraTask();
      });
    },
    async initCanvas(id){
      
      this.canvas = document.querySelector("#area-canvas");
      //this.canvas = document.querySelector("#area-canvas");
      this.canvas = this.$refs.areaCanvas;
      this.ctx = this.canvas.getContext("2d");
      // this.Camera.getPolygon();
      // this.Camera.getPolygon();x:758,y:280
      // console.log(this.Camera.canvasData);
      const rsp = await getAllPolygon({ cameraId: id });
      debugger
@@ -339,18 +362,41 @@
        this.canvasData = {
          line: rsp.data.line,
          arrow: rsp.data.arrow,
          polygon: rsp.data.polygon,
          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);
    },
    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: []
      //   };
      this.clickSelect(this.canvasData);
    }
  },
  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();
@@ -368,6 +414,16 @@
  top: 0;
  left: 0;
}
// .cavas{
//   width: 100%;
//   height: 100%;
//   position: absolute;
//   top: 0;
//   left: 0;
//   canvas{
//     background: transparent!important;
//   }
// }
video {
  object-fit: fill;
  width: 100%;