uniapp-dyckui 4.1.3 → 4.1.4
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.
- package/dist/assets/{style.BFlsbpSj.css → style.BEkFuBVh.css} +776 -774
- package/dist/index.cjs +840 -838
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +840 -838
- package/dist/index.mjs.map +1 -1
- package/dist/src/components/MyComs/Button/index.vue.d.ts +6 -6
- package/dist/src/components/MyComs/Dialog/index.vue.d.ts +6 -6
- package/dist/src/components/MyComs/Divider/index.vue.d.ts +5 -5
- package/dist/src/components/MyComs/DropdownSelect/dropdownSelect.d.ts +2 -2
- package/dist/src/components/MyComs/DropdownSelect/index.vue.d.ts +3 -6
- package/dist/src/components/MyComs/DropdownWithBadge/index.vue.d.ts +3 -6
- package/dist/src/components/MyComs/FilterDrawer/index.vue.d.ts +3 -6
- package/dist/src/components/MyComs/FilterDrawer/useFilterDrawer.d.ts +1 -1
- package/dist/src/components/MyComs/InfiniteScroll/index.vue.d.ts +5 -5
- package/dist/src/components/MyComs/Popup/index.vue.d.ts +5 -5
- package/dist/src/components/MyComs/PullRefresh/index.vue.d.ts +5 -5
- package/dist/src/components/MyComs/Swiper/index.vue.d.ts +7 -7
- package/dist/src/components/MyComs/Toast/index.vue.d.ts +7 -7
- package/dist/src/components/MyComs/index.d.ts +1590 -17
- package/package.json +101 -94
- package/src/components/MyComs/Popup/index.vue +837 -835
- package/src/components/MyComs/PullRefresh/index.vue +2 -1
- package/src/components/MyComs/Swiper/index.vue +246 -245
- package/src/components/MyComs/Toast/index.vue +373 -372
- package/src/components/MyComs/index.ts +54 -17
|
@@ -1,372 +1,373 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
v-show="showToast"
|
|
4
|
-
ref="toastRef"
|
|
5
|
-
class="sw-toast"
|
|
6
|
-
:class="[
|
|
7
|
-
`sw-toast--${type}`,
|
|
8
|
-
`sw-toast--${position}`,
|
|
9
|
-
{ 'sw-toast--large': large },
|
|
10
|
-
{ 'sw-toast--text': !showIcon && type === 'text' },
|
|
11
|
-
{ 'sw-toast--show': showToast && !isClosing },
|
|
12
|
-
{ 'sw-toast--hide': showToast && isClosing },
|
|
13
|
-
]"
|
|
14
|
-
:style="customStyle"
|
|
15
|
-
@click="onClick"
|
|
16
|
-
@transitionend="handleTransitionEnd"
|
|
17
|
-
>
|
|
18
|
-
<!-- 加载图标 -->
|
|
19
|
-
<view v-if="loading" class="sw-toast__loading">
|
|
20
|
-
<text v-if="!customIcon" class="sw-toast__spinner" />
|
|
21
|
-
<text v-else class="sw-toast__custom-icon">{{ customIcon }}</text>
|
|
22
|
-
</view>
|
|
23
|
-
|
|
24
|
-
<!-- 状态图标 -->
|
|
25
|
-
<view v-else-if="showIcon" class="sw-toast__icon">
|
|
26
|
-
<text v-if="type === 'success'" class="sw-toast__icon--success">✓</text>
|
|
27
|
-
<text v-else-if="type === 'fail'" class="sw-toast__icon--fail">✗</text>
|
|
28
|
-
<text v-else-if="customIcon" class="sw-toast__custom-icon">{{ customIcon }}</text>
|
|
29
|
-
</view>
|
|
30
|
-
|
|
31
|
-
<!-- 文本内容 -->
|
|
32
|
-
<text v-if="message" class="sw-toast__text">{{ message }}</text>
|
|
33
|
-
</view>
|
|
34
|
-
</template>
|
|
35
|
-
|
|
36
|
-
<script setup lang="ts">
|
|
37
|
-
import { computed, onMounted, onUnmounted, ref, watch
|
|
38
|
-
|
|
39
|
-
// Props
|
|
40
|
-
interface Props {
|
|
41
|
-
/**
|
|
42
|
-
* 控制显示/隐藏(支持v-model)
|
|
43
|
-
*/
|
|
44
|
-
modelValue?: boolean
|
|
45
|
-
/**
|
|
46
|
-
* 提示类型
|
|
47
|
-
*/
|
|
48
|
-
type?: 'text' | 'loading' | 'success' | 'fail'
|
|
49
|
-
/**
|
|
50
|
-
* 显示位置
|
|
51
|
-
*/
|
|
52
|
-
position?: 'top' | 'middle' | 'bottom'
|
|
53
|
-
/**
|
|
54
|
-
* 提示文字
|
|
55
|
-
*/
|
|
56
|
-
message?: string
|
|
57
|
-
/**
|
|
58
|
-
* 自动关闭时间(毫秒),0表示不会自动关闭
|
|
59
|
-
*/
|
|
60
|
-
duration?: number
|
|
61
|
-
/**
|
|
62
|
-
* 是否显示加载图标
|
|
63
|
-
*/
|
|
64
|
-
loading?: boolean
|
|
65
|
-
/**
|
|
66
|
-
* 是否显示图标
|
|
67
|
-
*/
|
|
68
|
-
icon?: boolean
|
|
69
|
-
/**
|
|
70
|
-
* 自定义图标
|
|
71
|
-
*/
|
|
72
|
-
customIcon?: string
|
|
73
|
-
/**
|
|
74
|
-
* 是否为大尺寸
|
|
75
|
-
*/
|
|
76
|
-
large?: boolean
|
|
77
|
-
/**
|
|
78
|
-
* 自定义样式
|
|
79
|
-
*/
|
|
80
|
-
customStyle?: Record<string, any>
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
84
|
-
modelValue: false,
|
|
85
|
-
type: 'text',
|
|
86
|
-
position: 'middle',
|
|
87
|
-
message: '',
|
|
88
|
-
duration: 3000,
|
|
89
|
-
loading: false,
|
|
90
|
-
icon: true,
|
|
91
|
-
customIcon: '',
|
|
92
|
-
large: false,
|
|
93
|
-
customStyle: () => ({}),
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
// Emits
|
|
97
|
-
const emit = defineEmits<{
|
|
98
|
-
/**
|
|
99
|
-
* 显示状态变化时触发
|
|
100
|
-
*/
|
|
101
|
-
(e: 'update:modelValue', value: boolean): void
|
|
102
|
-
/**
|
|
103
|
-
* 关闭时触发
|
|
104
|
-
*/
|
|
105
|
-
(e: 'close'): void
|
|
106
|
-
/**
|
|
107
|
-
* 点击时触发
|
|
108
|
-
*/
|
|
109
|
-
(e: 'click'): void
|
|
110
|
-
}>()
|
|
111
|
-
|
|
112
|
-
// Refs
|
|
113
|
-
const toastRef = ref<any>(null)
|
|
114
|
-
let timer: number | null | ReturnType<typeof setTimeout> = null
|
|
115
|
-
|
|
116
|
-
// 内部状态
|
|
117
|
-
const showToast = ref(props.modelValue)
|
|
118
|
-
const isClosing = ref(false)
|
|
119
|
-
|
|
120
|
-
// 计算是否需要显示图标
|
|
121
|
-
const showIcon = computed(() => {
|
|
122
|
-
if (props.loading)
|
|
123
|
-
return true
|
|
124
|
-
if (props.type === 'text')
|
|
125
|
-
return props.icon
|
|
126
|
-
return true
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
// 点击事件处理
|
|
130
|
-
function onClick() {
|
|
131
|
-
emit('click')
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// 关闭Toast
|
|
135
|
-
function close() {
|
|
136
|
-
if (!showToast.value)
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
// 添加关闭动画
|
|
140
|
-
isClosing.value = true
|
|
141
|
-
emit('close')
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// 自动关闭定时器
|
|
145
|
-
function startTimer() {
|
|
146
|
-
// 清除之前的定时器
|
|
147
|
-
clearTimer()
|
|
148
|
-
|
|
149
|
-
if (props.duration > 0 && !props.loading) {
|
|
150
|
-
timer = setTimeout(() => {
|
|
151
|
-
close()
|
|
152
|
-
}, props.duration)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// 清除定时器
|
|
157
|
-
function clearTimer() {
|
|
158
|
-
if (timer) {
|
|
159
|
-
clearTimeout(timer)
|
|
160
|
-
timer = null
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// 过渡结束处理
|
|
165
|
-
function handleTransitionEnd() {
|
|
166
|
-
if (isClosing.value) {
|
|
167
|
-
showToast.value = false
|
|
168
|
-
isClosing.value = false
|
|
169
|
-
emit('update:modelValue', false)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// 监听modelValue变化
|
|
174
|
-
watch(() => props.modelValue, (newVal) => {
|
|
175
|
-
if (newVal) {
|
|
176
|
-
// 显示Toast
|
|
177
|
-
showToast.value = true
|
|
178
|
-
isClosing.value = false
|
|
179
|
-
startTimer()
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
// 隐藏Toast
|
|
183
|
-
close()
|
|
184
|
-
}
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
// 监听message变化,重新启动定时器
|
|
188
|
-
watch(() => props.message, () => {
|
|
189
|
-
if (showToast.value && !props.loading) {
|
|
190
|
-
startTimer()
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
// 生命周期
|
|
195
|
-
onMounted(() => {
|
|
196
|
-
if (props.modelValue) {
|
|
197
|
-
startTimer()
|
|
198
|
-
}
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
onUnmounted(() => {
|
|
202
|
-
clearTimer()
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
// 暴露方法
|
|
206
|
-
defineExpose({
|
|
207
|
-
/**
|
|
208
|
-
* 手动关闭Toast
|
|
209
|
-
*/
|
|
210
|
-
close,
|
|
211
|
-
})
|
|
212
|
-
</script>
|
|
213
|
-
|
|
214
|
-
<style scoped>
|
|
215
|
-
.sw-toast {
|
|
216
|
-
display: inline-flex;
|
|
217
|
-
align-items: center;
|
|
218
|
-
justify-content: center;
|
|
219
|
-
max-width: 80%;
|
|
220
|
-
padding: 20rpx 32rpx;
|
|
221
|
-
border-radius: 8rpx;
|
|
222
|
-
font-size: 28rpx;
|
|
223
|
-
line-height: 40rpx;
|
|
224
|
-
color: #fff;
|
|
225
|
-
background-color: rgba(0, 0, 0, 0.7);
|
|
226
|
-
box-sizing: border-box;
|
|
227
|
-
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
228
|
-
z-index: 9999;
|
|
229
|
-
position: fixed;
|
|
230
|
-
left: 50%;
|
|
231
|
-
transform: translateX(-50%) translateY(0);
|
|
232
|
-
word-wrap: break-word;
|
|
233
|
-
white-space: pre-wrap;
|
|
234
|
-
user-select: none;
|
|
235
|
-
opacity: 0;
|
|
236
|
-
visibility: hidden;
|
|
237
|
-
pointer-events: none;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/* 显示动画 */
|
|
241
|
-
.sw-toast--show {
|
|
242
|
-
opacity: 1;
|
|
243
|
-
visibility: visible;
|
|
244
|
-
pointer-events: auto;
|
|
245
|
-
transform: translateX(-50%) translateY(0);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/* 隐藏动画 */
|
|
249
|
-
.sw-toast--hide {
|
|
250
|
-
opacity: 0;
|
|
251
|
-
transform: translateX(-50%) translateY(-20rpx);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/* 位置样式 */
|
|
255
|
-
.sw-toast--top {
|
|
256
|
-
top: 100rpx;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
.sw-toast--middle {
|
|
260
|
-
top: 50%;
|
|
261
|
-
transform: translate(-50%, -50%);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
.sw-toast--middle.sw-toast--show {
|
|
265
|
-
transform: translate(-50%, -50%);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
.sw-toast--middle.sw-toast--hide {
|
|
269
|
-
transform: translate(-50%, -60%);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
.sw-toast--bottom {
|
|
273
|
-
bottom: 100rpx;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/* 类型样式 */
|
|
277
|
-
.sw-toast--text {
|
|
278
|
-
background-color: rgba(0, 0, 0, 0.7);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
.sw-toast--loading {
|
|
282
|
-
background-color: rgba(0, 0, 0, 0.7);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
.sw-toast--success {
|
|
286
|
-
background-color: #67c23a;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
.sw-toast--fail {
|
|
290
|
-
background-color: #f56c6c;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/* 大尺寸样式 */
|
|
294
|
-
.sw-toast--large {
|
|
295
|
-
padding: 32rpx 48rpx;
|
|
296
|
-
font-size: 32rpx;
|
|
297
|
-
line-height: 48rpx;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/* 加载图标 */
|
|
301
|
-
.sw-toast__loading {
|
|
302
|
-
margin-right: 16rpx;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/* 加载动画 */
|
|
306
|
-
.sw-toast__spinner {
|
|
307
|
-
display: inline-block;
|
|
308
|
-
width: 40rpx;
|
|
309
|
-
height: 40rpx;
|
|
310
|
-
border: 4rpx solid rgba(255, 255, 255, 0.3);
|
|
311
|
-
border-radius: 50%;
|
|
312
|
-
border-top-color: #fff;
|
|
313
|
-
animation: sw-toast-spin 0.8s linear infinite;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/* 自定义图标 */
|
|
317
|
-
.sw-toast__custom-icon {
|
|
318
|
-
font-size: 40rpx;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/* 状态图标 */
|
|
322
|
-
.sw-toast__icon {
|
|
323
|
-
margin-right: 16rpx;
|
|
324
|
-
|
|
325
|
-
&--success,
|
|
326
|
-
&--fail {
|
|
327
|
-
display: inline-block;
|
|
328
|
-
width: 40rpx;
|
|
329
|
-
height: 40rpx;
|
|
330
|
-
font-size: 40rpx;
|
|
331
|
-
font-weight: bold;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/* 文本内容 */
|
|
336
|
-
.sw-toast__text {
|
|
337
|
-
margin: 0;
|
|
338
|
-
word-wrap: break-word;
|
|
339
|
-
white-space: pre-wrap;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/* 加载动画 */
|
|
343
|
-
@keyframes sw-toast-spin {
|
|
344
|
-
to {
|
|
345
|
-
transform: rotate(360deg);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/* 响应式设计 */
|
|
350
|
-
@media (max-width: 768px) {
|
|
351
|
-
.sw-toast {
|
|
352
|
-
max-width: 90%;
|
|
353
|
-
padding: 16rpx 24rpx;
|
|
354
|
-
font-size: 26rpx;
|
|
355
|
-
line-height: 36rpx;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
.sw-toast--large {
|
|
359
|
-
padding: 24rpx 40rpx;
|
|
360
|
-
font-size: 30rpx;
|
|
361
|
-
line-height: 44rpx;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
.sw-toast--top {
|
|
365
|
-
top: 60rpx;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
.sw-toast--bottom {
|
|
369
|
-
bottom: 60rpx;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
v-show="showToast"
|
|
4
|
+
ref="toastRef"
|
|
5
|
+
class="sw-toast"
|
|
6
|
+
:class="[
|
|
7
|
+
`sw-toast--${type}`,
|
|
8
|
+
`sw-toast--${position}`,
|
|
9
|
+
{ 'sw-toast--large': large },
|
|
10
|
+
{ 'sw-toast--text': !showIcon && type === 'text' },
|
|
11
|
+
{ 'sw-toast--show': showToast && !isClosing },
|
|
12
|
+
{ 'sw-toast--hide': showToast && isClosing },
|
|
13
|
+
]"
|
|
14
|
+
:style="customStyle"
|
|
15
|
+
@click="onClick"
|
|
16
|
+
@transitionend="handleTransitionEnd"
|
|
17
|
+
>
|
|
18
|
+
<!-- 加载图标 -->
|
|
19
|
+
<view v-if="loading" class="sw-toast__loading">
|
|
20
|
+
<text v-if="!customIcon" class="sw-toast__spinner" />
|
|
21
|
+
<text v-else class="sw-toast__custom-icon">{{ customIcon }}</text>
|
|
22
|
+
</view>
|
|
23
|
+
|
|
24
|
+
<!-- 状态图标 -->
|
|
25
|
+
<view v-else-if="showIcon" class="sw-toast__icon">
|
|
26
|
+
<text v-if="type === 'success'" class="sw-toast__icon--success">✓</text>
|
|
27
|
+
<text v-else-if="type === 'fail'" class="sw-toast__icon--fail">✗</text>
|
|
28
|
+
<text v-else-if="customIcon" class="sw-toast__custom-icon">{{ customIcon }}</text>
|
|
29
|
+
</view>
|
|
30
|
+
|
|
31
|
+
<!-- 文本内容 -->
|
|
32
|
+
<text v-if="message" class="sw-toast__text">{{ message }}</text>
|
|
33
|
+
</view>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
38
|
+
|
|
39
|
+
// Props
|
|
40
|
+
interface Props {
|
|
41
|
+
/**
|
|
42
|
+
* 控制显示/隐藏(支持v-model)
|
|
43
|
+
*/
|
|
44
|
+
modelValue?: boolean
|
|
45
|
+
/**
|
|
46
|
+
* 提示类型
|
|
47
|
+
*/
|
|
48
|
+
type?: 'text' | 'loading' | 'success' | 'fail'
|
|
49
|
+
/**
|
|
50
|
+
* 显示位置
|
|
51
|
+
*/
|
|
52
|
+
position?: 'top' | 'middle' | 'bottom'
|
|
53
|
+
/**
|
|
54
|
+
* 提示文字
|
|
55
|
+
*/
|
|
56
|
+
message?: string
|
|
57
|
+
/**
|
|
58
|
+
* 自动关闭时间(毫秒),0表示不会自动关闭
|
|
59
|
+
*/
|
|
60
|
+
duration?: number
|
|
61
|
+
/**
|
|
62
|
+
* 是否显示加载图标
|
|
63
|
+
*/
|
|
64
|
+
loading?: boolean
|
|
65
|
+
/**
|
|
66
|
+
* 是否显示图标
|
|
67
|
+
*/
|
|
68
|
+
icon?: boolean
|
|
69
|
+
/**
|
|
70
|
+
* 自定义图标
|
|
71
|
+
*/
|
|
72
|
+
customIcon?: string
|
|
73
|
+
/**
|
|
74
|
+
* 是否为大尺寸
|
|
75
|
+
*/
|
|
76
|
+
large?: boolean
|
|
77
|
+
/**
|
|
78
|
+
* 自定义样式
|
|
79
|
+
*/
|
|
80
|
+
customStyle?: Record<string, any>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
84
|
+
modelValue: false,
|
|
85
|
+
type: 'text',
|
|
86
|
+
position: 'middle',
|
|
87
|
+
message: '',
|
|
88
|
+
duration: 3000,
|
|
89
|
+
loading: false,
|
|
90
|
+
icon: true,
|
|
91
|
+
customIcon: '',
|
|
92
|
+
large: false,
|
|
93
|
+
customStyle: () => ({}),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// Emits
|
|
97
|
+
const emit = defineEmits<{
|
|
98
|
+
/**
|
|
99
|
+
* 显示状态变化时触发
|
|
100
|
+
*/
|
|
101
|
+
(e: 'update:modelValue', value: boolean): void
|
|
102
|
+
/**
|
|
103
|
+
* 关闭时触发
|
|
104
|
+
*/
|
|
105
|
+
(e: 'close'): void
|
|
106
|
+
/**
|
|
107
|
+
* 点击时触发
|
|
108
|
+
*/
|
|
109
|
+
(e: 'click'): void
|
|
110
|
+
}>()
|
|
111
|
+
|
|
112
|
+
// Refs
|
|
113
|
+
const toastRef = ref<any>(null)
|
|
114
|
+
let timer: number | null | ReturnType<typeof setTimeout> = null
|
|
115
|
+
|
|
116
|
+
// 内部状态
|
|
117
|
+
const showToast = ref(props.modelValue)
|
|
118
|
+
const isClosing = ref(false)
|
|
119
|
+
|
|
120
|
+
// 计算是否需要显示图标
|
|
121
|
+
const showIcon = computed(() => {
|
|
122
|
+
if (props.loading)
|
|
123
|
+
return true
|
|
124
|
+
if (props.type === 'text')
|
|
125
|
+
return props.icon
|
|
126
|
+
return true
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// 点击事件处理
|
|
130
|
+
function onClick() {
|
|
131
|
+
emit('click')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 关闭Toast
|
|
135
|
+
function close() {
|
|
136
|
+
if (!showToast.value)
|
|
137
|
+
return
|
|
138
|
+
|
|
139
|
+
// 添加关闭动画
|
|
140
|
+
isClosing.value = true
|
|
141
|
+
emit('close')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 自动关闭定时器
|
|
145
|
+
function startTimer() {
|
|
146
|
+
// 清除之前的定时器
|
|
147
|
+
clearTimer()
|
|
148
|
+
|
|
149
|
+
if (props.duration > 0 && !props.loading) {
|
|
150
|
+
timer = setTimeout(() => {
|
|
151
|
+
close()
|
|
152
|
+
}, props.duration)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 清除定时器
|
|
157
|
+
function clearTimer() {
|
|
158
|
+
if (timer) {
|
|
159
|
+
clearTimeout(timer)
|
|
160
|
+
timer = null
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 过渡结束处理
|
|
165
|
+
function handleTransitionEnd() {
|
|
166
|
+
if (isClosing.value) {
|
|
167
|
+
showToast.value = false
|
|
168
|
+
isClosing.value = false
|
|
169
|
+
emit('update:modelValue', false)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 监听modelValue变化
|
|
174
|
+
watch(() => props.modelValue, (newVal) => {
|
|
175
|
+
if (newVal) {
|
|
176
|
+
// 显示Toast
|
|
177
|
+
showToast.value = true
|
|
178
|
+
isClosing.value = false
|
|
179
|
+
startTimer()
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// 隐藏Toast
|
|
183
|
+
close()
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
// 监听message变化,重新启动定时器
|
|
188
|
+
watch(() => props.message, () => {
|
|
189
|
+
if (showToast.value && !props.loading) {
|
|
190
|
+
startTimer()
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
// 生命周期
|
|
195
|
+
onMounted(() => {
|
|
196
|
+
if (props.modelValue) {
|
|
197
|
+
startTimer()
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
onUnmounted(() => {
|
|
202
|
+
clearTimer()
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
// 暴露方法
|
|
206
|
+
defineExpose({
|
|
207
|
+
/**
|
|
208
|
+
* 手动关闭Toast
|
|
209
|
+
*/
|
|
210
|
+
close,
|
|
211
|
+
})
|
|
212
|
+
</script>
|
|
213
|
+
|
|
214
|
+
<style scoped>
|
|
215
|
+
.sw-toast {
|
|
216
|
+
display: inline-flex;
|
|
217
|
+
align-items: center;
|
|
218
|
+
justify-content: center;
|
|
219
|
+
max-width: 80%;
|
|
220
|
+
padding: 20rpx 32rpx;
|
|
221
|
+
border-radius: 8rpx;
|
|
222
|
+
font-size: 28rpx;
|
|
223
|
+
line-height: 40rpx;
|
|
224
|
+
color: #fff;
|
|
225
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
226
|
+
box-sizing: border-box;
|
|
227
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
228
|
+
z-index: 9999;
|
|
229
|
+
position: fixed;
|
|
230
|
+
left: 50%;
|
|
231
|
+
transform: translateX(-50%) translateY(0);
|
|
232
|
+
word-wrap: break-word;
|
|
233
|
+
white-space: pre-wrap;
|
|
234
|
+
user-select: none;
|
|
235
|
+
opacity: 0;
|
|
236
|
+
visibility: hidden;
|
|
237
|
+
pointer-events: none;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* 显示动画 */
|
|
241
|
+
.sw-toast--show {
|
|
242
|
+
opacity: 1;
|
|
243
|
+
visibility: visible;
|
|
244
|
+
pointer-events: auto;
|
|
245
|
+
transform: translateX(-50%) translateY(0);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* 隐藏动画 */
|
|
249
|
+
.sw-toast--hide {
|
|
250
|
+
opacity: 0;
|
|
251
|
+
transform: translateX(-50%) translateY(-20rpx);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* 位置样式 */
|
|
255
|
+
.sw-toast--top {
|
|
256
|
+
top: 100rpx;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.sw-toast--middle {
|
|
260
|
+
top: 50%;
|
|
261
|
+
transform: translate(-50%, -50%);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.sw-toast--middle.sw-toast--show {
|
|
265
|
+
transform: translate(-50%, -50%);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.sw-toast--middle.sw-toast--hide {
|
|
269
|
+
transform: translate(-50%, -60%);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.sw-toast--bottom {
|
|
273
|
+
bottom: 100rpx;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* 类型样式 */
|
|
277
|
+
.sw-toast--text {
|
|
278
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.sw-toast--loading {
|
|
282
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.sw-toast--success {
|
|
286
|
+
background-color: #67c23a;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.sw-toast--fail {
|
|
290
|
+
background-color: #f56c6c;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* 大尺寸样式 */
|
|
294
|
+
.sw-toast--large {
|
|
295
|
+
padding: 32rpx 48rpx;
|
|
296
|
+
font-size: 32rpx;
|
|
297
|
+
line-height: 48rpx;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/* 加载图标 */
|
|
301
|
+
.sw-toast__loading {
|
|
302
|
+
margin-right: 16rpx;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/* 加载动画 */
|
|
306
|
+
.sw-toast__spinner {
|
|
307
|
+
display: inline-block;
|
|
308
|
+
width: 40rpx;
|
|
309
|
+
height: 40rpx;
|
|
310
|
+
border: 4rpx solid rgba(255, 255, 255, 0.3);
|
|
311
|
+
border-radius: 50%;
|
|
312
|
+
border-top-color: #fff;
|
|
313
|
+
animation: sw-toast-spin 0.8s linear infinite;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/* 自定义图标 */
|
|
317
|
+
.sw-toast__custom-icon {
|
|
318
|
+
font-size: 40rpx;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/* 状态图标 */
|
|
322
|
+
.sw-toast__icon {
|
|
323
|
+
margin-right: 16rpx;
|
|
324
|
+
|
|
325
|
+
&--success,
|
|
326
|
+
&--fail {
|
|
327
|
+
display: inline-block;
|
|
328
|
+
width: 40rpx;
|
|
329
|
+
height: 40rpx;
|
|
330
|
+
font-size: 40rpx;
|
|
331
|
+
font-weight: bold;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/* 文本内容 */
|
|
336
|
+
.sw-toast__text {
|
|
337
|
+
margin: 0;
|
|
338
|
+
word-wrap: break-word;
|
|
339
|
+
white-space: pre-wrap;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/* 加载动画 */
|
|
343
|
+
@keyframes sw-toast-spin {
|
|
344
|
+
to {
|
|
345
|
+
transform: rotate(360deg);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/* 响应式设计 */
|
|
350
|
+
@media (max-width: 768px) {
|
|
351
|
+
.sw-toast {
|
|
352
|
+
max-width: 90%;
|
|
353
|
+
padding: 16rpx 24rpx;
|
|
354
|
+
font-size: 26rpx;
|
|
355
|
+
line-height: 36rpx;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.sw-toast--large {
|
|
359
|
+
padding: 24rpx 40rpx;
|
|
360
|
+
font-size: 30rpx;
|
|
361
|
+
line-height: 44rpx;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.sw-toast--top {
|
|
365
|
+
top: 60rpx;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.sw-toast--bottom {
|
|
369
|
+
bottom: 60rpx;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
</style>
|
|
373
|
+
|