File size: 3,230 Bytes
b4cec68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3404aeb
 
b4cec68
 
 
 
 
 
 
3404aeb
 
b4cec68
 
 
 
 
 
 
3404aeb
 
b4cec68
 
 
 
 
 
 
 
3404aeb
 
b4cec68
 
 
 
 
 
3404aeb
b4cec68
 
 
 
 
 
 
 
 
 
 
 
 
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
  <div class="loading-container" v-if="isLoading">
    <div class="loading-spinner">
      <div class="spinner-ring" ref="ring1"></div>
      <div class="spinner-ring" ref="ring2"></div>
      <div class="spinner-ring" ref="ring3"></div>
      <div class="spinner-dot" ref="dot"></div>
    </div>
    <p class="loading-text">{{ loadingText }}</p>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, watch } from 'vue'
import { gsap } from 'gsap'

// 定义组件名称
defineOptions({
  name: 'LoadingSpinner'
})

interface Props {
  isLoading: boolean
  loadingText?: string
}

const props = withDefaults(defineProps<Props>(), {
  loadingText: '加载中...'
})

const ring1 = ref<HTMLElement>()
const ring2 = ref<HTMLElement>()
const ring3 = ref<HTMLElement>()
const dot = ref<HTMLElement>()

onMounted(() => {
  if (props.isLoading) {
    startAnimation()
  }
})

watch(() => props.isLoading, (newVal) => {
  if (newVal) {
    startAnimation()
  } else {
    stopAnimation()
  }
})

const startAnimation = () => {
  if (!ring1.value || !ring2.value || !ring3.value || !dot.value) return
  
  // 外环动画
  gsap.to(ring1.value, {
    rotation: 360,
    duration: 2,
    ease: "none",
    repeat: -1
  })
  
  // 中环动画
  gsap.to(ring2.value, {
    rotation: -360,
    duration: 1.5,
    ease: "none",
    repeat: -1
  })
  
  // 内环动画
  gsap.to(ring3.value, {
    rotation: 360,
    duration: 1,
    ease: "none",
    repeat: -1
  })
  
  // 中心点脉冲动画
  gsap.to(dot.value, {
    scale: 1.2,
    duration: 0.8,
    ease: "power2.inOut",
    repeat: -1,
    yoyo: true
  })
}

const stopAnimation = () => {
  gsap.killTweensOf([ring1.value, ring2.value, ring3.value, dot.value])
}
</script>

<style scoped>
.loading-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-spinner {
  position: relative;
  width: 80px;
  height: 80px;
  margin-bottom: 2rem;
}

.spinner-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 3px solid transparent;
  border-radius: 50%;
}

.spinner-ring:nth-child(1) {
  border-top-color: var(--ramex-accent);
  border-right-color: var(--ramex-accent);
}

.spinner-ring:nth-child(2) {
  width: 60px;
  height: 60px;
  top: 10px;
  left: 10px;
  border-top-color: var(--ramex-text-secondary);
  border-left-color: var(--ramex-text-secondary);
}

.spinner-ring:nth-child(3) {
  width: 40px;
  height: 40px;
  top: 20px;
  left: 20px;
  border-top-color: var(--ramex-text-muted);
  border-right-color: var(--ramex-text-muted);
}

.spinner-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  background: var(--ramex-accent);
  border-radius: var(--ramex-radius);
  transform: translate(-50%, -50%);
}

.loading-text {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--ramex-text-secondary);
  margin: 0;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}
</style>