Blame view

frontend/front/src/views/matter/components/processForecast/packages/markLine.vue 1.12 KB
8d73e917   陈威   初始化提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!--
 * User: CHT
 * Date: 2020/6/27
 * Time: 15:55
-->
<template>
  <canvas ref="markLine" class="super-flow__mark-line"></canvas>
</template>

<script>
  export default {
    props: {
      width: {
        type: Number,
        default: 0,
      },
      height: {
        type: Number,
        default: 0,
      },
      markLine: Array,
      markColor: String,
    },
    watch: {
      markLine() {
        this.draw()
      },
    },
    mounted() {
      this.$refs.markLine.height = this.height
      this.$refs.markLine.width = this.width
      this.draw()
    },
    methods: {
      draw() {
        const ctx = this.$el.getContext('2d')
        ctx.clearRect(0, 0, this.width, this.height)
        ctx.strokeStyle = this.markColor
        ctx.lineWidth = 1
        ctx.setLineDash([4, 2])
        this.markLine.forEach(([start, end]) => {
          ctx.beginPath()
          ctx.moveTo(...start)
          ctx.lineTo(...end)
          ctx.stroke()
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  .super-flow__mark-line {
    position: absolute;
    z-index: 0;
    border: 1px solid transparent;
  }
</style>