uniapp-dyckui 4.1.1
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/LICENSE +21 -0
- package/README.md +104 -0
- package/dist/assets/style.BFlsbpSj.css +1472 -0
- package/dist/index.cjs.js +1380 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.es.js +1380 -0
- package/dist/index.es.js.map +1 -0
- package/dist/src/components/MyComs/Button/index.d.ts +3 -0
- package/dist/src/components/MyComs/Button/index.vue.d.ts +93 -0
- package/dist/src/components/MyComs/Dialog/index.d.ts +3 -0
- package/dist/src/components/MyComs/Dialog/index.vue.d.ts +65 -0
- package/dist/src/components/MyComs/Divider/index.d.ts +3 -0
- package/dist/src/components/MyComs/Divider/index.vue.d.ts +53 -0
- package/dist/src/components/MyComs/DropdownSelect/dropdownSelect.d.ts +10 -0
- package/dist/src/components/MyComs/DropdownSelect/index.d.ts +4 -0
- package/dist/src/components/MyComs/DropdownSelect/index.vue.d.ts +26 -0
- package/dist/src/components/MyComs/DropdownSelect/type.d.ts +13 -0
- package/dist/src/components/MyComs/DropdownWithBadge/dropdownWithBadge.d.ts +5 -0
- package/dist/src/components/MyComs/DropdownWithBadge/index.d.ts +4 -0
- package/dist/src/components/MyComs/DropdownWithBadge/index.vue.d.ts +26 -0
- package/dist/src/components/MyComs/DropdownWithBadge/type.d.ts +9 -0
- package/dist/src/components/MyComs/FilterDrawer/hasBadge.d.ts +8 -0
- package/dist/src/components/MyComs/FilterDrawer/index.d.ts +5 -0
- package/dist/src/components/MyComs/FilterDrawer/index.vue.d.ts +26 -0
- package/dist/src/components/MyComs/FilterDrawer/type.d.ts +8 -0
- package/dist/src/components/MyComs/FilterDrawer/useFilterDrawer.d.ts +10 -0
- package/dist/src/components/MyComs/InfiniteScroll/index.d.ts +3 -0
- package/dist/src/components/MyComs/InfiniteScroll/index.vue.d.ts +65 -0
- package/dist/src/components/MyComs/Popup/index.d.ts +3 -0
- package/dist/src/components/MyComs/Popup/index.vue.d.ts +119 -0
- package/dist/src/components/MyComs/PullRefresh/index.d.ts +3 -0
- package/dist/src/components/MyComs/PullRefresh/index.vue.d.ts +117 -0
- package/dist/src/components/MyComs/Swiper/index.d.ts +3 -0
- package/dist/src/components/MyComs/Swiper/index.vue.d.ts +79 -0
- package/dist/src/components/MyComs/Toast/index.d.ts +3 -0
- package/dist/src/components/MyComs/Toast/index.vue.d.ts +108 -0
- package/dist/src/components/MyComs/index.d.ts +20 -0
- package/package.json +218 -0
- package/src/components/MyComs/Button/README.md +235 -0
- package/src/components/MyComs/Button/index.ts +3 -0
- package/src/components/MyComs/Button/index.vue +413 -0
- package/src/components/MyComs/Dialog/README.md +160 -0
- package/src/components/MyComs/Dialog/index.ts +2 -0
- package/src/components/MyComs/Dialog/index.vue +275 -0
- package/src/components/MyComs/Divider/README.md +0 -0
- package/src/components/MyComs/Divider/index.ts +2 -0
- package/src/components/MyComs/Divider/index.vue +106 -0
- package/src/components/MyComs/DropdownSelect/README.md +112 -0
- package/src/components/MyComs/DropdownSelect/dropdownSelect.less +75 -0
- package/src/components/MyComs/DropdownSelect/dropdownSelect.ts +59 -0
- package/src/components/MyComs/DropdownSelect/index.ts +4 -0
- package/src/components/MyComs/DropdownSelect/index.vue +88 -0
- package/src/components/MyComs/DropdownSelect/type.ts +15 -0
- package/src/components/MyComs/DropdownWithBadge/README.md +77 -0
- package/src/components/MyComs/DropdownWithBadge/dropdownWithBadge.less +11 -0
- package/src/components/MyComs/DropdownWithBadge/dropdownWithBadge.ts +10 -0
- package/src/components/MyComs/DropdownWithBadge/index.ts +4 -0
- package/src/components/MyComs/DropdownWithBadge/index.vue +39 -0
- package/src/components/MyComs/DropdownWithBadge/type.ts +12 -0
- package/src/components/MyComs/FilterDrawer/filterDrawer.less +117 -0
- package/src/components/MyComs/FilterDrawer/hasBadge.ts +41 -0
- package/src/components/MyComs/FilterDrawer/index.ts +5 -0
- package/src/components/MyComs/FilterDrawer/index.vue +53 -0
- package/src/components/MyComs/FilterDrawer/type.ts +9 -0
- package/src/components/MyComs/FilterDrawer/useFilterDrawer.ts +38 -0
- package/src/components/MyComs/InfiniteScroll/index.ts +2 -0
- package/src/components/MyComs/InfiniteScroll/index.vue +171 -0
- package/src/components/MyComs/Popup/README.md +684 -0
- package/src/components/MyComs/Popup/index.ts +2 -0
- package/src/components/MyComs/Popup/index.vue +835 -0
- package/src/components/MyComs/PullRefresh/README.md +600 -0
- package/src/components/MyComs/PullRefresh/index.ts +2 -0
- package/src/components/MyComs/PullRefresh/index.vue +599 -0
- package/src/components/MyComs/Swiper/README.md +202 -0
- package/src/components/MyComs/Swiper/index.ts +2 -0
- package/src/components/MyComs/Swiper/index.vue +245 -0
- package/src/components/MyComs/Toast/README.md +604 -0
- package/src/components/MyComs/Toast/index.ts +2 -0
- package/src/components/MyComs/Toast/index.vue +372 -0
- package/src/components/MyComs/index.ts +33 -0
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
# 轻提示组件 (SwToast)
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://vuejs.org/)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://uniapp.dcloud.net.cn/)
|
|
7
|
+
|
|
8
|
+
## 📋 目录
|
|
9
|
+
|
|
10
|
+
- [组件介绍](#组件介绍)
|
|
11
|
+
- [主要特性](#主要特性)
|
|
12
|
+
- [适用场景](#适用场景)
|
|
13
|
+
- [安装使用](#安装使用)
|
|
14
|
+
- [API文档](#api文档)
|
|
15
|
+
- [使用示例](#使用示例)
|
|
16
|
+
- [高级用法](#高级用法)
|
|
17
|
+
- [最佳实践](#最佳实践)
|
|
18
|
+
- [常见问题](#常见问题)
|
|
19
|
+
- [浏览器兼容性](#浏览器兼容性)
|
|
20
|
+
|
|
21
|
+
## 🌟 组件介绍
|
|
22
|
+
|
|
23
|
+
SwToast 是一个功能强大、高度可定制的移动端轻提示组件,专为 uni-app 框架设计。该组件支持多种提示类型、位置和样式,提供了丰富的交互功能和优秀的用户体验。
|
|
24
|
+
|
|
25
|
+
### 主要特性
|
|
26
|
+
|
|
27
|
+
- ✨ **多种提示类型**:支持文字、加载、成功、失败四种提示类型
|
|
28
|
+
- 📍 **灵活位置**:支持顶部、中部、底部三种显示位置
|
|
29
|
+
- ⏱️ **智能控制**:可配置自动关闭时间,支持手动控制
|
|
30
|
+
- 🎨 **样式定制**:支持自定义样式、图标和尺寸
|
|
31
|
+
- 🎭 **动画效果**:流畅的显示和隐藏动画
|
|
32
|
+
- 📱 **响应式设计**:完美适配不同屏幕尺寸
|
|
33
|
+
- 🔧 **TypeScript支持**:完整的类型定义
|
|
34
|
+
- ⚡ **高性能**:轻量级实现,零依赖
|
|
35
|
+
|
|
36
|
+
### 适用场景
|
|
37
|
+
|
|
38
|
+
- **操作反馈**:用户操作后的成功或失败提示
|
|
39
|
+
- **加载状态**:异步操作进行中的状态提示
|
|
40
|
+
- **信息通知**:重要信息的临时展示
|
|
41
|
+
- **引导提示**:帮助用户理解应用功能
|
|
42
|
+
- **状态监控**:实时状态变化的反馈
|
|
43
|
+
|
|
44
|
+
## 🚀 安装使用
|
|
45
|
+
|
|
46
|
+
### 1. 组件引入
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// 全局引入(推荐)
|
|
50
|
+
import SwToast from '@/components/MyComs/Toast/index.vue'
|
|
51
|
+
|
|
52
|
+
// 在页面中引入
|
|
53
|
+
import { ref } from 'vue'
|
|
54
|
+
import SwToast from '@/components/MyComs/Toast/index.vue'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. 基础用法
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<template>
|
|
61
|
+
<view class="container">
|
|
62
|
+
<button @click="showBasicToast = true">显示提示</button>
|
|
63
|
+
|
|
64
|
+
<SwToast
|
|
65
|
+
v-model="showBasicToast"
|
|
66
|
+
message="操作成功"
|
|
67
|
+
/>
|
|
68
|
+
</view>
|
|
69
|
+
</template>
|
|
70
|
+
|
|
71
|
+
<script setup lang="ts">
|
|
72
|
+
import { ref } from 'vue'
|
|
73
|
+
import SwToast from '@/components/MyComs/Toast/index.vue'
|
|
74
|
+
|
|
75
|
+
const showBasicToast = ref(false)
|
|
76
|
+
</script>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 📖 API文档
|
|
80
|
+
|
|
81
|
+
### Props 参数
|
|
82
|
+
|
|
83
|
+
| 参数名 | 类型 | 默认值 | 说明 | 可选值 |
|
|
84
|
+
|--------|------|--------|------|--------|
|
|
85
|
+
| `modelValue` | `boolean` | `false` | 控制显示/隐藏(支持v-model) | `true/false` |
|
|
86
|
+
| `type` | `'text' \| 'loading' \| 'success' \| 'fail'` | `'text'` | 提示类型 | `text/loading/success/fail` |
|
|
87
|
+
| `position` | `'top' \| 'middle' \| 'bottom'` | `'middle'` | 显示位置 | `top/middle/bottom` |
|
|
88
|
+
| `message` | `string` | `''` | 提示文字内容 | - |
|
|
89
|
+
| `duration` | `number` | `3000` | 自动关闭时间(毫秒),0表示不自动关闭 | - |
|
|
90
|
+
| `loading` | `boolean` | `false` | 是否显示加载图标 | `true/false` |
|
|
91
|
+
| `icon` | `boolean` | `true` | 是否显示图标 | `true/false` |
|
|
92
|
+
| `customIcon` | `string` | `''` | 自定义图标字符 | - |
|
|
93
|
+
| `large` | `boolean` | `false` | 是否为大尺寸模式 | `true/false` |
|
|
94
|
+
| `customStyle` | `Record<string, any>` | `{}` | 自定义样式对象 | - |
|
|
95
|
+
|
|
96
|
+
### Emits 事件
|
|
97
|
+
|
|
98
|
+
| 事件名 | 说明 | 参数 |
|
|
99
|
+
|--------|------|------|
|
|
100
|
+
| `update:modelValue` | 显示状态变化时触发 | `value: boolean` - 新的显示状态 |
|
|
101
|
+
| `close` | Toast关闭时触发 | - |
|
|
102
|
+
| `click` | Toast被点击时触发 | - |
|
|
103
|
+
|
|
104
|
+
### Methods 方法
|
|
105
|
+
|
|
106
|
+
| 方法名 | 说明 |
|
|
107
|
+
|--------|------|
|
|
108
|
+
| `close()` | 手动关闭Toast |
|
|
109
|
+
|
|
110
|
+
## 💡 使用示例
|
|
111
|
+
|
|
112
|
+
### 基础用法
|
|
113
|
+
|
|
114
|
+
#### 文字提示
|
|
115
|
+
```vue
|
|
116
|
+
<SwToast
|
|
117
|
+
v-model="showTextToast"
|
|
118
|
+
type="text"
|
|
119
|
+
message="这是一个文字提示"
|
|
120
|
+
/>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### 加载提示
|
|
124
|
+
```vue
|
|
125
|
+
<SwToast
|
|
126
|
+
v-model="showLoadingToast"
|
|
127
|
+
type="loading"
|
|
128
|
+
message="正在加载中..."
|
|
129
|
+
/>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### 状态提示
|
|
133
|
+
```vue
|
|
134
|
+
<!-- 成功提示 -->
|
|
135
|
+
<SwToast
|
|
136
|
+
v-model="showSuccessToast"
|
|
137
|
+
type="success"
|
|
138
|
+
message="操作成功!"
|
|
139
|
+
/>
|
|
140
|
+
|
|
141
|
+
<!-- 失败提示 -->
|
|
142
|
+
<SwToast
|
|
143
|
+
v-model="showFailToast"
|
|
144
|
+
type="fail"
|
|
145
|
+
message="操作失败,请重试"
|
|
146
|
+
/>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 高级用法
|
|
150
|
+
|
|
151
|
+
#### 位置控制
|
|
152
|
+
```vue
|
|
153
|
+
<!-- 顶部提示 -->
|
|
154
|
+
<SwToast
|
|
155
|
+
v-model="showTopToast"
|
|
156
|
+
position="top"
|
|
157
|
+
message="顶部提示信息"
|
|
158
|
+
/>
|
|
159
|
+
|
|
160
|
+
<!-- 中部提示 -->
|
|
161
|
+
<SwToast
|
|
162
|
+
v-model="showMiddleToast"
|
|
163
|
+
position="middle"
|
|
164
|
+
message="中部提示信息"
|
|
165
|
+
/>
|
|
166
|
+
|
|
167
|
+
<!-- 底部提示 -->
|
|
168
|
+
<SwToast
|
|
169
|
+
v-model="showBottomToast"
|
|
170
|
+
position="bottom"
|
|
171
|
+
message="底部提示信息"
|
|
172
|
+
/>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### 自定义样式
|
|
176
|
+
```vue
|
|
177
|
+
<!-- 自定义背景色 -->
|
|
178
|
+
<SwToast
|
|
179
|
+
v-model="showCustomToast"
|
|
180
|
+
message="自定义样式"
|
|
181
|
+
:customStyle="{
|
|
182
|
+
backgroundColor: '#e6a23c',
|
|
183
|
+
color: '#fff'
|
|
184
|
+
}"
|
|
185
|
+
/>
|
|
186
|
+
|
|
187
|
+
<!-- 自定义图标 -->
|
|
188
|
+
<SwToast
|
|
189
|
+
v-model="showCustomIconToast"
|
|
190
|
+
message="自定义图标"
|
|
191
|
+
custom-icon="⚠️"
|
|
192
|
+
/>
|
|
193
|
+
|
|
194
|
+
<!-- 大尺寸模式 -->
|
|
195
|
+
<SwToast
|
|
196
|
+
v-model="showLargeToast"
|
|
197
|
+
message="大号提示"
|
|
198
|
+
large
|
|
199
|
+
/>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### 时间控制
|
|
203
|
+
```vue
|
|
204
|
+
<!-- 快速关闭 -->
|
|
205
|
+
<SwToast
|
|
206
|
+
v-model="showQuickToast"
|
|
207
|
+
message="1秒后自动关闭"
|
|
208
|
+
:duration="1000"
|
|
209
|
+
/>
|
|
210
|
+
|
|
211
|
+
<!-- 长时间显示 -->
|
|
212
|
+
<SwToast
|
|
213
|
+
v-model="showLongToast"
|
|
214
|
+
message="5秒后自动关闭"
|
|
215
|
+
:duration="5000"
|
|
216
|
+
/>
|
|
217
|
+
|
|
218
|
+
<!-- 手动关闭 -->
|
|
219
|
+
<SwToast
|
|
220
|
+
v-model="showManualToast"
|
|
221
|
+
message="需要手动点击关闭"
|
|
222
|
+
:duration="0"
|
|
223
|
+
/>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### 完整示例
|
|
227
|
+
|
|
228
|
+
```vue
|
|
229
|
+
<template>
|
|
230
|
+
<view class="demo-container">
|
|
231
|
+
<!-- 操作按钮 -->
|
|
232
|
+
<view class="button-group">
|
|
233
|
+
<button @click="showSuccess">成功提示</button>
|
|
234
|
+
<button @click="showError">错误提示</button>
|
|
235
|
+
<button @click="showLoading">加载提示</button>
|
|
236
|
+
<button @click="showCustom">自定义提示</button>
|
|
237
|
+
</view>
|
|
238
|
+
|
|
239
|
+
<!-- Toast组件 -->
|
|
240
|
+
<SwToast
|
|
241
|
+
v-model="showToast"
|
|
242
|
+
:type="toastType"
|
|
243
|
+
:message="toastMessage"
|
|
244
|
+
:position="toastPosition"
|
|
245
|
+
:duration="toastDuration"
|
|
246
|
+
:customStyle="customStyle"
|
|
247
|
+
:customIcon="customIcon"
|
|
248
|
+
@close="onToastClose"
|
|
249
|
+
@click="onToastClick"
|
|
250
|
+
/>
|
|
251
|
+
</view>
|
|
252
|
+
</template>
|
|
253
|
+
|
|
254
|
+
<script setup lang="ts">
|
|
255
|
+
import { ref } from 'vue'
|
|
256
|
+
import SwToast from '@/components/MyComs/Toast/index.vue'
|
|
257
|
+
|
|
258
|
+
// Toast控制状态
|
|
259
|
+
const showToast = ref(false)
|
|
260
|
+
const toastType = ref<'text' | 'loading' | 'success' | 'fail'>('text')
|
|
261
|
+
const toastMessage = ref('')
|
|
262
|
+
const toastPosition = ref<'top' | 'middle' | 'bottom'>('middle')
|
|
263
|
+
const toastDuration = ref(3000)
|
|
264
|
+
const customStyle = ref({})
|
|
265
|
+
const customIcon = ref('')
|
|
266
|
+
|
|
267
|
+
// 显示不同类型的Toast
|
|
268
|
+
const showSuccess = () => {
|
|
269
|
+
toastType.value = 'success'
|
|
270
|
+
toastMessage.value = '操作成功!'
|
|
271
|
+
showToast.value = true
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const showError = () => {
|
|
275
|
+
toastType.value = 'fail'
|
|
276
|
+
toastMessage.value = '操作失败,请重试'
|
|
277
|
+
showToast.value = true
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const showLoading = () => {
|
|
281
|
+
toastType.value = 'loading'
|
|
282
|
+
toastMessage.value = '正在处理中...'
|
|
283
|
+
toastDuration.value = 0 // 加载提示不自动关闭
|
|
284
|
+
showToast.value = true
|
|
285
|
+
|
|
286
|
+
// 模拟异步操作
|
|
287
|
+
setTimeout(() => {
|
|
288
|
+
showToast.value = false
|
|
289
|
+
toastDuration.value = 3000 // 重置默认值
|
|
290
|
+
}, 2000)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const showCustom = () => {
|
|
294
|
+
toastType.value = 'text'
|
|
295
|
+
toastMessage.value = '自定义样式提示'
|
|
296
|
+
toastPosition.value = 'bottom'
|
|
297
|
+
customStyle.value = {
|
|
298
|
+
backgroundColor: '#ff6b6b',
|
|
299
|
+
color: '#fff',
|
|
300
|
+
borderRadius: '12rpx'
|
|
301
|
+
}
|
|
302
|
+
customIcon.value = '🎯'
|
|
303
|
+
showToast.value = true
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 事件处理
|
|
307
|
+
const onToastClose = () => {
|
|
308
|
+
console.log('Toast已关闭')
|
|
309
|
+
// 清理自定义样式
|
|
310
|
+
customStyle.value = {}
|
|
311
|
+
customIcon.value = ''
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const onToastClick = () => {
|
|
315
|
+
console.log('Toast被点击')
|
|
316
|
+
}
|
|
317
|
+
</script>
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## 🛠️ 高级用法
|
|
321
|
+
|
|
322
|
+
### 组合使用模式
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
// 创建Toast服务
|
|
326
|
+
class ToastService {
|
|
327
|
+
private static instance: ToastService
|
|
328
|
+
private toastRef = ref<any>(null)
|
|
329
|
+
|
|
330
|
+
static getInstance() {
|
|
331
|
+
if (!ToastService.instance) {
|
|
332
|
+
ToastService.instance = new ToastService()
|
|
333
|
+
}
|
|
334
|
+
return ToastService.instance
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
show(options: ToastOptions) {
|
|
338
|
+
if (this.toastRef.value) {
|
|
339
|
+
Object.assign(this.toastRef.value, options, { show: true })
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
success(message: string, duration = 3000) {
|
|
344
|
+
this.show({ type: 'success', message, duration })
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
error(message: string, duration = 3000) {
|
|
348
|
+
this.show({ type: 'fail', message, duration })
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
loading(message = '加载中...') {
|
|
352
|
+
this.show({ type: 'loading', message, duration: 0 })
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
hide() {
|
|
356
|
+
if (this.toastRef.value) {
|
|
357
|
+
this.toastRef.value.show = false
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 使用示例
|
|
363
|
+
const toast = ToastService.getInstance()
|
|
364
|
+
|
|
365
|
+
// 在组件中使用
|
|
366
|
+
toast.success('操作成功!')
|
|
367
|
+
toast.error('操作失败')
|
|
368
|
+
toast.loading('正在处理...')
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### 与网络请求结合
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
// 请求拦截器中使用
|
|
375
|
+
import { alova } from '@/http/alova'
|
|
376
|
+
|
|
377
|
+
alova.interceptor.request((config) => {
|
|
378
|
+
// 显示加载提示
|
|
379
|
+
showLoadingToast.value = true
|
|
380
|
+
return config
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
alova.interceptor.response((response) => {
|
|
384
|
+
// 隐藏加载提示
|
|
385
|
+
showLoadingToast.value = false
|
|
386
|
+
|
|
387
|
+
if (response.success) {
|
|
388
|
+
showSuccessToast.value = true
|
|
389
|
+
} else {
|
|
390
|
+
showFailToast.value = true
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return response
|
|
394
|
+
})
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## 📋 最佳实践
|
|
398
|
+
|
|
399
|
+
### 1. 提示文案规范
|
|
400
|
+
|
|
401
|
+
- **简洁明了**:使用简短、准确的文案
|
|
402
|
+
- **积极语言**:优先使用积极、正面的表述
|
|
403
|
+
- **一致性**:保持同类操作提示的一致性
|
|
404
|
+
- **可操作性**:提供明确的操作建议
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
// ✅ 推荐
|
|
408
|
+
const successMessages = [
|
|
409
|
+
'保存成功',
|
|
410
|
+
'删除成功',
|
|
411
|
+
'操作成功'
|
|
412
|
+
]
|
|
413
|
+
|
|
414
|
+
const errorMessages = [
|
|
415
|
+
'保存失败,请重试',
|
|
416
|
+
'网络异常,请检查网络连接',
|
|
417
|
+
'参数错误,请检查输入'
|
|
418
|
+
]
|
|
419
|
+
|
|
420
|
+
// ❌ 不推荐
|
|
421
|
+
const badMessages = [
|
|
422
|
+
'出错了',
|
|
423
|
+
'失败',
|
|
424
|
+
'有问题'
|
|
425
|
+
]
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### 2. 时间控制建议
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
// 不同场景的建议时长
|
|
432
|
+
const durationConfig = {
|
|
433
|
+
success: 2000, // 成功提示:2秒
|
|
434
|
+
error: 4000, // 错误提示:4秒
|
|
435
|
+
warning: 3000, // 警告提示:3秒
|
|
436
|
+
info: 3000, // 信息提示:3秒
|
|
437
|
+
loading: 0 // 加载提示:不自动关闭
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### 3. 位置选择建议
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
// 不同场景的位置建议
|
|
445
|
+
const positionConfig = {
|
|
446
|
+
success: 'middle', // 成功提示:居中显示
|
|
447
|
+
error: 'middle', // 错误提示:居中显示
|
|
448
|
+
warning: 'top', // 警告提示:顶部显示
|
|
449
|
+
info: 'bottom', // 信息提示:底部显示
|
|
450
|
+
loading: 'middle' // 加载提示:居中显示
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### 4. 性能优化
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
// 使用防抖处理频繁操作
|
|
458
|
+
import { debounce } from '@/utils/debounce'
|
|
459
|
+
|
|
460
|
+
const showToastDebounced = debounce((message: string) => {
|
|
461
|
+
showToast.value = true
|
|
462
|
+
toastMessage.value = message
|
|
463
|
+
}, 300)
|
|
464
|
+
|
|
465
|
+
// 在事件中使用
|
|
466
|
+
const handleInput = (value: string) => {
|
|
467
|
+
if (error) {
|
|
468
|
+
showToastDebounced(error)
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
## ❓ 常见问题
|
|
474
|
+
|
|
475
|
+
### Q: Toast不显示怎么办?
|
|
476
|
+
|
|
477
|
+
A: 检查以下几点:
|
|
478
|
+
1. 确保 `modelValue` 为 `true`
|
|
479
|
+
2. 检查 `message` 是否有内容
|
|
480
|
+
3. 确认组件已正确引入
|
|
481
|
+
4. 检查样式是否被其他元素遮挡
|
|
482
|
+
|
|
483
|
+
### Q: 加载提示不自动关闭?
|
|
484
|
+
|
|
485
|
+
A: 这是正常行为,加载提示需要手动关闭或调用接口完成:
|
|
486
|
+
```typescript
|
|
487
|
+
// 方法1:手动关闭
|
|
488
|
+
<SwToast
|
|
489
|
+
v-model="showLoading"
|
|
490
|
+
type="loading"
|
|
491
|
+
message="加载中..."
|
|
492
|
+
/>
|
|
493
|
+
|
|
494
|
+
// 手动控制
|
|
495
|
+
function handleLoading() {
|
|
496
|
+
showLoading.value = false
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// 方法2:通过duration控制
|
|
500
|
+
<SwToast
|
|
501
|
+
:modelValue="showLoading"
|
|
502
|
+
type="loading"
|
|
503
|
+
message="加载中..."
|
|
504
|
+
:duration="5000" // 5秒后自动关闭
|
|
505
|
+
/>
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Q: 如何自定义样式?
|
|
509
|
+
|
|
510
|
+
A: 使用 `customStyle` 属性:
|
|
511
|
+
```vue
|
|
512
|
+
<SwToast
|
|
513
|
+
v-model="showCustom"
|
|
514
|
+
message="自定义样式"
|
|
515
|
+
:customStyle="{
|
|
516
|
+
backgroundColor: '#ff6b6b',
|
|
517
|
+
color: '#fff',
|
|
518
|
+
fontSize: '32rpx',
|
|
519
|
+
borderRadius: '12rpx',
|
|
520
|
+
padding: '20rpx 40rpx'
|
|
521
|
+
}"
|
|
522
|
+
/>
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### Q: 多个Toast同时显示怎么办?
|
|
526
|
+
|
|
527
|
+
A: 建议使用队列管理:
|
|
528
|
+
```typescript
|
|
529
|
+
class ToastQueue {
|
|
530
|
+
private queue: ToastItem[] = []
|
|
531
|
+
private showing = false
|
|
532
|
+
|
|
533
|
+
add(item: ToastItem) {
|
|
534
|
+
this.queue.push(item)
|
|
535
|
+
this.showNext()
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
private showNext() {
|
|
539
|
+
if (this.showing || this.queue.length === 0) return
|
|
540
|
+
|
|
541
|
+
this.showing = true
|
|
542
|
+
const item = this.queue.shift()!
|
|
543
|
+
|
|
544
|
+
// 显示Toast
|
|
545
|
+
showToast.value = true
|
|
546
|
+
// ... 其他逻辑
|
|
547
|
+
|
|
548
|
+
// 监听关闭事件
|
|
549
|
+
const unwatch = watch(() => showToast.value, (val) => {
|
|
550
|
+
if (!val) {
|
|
551
|
+
this.showing = false
|
|
552
|
+
unwatch()
|
|
553
|
+
setTimeout(() => this.showNext(), 100)
|
|
554
|
+
}
|
|
555
|
+
})
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
## 🌐 浏览器兼容性
|
|
561
|
+
|
|
562
|
+
| 浏览器 | 最低版本 | 状态 |
|
|
563
|
+
|--------|----------|------|
|
|
564
|
+
| iOS Safari | 9.0+ | ✅ 完全支持 |
|
|
565
|
+
| Android Browser | 4.4+ | ✅ 完全支持 |
|
|
566
|
+
| Chrome | 45+ | ✅ 完全支持 |
|
|
567
|
+
| Firefox | 40+ | ✅ 完全支持 |
|
|
568
|
+
| Edge | 15+ | ✅ 完全支持 |
|
|
569
|
+
| 微信小程序 | 最新版 | ✅ 完全支持 |
|
|
570
|
+
| 支付宝小程序 | 最新版 | ✅ 完全支持 |
|
|
571
|
+
| H5 | - | ✅ 完全支持 |
|
|
572
|
+
|
|
573
|
+
## 📄 更新日志
|
|
574
|
+
|
|
575
|
+
### v1.0.0 (2024-01-01)
|
|
576
|
+
- 🎉 初始版本发布
|
|
577
|
+
- ✨ 支持四种提示类型
|
|
578
|
+
- ✨ 支持三种显示位置
|
|
579
|
+
- ✨ 支持自定义样式和图标
|
|
580
|
+
- ✨ 完整的TypeScript类型定义
|
|
581
|
+
|
|
582
|
+
### v1.1.0 (计划中)
|
|
583
|
+
- 🔄 添加更多动画效果
|
|
584
|
+
- 🔄 支持批量Toast管理
|
|
585
|
+
- 🔄 添加Toast队列功能
|
|
586
|
+
- 🔄 优化性能表现
|
|
587
|
+
|
|
588
|
+
## 📞 支持与反馈
|
|
589
|
+
|
|
590
|
+
如果您在使用过程中遇到问题或有改进建议,欢迎通过以下方式联系:
|
|
591
|
+
|
|
592
|
+
- 📧 邮箱:support@example.com
|
|
593
|
+
- 🐛 问题反馈:[GitHub Issues](https://github.com/example/toast/issues)
|
|
594
|
+
- 📖 文档反馈:[GitHub Wiki](https://github.com/example/toast/wiki)
|
|
595
|
+
|
|
596
|
+
---
|
|
597
|
+
|
|
598
|
+
<div align="center">
|
|
599
|
+
|
|
600
|
+
**[⬆ 回到顶部](#轻提示组件-swtoast)**
|
|
601
|
+
|
|
602
|
+
Made with ❤️ by Sw Team
|
|
603
|
+
|
|
604
|
+
</div>
|