he wei
2024-07-31 af9733ab928ccc696cc00675fa2b2af85797b47c
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
<template>
  <g ref="g" :transform="'translate(' + offset.join(',') + ')'">
    <circle :r="r" style="fill: #fff; stroke: none"></circle>
    <circle :r="r" :cx="cx" :cy="cy" style="fill: #fff; stroke: none"></circle>
    <line :x2="cx" :y2="cy" :stroke-width="lineWidth" :stroke="color">
      <animateTransform
        ref="anim"
        attributeName="transform"
        attributeType="XML"
        type="rotate"
        :from="[fromDeg, isVertical ? cx : 0, isVertical ? cy : 0].join(',')"
        :to="[toDeg, isVertical ? cx : 0, isVertical ? cy : 0].join(',')"
        dur="0.3s"
        repeatCount="1"
        fill="freeze"
      />
    </line>
  </g>
</template>
 
<script>
export default {
  name: "",
  props: {
    r: {
      type: Number,
      default: 3,
    },
    len: {
      type: Number,
      default: 60,
    },
    offset: {
      type: Array,
      default() {
        return [0, 0];
      },
    },
    isVertical: {
      type: Boolean,
      default: false,
    },
    state: {
      type: Boolean,
      defalut: false,
    },
    points: {
      type: Array,
      default() {
        return [
          [0, 0],
          [10, 10],
        ];
      },
    },
    color: {
      type: String,
      default: "#f59a23",
    },
    currColor: {
      type: String,
      default: "#0f0",
    },
    lineWidth: {
      type: [Number, String],
      default: 2,
    },
  },
  computed: {
    cx() {
      let { isVertical, len } = this;
      return isVertical ? 0 : len;
    },
    cy() {
      let { isVertical, len } = this;
      return isVertical ? len : 0;
    },
    pointsStr() {
      return this.points.join(" ");
    },
  },
  data() {
    return {
      fromDeg: -2,
      toDeg: -38,
    };
  },
  watch: {
    state: {
      handler(n) {
        this.$nextTick(() => {
          this.changeSwitch();
        });
      },
      immediate: true,
    },
  },
  components: {},
  methods: {
    changeSwitch() {
      if (this.state) {
        this.fromDeg = -38;
        this.toDeg = -2;
      } else {
        this.fromDeg = -2;
        this.toDeg = -38;
      }
      // 重新开启动画
      this.$refs.anim?.beginElement();
    },
  },
 
  mounted() {
  },
};
</script>
 
<style scoped lang="less">
</style>