hanbaoshan
2020-12-20 ecb6cadc3f016cf9968f48e0cc77479a1e56365b
src/components/canvas/Dialog.vue
@@ -198,7 +198,8 @@
  methods: {
    // 初始化函数
    init() {
      this.c = document.querySelector("#canvasDialog");
      //this.c = document.querySelector("#canvasDialog");
      this.c = this.$refs['canvasDialog'];
      this.ctx = this.c.getContext("2d");
      this.drawCanvasInit();
      this.canvasData = JSON.parse(JSON.stringify(this.canvasDataToChild));
@@ -394,7 +395,6 @@
    },
    // 删除元素
    del() {
      debugger
      let delEle = {};
      switch (this.delCursor.type) {
        case "1":
@@ -411,7 +411,7 @@
          break;
        case "5":
          delEle = this.canvasData.polygon[this.delCursor.index];
          this.canvasData.polygon.splice(this.delCursor.index+1, 1);
          this.canvasData.polygon.splice(this.delCursor.index, 1);
          break;
      }
      this.clickSelect();
@@ -522,6 +522,7 @@
        }
      });
      _this.canvasData.rect.forEach(function (v, i) {
        _this.ctx.strokeStyle = "yellow";
        _this.ctx.beginPath();
        _this.ctx.moveTo(v.location[0].x, v.location[0].y);
@@ -788,6 +789,7 @@
      // console.log("撤销!",this.canvasData);
    },
    disabledOthers(type) {
      console.log("当前type:", type)
      switch (type) {
        case "1":
@@ -825,6 +827,7 @@
      console.log("禁用多边形:", this.disablePolygon)
    },
    undisabled() {
      this.disableLine = false
      this.disableRect = false
      this.disableArrow = false
@@ -854,7 +857,7 @@
      width = typeof width !== "undefined" ? width : 1;
      // color = typeof color !== 'undefined' ? color : 'yellow'
      // 计算各角度和对应的P2,P3坐标
      debugger
      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;
@@ -884,6 +887,7 @@
    },
    // 获取相对坐标(暂不用)
    getLocation(x, y, c) {
      let bbox = c.getBoundingClientRect();
      return {
        x: (x - bbox.left) * (c.width / bbox.width),
@@ -898,6 +902,7 @@
    },
    // 生成图形备注
    remarks(x, y, type) {
      this.ctx.moveTo(x, y - 20);
      this.ctx.fillStyle = "green"; // 设置填充颜色为绿色
      this.ctx.font = '20px "微软雅黑"'; // 设置字体
@@ -927,6 +932,7 @@
    },
    // 回显图形备注
    showRemarks(x, y, remarks, isHightlight) {
      this.ctx.moveTo(x, y - 20);
      if (isHightlight) {
        this.ctx.fillStyle = "#8ae22e"; // 设置填充颜色为绿色
@@ -940,6 +946,7 @@
    },
    // 重现保存画面
    loadImage() {
      if (this.step > -1) {
        let img = new Image();
        img.src = this.canvasHistory[this.step].src;
@@ -948,6 +955,7 @@
    },
    // 切换画线类型
    changeType(num) {
      if (num === '0') {
        this.c.style.cursor = "pointer";
      } else {
@@ -957,6 +965,7 @@
    },
    // 绘制多边形方法
    drawPolygonUtil(points) {
      this.ctx.strokeStyle = "yellow";
      this.ctx.lineWidth = 2;
      this.ctx.beginPath();
@@ -983,6 +992,7 @@
    },
    // 画矩形移动函数
    drawRect(e) {
      if (this.flag) {
        this.ctx.clearRect(0, 0, this.c.width, this.c.height);
        this.loadImage();
@@ -1017,11 +1027,13 @@
      }
    },
    twoPointDistance(p1, p2) {
      let dep = Math.sqrt(Math.pow((p1.x - p2.x), 2) + Math.pow((p1.y - p2.y), 2));
      return dep;
    },
    // 画多边形移动函数
    drawPolygon(e) {
      if (this.flag) {
        this.ctx.clearRect(0, 0, this.c.width, this.c.height);
        this.loadImage();
@@ -1040,6 +1052,7 @@
    },
    // 画直线抬起
    lineMouseUp(e) {
      if (
        Math.abs(this.originX - e.offsetX) < 5 &&
        Math.abs(this.originY - e.offsetY) < 5
@@ -1096,6 +1109,7 @@
    },
    // 画矩形抬起
    rectMouseUp(e) {
      if (
        Math.abs(this.originX - e.offsetX) < 5 &&
        Math.abs(this.originY - e.offsetY) < 5
@@ -1218,6 +1232,7 @@
    },
    // 画多边形结束时双击
    polygonDblclick(e) {
      this.flag = false;
      this.points.pop(); // 双击之后多一个点的重复坐标,需要删除
      let Id
@@ -1265,6 +1280,7 @@
    },
    // 释放编辑状态
    freedEdit() {
      this.editObj = {}
    },
    // 回显历史数据时计算一下回显的每种元素的数量以便生成图形注解时获得正确的开头
@@ -1279,6 +1295,7 @@
    },
    // 生成uuid
    getUuid() {
      let originStr = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
      let originChar = "0123456789abcdef";
      let len = originChar.length;
@@ -1288,6 +1305,7 @@
    },
    // 判断一个点是否离一个图形的最小距离为n像素以内
    minDistance(x, y, locations, n) {
      let flag = false
      for (let i = 0; i < locations.length; i++) {
        if (i == locations.length - 1) {