little-dizzy 2.3.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,287 @@
1
+ <template>
2
+ <div class="ld-carousel" :class="{ 'ld-carousel--vertical': direction === 'vertical' }" :style="{ height: height }">
3
+ <div class="carousel-container" :style="containerStyle">
4
+ <div v-for="(item, index) in items" :key="index" class="carousel-slide"
5
+ :class="{ active: index === currentIndex }">
6
+ <slot name="item" :item="item" :index="index">
7
+ <img v-if="item.image" :src="item.image" :alt="item.title || ''" />
8
+ <div v-if="item.title" class="slide-title">{{ item.title }}</div>
9
+ </slot>
10
+ </div>
11
+ </div>
12
+
13
+ <!-- 指示器 -->
14
+ <div v-if="showIndicators" class="carousel-indicators">
15
+ <span v-for="(_, index) in items" :key="index" class="indicator" :class="{ active: index === currentIndex }"
16
+ @click="goTo(index)" />
17
+ </div>
18
+
19
+ <!-- 箭头 -->
20
+ <template v-if="showArrows">
21
+ <button class="carousel-arrow prev" @click="prev">
22
+ <svg viewBox="0 0 24 24" width="24" height="24">
23
+ <path fill="currentColor" :d="direction === 'vertical'
24
+ ? 'M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z'
25
+ : 'M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z'" />
26
+ </svg>
27
+ </button>
28
+ <button class="carousel-arrow next" @click="next">
29
+ <svg viewBox="0 0 24 24" width="24" height="24">
30
+ <path fill="currentColor" :d="direction === 'vertical'
31
+ ? 'M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z'
32
+ : 'M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z'" />
33
+ </svg>
34
+ </button>
35
+ </template>
36
+ </div>
37
+ </template>
38
+
39
+ <script setup>
40
+ import { ref, computed, onMounted, onUnmounted } from 'vue'
41
+
42
+ defineOptions({
43
+ name: 'Carousel'
44
+ })
45
+
46
+ const props = defineProps({
47
+ items: {
48
+ type: Array,
49
+ default: () => []
50
+ },
51
+ height: {
52
+ type: String,
53
+ default: '300px'
54
+ },
55
+ direction: {
56
+ type: String,
57
+ default: 'horizontal',
58
+ validator: (val) => ['horizontal', 'vertical'].includes(val)
59
+ },
60
+ autoplay: {
61
+ type: Boolean,
62
+ default: true
63
+ },
64
+ interval: {
65
+ type: Number,
66
+ default: 3000
67
+ },
68
+ showIndicators: {
69
+ type: Boolean,
70
+ default: true
71
+ },
72
+ showArrows: {
73
+ type: Boolean,
74
+ default: true
75
+ }
76
+ })
77
+
78
+ const emit = defineEmits(['change'])
79
+
80
+ const currentIndex = ref(0)
81
+ let timer = null
82
+
83
+ const containerStyle = computed(() => {
84
+ const offset = currentIndex.value * 100
85
+ return props.direction === 'vertical'
86
+ ? { transform: `translateY(-${offset}%)` }
87
+ : { transform: `translateX(-${offset}%)` }
88
+ })
89
+
90
+ const next = () => {
91
+ currentIndex.value = (currentIndex.value + 1) % props.items.length
92
+ emit('change', currentIndex.value)
93
+ }
94
+
95
+ const prev = () => {
96
+ currentIndex.value = (currentIndex.value - 1 + props.items.length) % props.items.length
97
+ emit('change', currentIndex.value)
98
+ }
99
+
100
+ const goTo = (index) => {
101
+ currentIndex.value = index
102
+ emit('change', currentIndex.value)
103
+ }
104
+
105
+ const startAutoplay = () => {
106
+ if (props.autoplay && props.items.length > 1) {
107
+ timer = setInterval(next, props.interval)
108
+ }
109
+ }
110
+
111
+ const stopAutoplay = () => {
112
+ if (timer) {
113
+ clearInterval(timer)
114
+ timer = null
115
+ }
116
+ }
117
+
118
+ onMounted(() => {
119
+ startAutoplay()
120
+ })
121
+
122
+ onUnmounted(() => {
123
+ stopAutoplay()
124
+ })
125
+
126
+ defineExpose({
127
+ next,
128
+ prev,
129
+ goTo,
130
+ currentIndex
131
+ })
132
+ </script>
133
+
134
+ <style scoped>
135
+ .ld-carousel {
136
+ position: relative;
137
+ width: 100%;
138
+ overflow: hidden;
139
+ border-radius: 8px;
140
+ background: var(--ld-color-bg-secondary, #f5f5f5);
141
+ }
142
+
143
+ .carousel-container {
144
+ display: flex;
145
+ height: 100%;
146
+ transition: transform 0.5s ease;
147
+ }
148
+
149
+ .carousel-slide {
150
+ flex-shrink: 0;
151
+ width: 100%;
152
+ height: 100%;
153
+ display: flex;
154
+ align-items: center;
155
+ justify-content: center;
156
+ }
157
+
158
+ .carousel-slide img {
159
+ width: 100%;
160
+ height: 100%;
161
+ object-fit: cover;
162
+ }
163
+
164
+ .slide-title {
165
+ position: absolute;
166
+ bottom: 40px;
167
+ left: 0;
168
+ right: 0;
169
+ text-align: center;
170
+ color: #fff;
171
+ font-size: 18px;
172
+ text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
173
+ }
174
+
175
+ .carousel-indicators {
176
+ position: absolute;
177
+ bottom: 12px;
178
+ left: 50%;
179
+ transform: translateX(-50%);
180
+ display: flex;
181
+ gap: 8px;
182
+ }
183
+
184
+ .indicator {
185
+ width: 8px;
186
+ height: 8px;
187
+ border-radius: 50%;
188
+ background: rgba(255, 255, 255, 0.5);
189
+ cursor: pointer;
190
+ transition: all 0.3s;
191
+ }
192
+
193
+ .indicator.active {
194
+ background: #fff;
195
+ width: 24px;
196
+ border-radius: 4px;
197
+ }
198
+
199
+ .carousel-arrow {
200
+ position: absolute;
201
+ top: 50%;
202
+ width: 40px;
203
+ height: 40px;
204
+ border: none;
205
+ border-radius: 50%;
206
+ background: rgba(0, 0, 0, 0.3);
207
+ color: #fff;
208
+ cursor: pointer;
209
+ display: flex;
210
+ align-items: center;
211
+ justify-content: center;
212
+ transition: all 0.3s ease;
213
+ }
214
+
215
+ .carousel-arrow:hover {
216
+ background: rgba(0, 0, 0, 0.5);
217
+ }
218
+
219
+ .carousel-arrow.prev {
220
+ left: -50px;
221
+ transform: translateY(-50%);
222
+ }
223
+
224
+ .carousel-arrow.next {
225
+ right: -50px;
226
+ transform: translateY(-50%);
227
+ }
228
+
229
+ .ld-carousel:hover .carousel-arrow.prev {
230
+ left: 12px;
231
+ }
232
+
233
+ .ld-carousel:hover .carousel-arrow.next {
234
+ right: 12px;
235
+ }
236
+
237
+ /* 垂直方向样式 */
238
+ .ld-carousel--vertical .carousel-container {
239
+ flex-direction: column;
240
+ }
241
+
242
+ .ld-carousel--vertical .carousel-slide {
243
+ width: 100%;
244
+ height: 100%;
245
+ }
246
+
247
+ .ld-carousel--vertical .carousel-indicators {
248
+ flex-direction: column;
249
+ right: 12px;
250
+ top: 50%;
251
+ left: auto;
252
+ bottom: auto;
253
+ transform: translateY(-50%);
254
+ }
255
+
256
+ .ld-carousel--vertical .indicator.active {
257
+ width: 8px;
258
+ height: 24px;
259
+ }
260
+
261
+ .ld-carousel--vertical .carousel-arrow {
262
+ left: 50%;
263
+ right: auto;
264
+ }
265
+
266
+ .ld-carousel--vertical .carousel-arrow.prev {
267
+ top: -50px;
268
+ bottom: auto;
269
+ transform: translateX(-50%);
270
+ }
271
+
272
+ .ld-carousel--vertical .carousel-arrow.next {
273
+ top: auto;
274
+ bottom: -50px;
275
+ transform: translateX(-50%);
276
+ }
277
+
278
+ .ld-carousel--vertical:hover .carousel-arrow.prev {
279
+ left: 50%;
280
+ top: 12px;
281
+ }
282
+
283
+ .ld-carousel--vertical:hover .carousel-arrow.next {
284
+ right: auto;
285
+ bottom: 12px;
286
+ }
287
+ </style>
@@ -0,0 +1,224 @@
1
+ <template>
2
+ <div class="ld-loading" :class="[`ld-loading--${type}`, { 'ld-loading--fullscreen': fullscreen }]">
3
+ <!-- Spinner -->
4
+ <template v-if="type === 'spinner'">
5
+ <div class="spinner" :style="spinnerStyle">
6
+ <div v-for="i in 12" :key="i" class="spinner-blade" />
7
+ </div>
8
+ </template>
9
+
10
+ <!-- Dots -->
11
+ <template v-else-if="type === 'dots'">
12
+ <div class="dots">
13
+ <span v-for="i in 3" :key="i" class="dot" :style="{ background: color }" />
14
+ </div>
15
+ </template>
16
+
17
+ <!-- Ring -->
18
+ <template v-else-if="type === 'ring'">
19
+ <div class="ring" :style="ringStyle">
20
+ <div class="ring-inner" />
21
+ </div>
22
+ </template>
23
+
24
+ <!-- Pulse -->
25
+ <template v-else-if="type === 'pulse'">
26
+ <div class="pulse" :style="{ background: color, width: size, height: size }" />
27
+ </template>
28
+
29
+ <!-- Bars -->
30
+ <template v-else-if="type === 'bars'">
31
+ <div class="bars">
32
+ <span v-for="i in 5" :key="i" class="bar" :style="{ background: color }" />
33
+ </div>
34
+ </template>
35
+
36
+ <!-- 文字 -->
37
+ <div v-if="text" class="loading-text">{{ text }}</div>
38
+ </div>
39
+ </template>
40
+
41
+ <script setup>
42
+ import { computed } from 'vue'
43
+
44
+ defineOptions({
45
+ name: 'Loading'
46
+ })
47
+
48
+ const props = defineProps({
49
+ type: {
50
+ type: String,
51
+ default: 'spinner',
52
+ validator: (val) => ['spinner', 'dots', 'ring', 'pulse', 'bars'].includes(val)
53
+ },
54
+ size: {
55
+ type: String,
56
+ default: '40px'
57
+ },
58
+ color: {
59
+ type: String,
60
+ default: 'var(--ld-color-primary, #6366f1)'
61
+ },
62
+ text: {
63
+ type: String,
64
+ default: ''
65
+ },
66
+ fullscreen: {
67
+ type: Boolean,
68
+ default: false
69
+ }
70
+ })
71
+
72
+ const spinnerStyle = computed(() => ({
73
+ width: props.size,
74
+ height: props.size,
75
+ '--spinner-color': props.color
76
+ }))
77
+
78
+ const ringStyle = computed(() => ({
79
+ width: props.size,
80
+ height: props.size,
81
+ '--ring-color': props.color
82
+ }))
83
+ </script>
84
+
85
+ <style scoped>
86
+ .ld-loading {
87
+ display: inline-flex;
88
+ flex-direction: column;
89
+ align-items: center;
90
+ justify-content: center;
91
+ gap: 12px;
92
+ }
93
+
94
+ .ld-loading--fullscreen {
95
+ position: fixed;
96
+ top: 0;
97
+ left: 0;
98
+ right: 0;
99
+ bottom: 0;
100
+ background: var(--ld-loading-fullscreen-bg, rgba(255, 255, 255, 0.9));
101
+ z-index: 9999;
102
+ }
103
+
104
+ .loading-text {
105
+ color: var(--ld-color-text-secondary, #666);
106
+ font-size: 14px;
107
+ }
108
+
109
+ /* Spinner */
110
+ .spinner {
111
+ position: relative;
112
+ }
113
+
114
+ .spinner-blade {
115
+ position: absolute;
116
+ left: 50%;
117
+ top: 50%;
118
+ width: 8%;
119
+ height: 24%;
120
+ background: var(--spinner-color, #6366f1);
121
+ border-radius: 4px;
122
+ transform-origin: center bottom;
123
+ animation: spinner-fade 1s infinite linear;
124
+ }
125
+
126
+ .spinner-blade:nth-child(1) { transform: translateX(-50%) rotate(0deg) translateY(-120%); animation-delay: -0.083s; }
127
+ .spinner-blade:nth-child(2) { transform: translateX(-50%) rotate(30deg) translateY(-120%); animation-delay: -0.166s; }
128
+ .spinner-blade:nth-child(3) { transform: translateX(-50%) rotate(60deg) translateY(-120%); animation-delay: -0.25s; }
129
+ .spinner-blade:nth-child(4) { transform: translateX(-50%) rotate(90deg) translateY(-120%); animation-delay: -0.333s; }
130
+ .spinner-blade:nth-child(5) { transform: translateX(-50%) rotate(120deg) translateY(-120%); animation-delay: -0.416s; }
131
+ .spinner-blade:nth-child(6) { transform: translateX(-50%) rotate(150deg) translateY(-120%); animation-delay: -0.5s; }
132
+ .spinner-blade:nth-child(7) { transform: translateX(-50%) rotate(180deg) translateY(-120%); animation-delay: -0.583s; }
133
+ .spinner-blade:nth-child(8) { transform: translateX(-50%) rotate(210deg) translateY(-120%); animation-delay: -0.666s; }
134
+ .spinner-blade:nth-child(9) { transform: translateX(-50%) rotate(240deg) translateY(-120%); animation-delay: -0.75s; }
135
+ .spinner-blade:nth-child(10) { transform: translateX(-50%) rotate(270deg) translateY(-120%); animation-delay: -0.833s; }
136
+ .spinner-blade:nth-child(11) { transform: translateX(-50%) rotate(300deg) translateY(-120%); animation-delay: -0.916s; }
137
+ .spinner-blade:nth-child(12) { transform: translateX(-50%) rotate(330deg) translateY(-120%); animation-delay: -1s; }
138
+
139
+ @keyframes spinner-fade {
140
+ 0%, 100% { opacity: 0.2; }
141
+ 50% { opacity: 1; }
142
+ }
143
+
144
+ /* Dots */
145
+ .dots {
146
+ display: flex;
147
+ gap: 6px;
148
+ }
149
+
150
+ .dot {
151
+ width: 10px;
152
+ height: 10px;
153
+ border-radius: 50%;
154
+ animation: dots-bounce 1.4s ease-in-out infinite both;
155
+ }
156
+
157
+ .dot:nth-child(1) { animation-delay: -0.32s; }
158
+ .dot:nth-child(2) { animation-delay: -0.16s; }
159
+ .dot:nth-child(3) { animation-delay: 0s; }
160
+
161
+ @keyframes dots-bounce {
162
+ 0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
163
+ 40% { transform: scale(1); opacity: 1; }
164
+ }
165
+
166
+ /* Ring */
167
+ .ring {
168
+ position: relative;
169
+ border: 3px solid var(--ld-loading-ring-border, rgba(99, 102, 241, 0.2));
170
+ border-radius: 50%;
171
+ }
172
+
173
+ .ring-inner {
174
+ position: absolute;
175
+ top: -3px;
176
+ left: -3px;
177
+ right: -3px;
178
+ bottom: -3px;
179
+ border: 3px solid transparent;
180
+ border-top-color: var(--ring-color, #6366f1);
181
+ border-radius: 50%;
182
+ animation: ring-spin 1s linear infinite;
183
+ }
184
+
185
+ @keyframes ring-spin {
186
+ to { transform: rotate(360deg); }
187
+ }
188
+
189
+ /* Pulse */
190
+ .pulse {
191
+ border-radius: 50%;
192
+ animation: pulse-scale 1.5s ease-in-out infinite;
193
+ }
194
+
195
+ @keyframes pulse-scale {
196
+ 0%, 100% { transform: scale(0.8); opacity: 0.5; }
197
+ 50% { transform: scale(1); opacity: 1; }
198
+ }
199
+
200
+ /* Bars */
201
+ .bars {
202
+ display: flex;
203
+ align-items: flex-end;
204
+ gap: 4px;
205
+ height: 30px;
206
+ }
207
+
208
+ .bar {
209
+ width: 6px;
210
+ animation: bars-grow 1.2s ease-in-out infinite;
211
+ }
212
+
213
+ .bar:nth-child(1) { animation-delay: 0s; }
214
+ .bar:nth-child(2) { animation-delay: 0.1s; }
215
+ .bar:nth-child(3) { animation-delay: 0.2s; }
216
+ .bar:nth-child(4) { animation-delay: 0.3s; }
217
+ .bar:nth-child(5) { animation-delay: 0.4s; }
218
+
219
+ @keyframes bars-grow {
220
+ 0%, 40%, 100% { height: 40%; }
221
+ 20% { height: 100%; }
222
+ }
223
+ </style>
224
+