wangrong
2026-08-30 4c949c0dc9bcae785c281c9d8125295f09810b15
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
<template>
  <div class="svg-triangle-container">
    <svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">
      <polygon
        ref="star"
        :points="points"
        :stroke="element.style.borderColor"
        :fill="element.style.backgroundColor"
        :stroke-width="borderWidth"
      />
    </svg>
  </div>
</template>
 
<script setup lang="ts">
import { computed, onMounted, ref, toRefs, watch } from 'vue'
 
const props = defineProps({
  propValue: {
    type: String,
    required: true,
    default: ''
  },
  element: {
    type: Object,
    default() {
      return {
        propValue: null
      }
    }
  }
})
const { element } = toRefs(props)
const points = ref('')
 
watch(
  () => element.value.style.width,
  () => {
    draw()
  }
)
 
watch(
  () => element.value.style.height,
  () => {
    draw()
  }
)
 
onMounted(() => {
  draw()
})
 
const borderWidth = computed(() => {
  return element.value.style.borderActive ? element.value.style.borderWidth : 0
})
 
const draw = () => {
  const { width, height } = element.value.style
  drawPolygon(width, height)
}
 
const drawPolygon = (width, height) => {
  // 三角形三个坐标
  const pointsArray = [
    [0.5, 0.05],
    [1, 0.95],
    [0, 0.95]
  ]
 
  const coordinatePoints = pointsArray.map(point => width * point[0] + ' ' + height * point[1])
  points.value = coordinatePoints.toString()
}
</script>
<style lang="less" scoped>
.svg-triangle-container {
  width: 100%;
  height: 100%;
 
  svg {
    width: 100%;
    height: 100%;
  }
 
  .v-text {
    position: absolute;
    top: 72%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50%;
    height: 40%;
  }
}
</style>