he wei
2023-11-25 d043e9283165ac10757ab4bf536998bf42b98e9b
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
  <g class="pointer" :transform="'translate(' + offset.join(',') + ')'">
    <!-- 圆角矩形 -->
    <path
      :d="createRoundRectPath(small ? 64 : 84, 68, 10)"
      stroke="#07D0C8"
      :fill="alarm ? '#FF3801' : '#0C4D77'"
    />
 
    <!-- 绘制标题 -->
    <text
      x="16"
      y="44"
      text-anchor="middle"
      fill="rgb(200,200,200)"
      font-size="20"
    >
      {{ type + "P" }}
    </text>
 
    <!-- 绘制图片 -->
    <image :x="small ? 36 : 40" y="6" :width="imgW" height="60" :xlink:href="url" />
  </g>
</template>
 
<script>
import SP1 from "../images/s-1p.png";
import SP2 from "../images/s-2p.png";
import SP3 from "../images/s-3p.png";
export default {
  name: "",
  props: {
    type: {
      type: Number,
      default: 1,
    },
    small: {
      type: Boolean,
      default: false,
    },
    alarm: {
      type: Boolean,
      default: false,
    },
    offset: {
      type: Array,
      default() {
        return [0, 0];
      },
    },
  },
  computed: {
    url() {
      let res = "";
      switch (this.type) {
        case 1:
          res = SP1;
          break;
 
        case 2:
          res = SP2;
          break;
        case 3:
          res = SP3;
          break;
      }
      return res;
    },
    imgW() {
      let res = "";
      switch (this.type) {
        case 1:
          res = 20;
          break;
 
        case 2:
          res = 26;
          break;
        case 3:
          res = 32;
          break;
      }
      return res;
    },
  },
  data() {
    return {};
  },
  methods: {
    createRoundRectPath(w, h, r = 5, x = 0, y = 0) {
      let p0 = [x, y];
      let p1 = [x + w, y];
      let p2 = [x + w, y + h];
      let p3 = [x, y + h];
 
      let cp0 = [x + r, y];
      let cp1 = [x + w - r, y];
      let cp2 = [x + w, y + r];
      let cp3 = [x + w, y + h - r];
      let cp4 = [x + w - r, y + h];
      let cp5 = [x + r, y + h];
      let cp6 = [x, y + h - r];
      let cp7 = [x, y + r];
 
      return `M${cp0[0]},${cp0[1]}
        L ${cp1[0]} ${cp1[1]}
        C ${cp1[0]} ${cp1[1]}, ${p1[0]} ${p1[1]}, ${cp2[0]} ${cp2[1]}
        L ${cp3[0]} ${cp3[1]}
        C ${cp3[0]} ${cp3[1]}, ${p2[0]} ${p2[1]}, ${cp4[0]} ${cp4[1]}
        L ${cp5[0]} ${cp5[1]}
        C ${cp5[0]} ${cp5[1]}, ${p3[0]} ${p3[1]}, ${cp6[0]} ${cp6[1]}
        L ${cp7[0]} ${cp7[1]}
        C ${cp7[0]} ${cp7[1]}, ${p0[0]} ${p0[1]}, ${cp0[0]} ${cp0[1]}
        Z`;
    },
  },
 
  mounted() {},
};
</script>
 
<style scoped>
.pointer {
  cursor: pointer;
}
</style>