@gmcb/uv-ui 0.2.27 → 0.3.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.
Files changed (134) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -141
  3. package/docs/api/configs/color.md +52 -0
  4. package/docs/api/index.md +77 -0
  5. package/docs/api/mixins/mpShare.md +95 -0
  6. package/docs/api/request/apiManage.md +88 -0
  7. package/docs/api/request/http.md +451 -0
  8. package/docs/api/utils/colorSwitch.md +78 -0
  9. package/docs/api/utils/debounce.md +104 -0
  10. package/docs/api/utils/fastUse.md +246 -0
  11. package/docs/api/utils/getRect.md +238 -0
  12. package/docs/api/utils/guid.md +41 -0
  13. package/docs/api/utils/index.md +55 -0
  14. package/docs/api/utils/intro.md +25 -0
  15. package/docs/api/utils/object.md +171 -0
  16. package/docs/api/utils/queryParams.md +68 -0
  17. package/docs/api/utils/random.md +23 -0
  18. package/docs/api/utils/randomArray.md +28 -0
  19. package/docs/api/utils/route.md +121 -0
  20. package/docs/api/utils/test.md +237 -0
  21. package/docs/api/utils/time.md +81 -0
  22. package/docs/api/utils/trim.md +24 -0
  23. package/docs/components/actionSheet.md +236 -0
  24. package/docs/components/addQQGroup.md +5 -0
  25. package/docs/components/album.md +91 -0
  26. package/docs/components/alert.md +83 -0
  27. package/docs/components/avatar.md +152 -0
  28. package/docs/components/backTop.md +181 -0
  29. package/docs/components/badge.md +117 -0
  30. package/docs/components/button.md +196 -0
  31. package/docs/components/calendar.md +398 -0
  32. package/docs/components/calendars.md +294 -0
  33. package/docs/components/cell.md +185 -0
  34. package/docs/components/checkbox.md +281 -0
  35. package/docs/components/circleProgress.md +5 -0
  36. package/docs/components/code.md +162 -0
  37. package/docs/components/codeInput.md +175 -0
  38. package/docs/components/collapse.md +250 -0
  39. package/docs/components/color.md +324 -0
  40. package/docs/components/common.md +126 -0
  41. package/docs/components/countDown.md +166 -0
  42. package/docs/components/countTo.md +140 -0
  43. package/docs/components/datetimePicker.md +283 -0
  44. package/docs/components/diff1.x.md +190 -0
  45. package/docs/components/divider.md +88 -0
  46. package/docs/components/downloadSetting.md +54 -0
  47. package/docs/components/dropDown.md +375 -0
  48. package/docs/components/empty.md +99 -0
  49. package/docs/components/feature.md +261 -0
  50. package/docs/components/form.md +736 -0
  51. package/docs/components/gap.md +49 -0
  52. package/docs/components/grid.md +225 -0
  53. package/docs/components/icon.md +101 -0
  54. package/docs/components/image.md +182 -0
  55. package/docs/components/index.md +110 -0
  56. package/docs/components/indexList.md +133 -0
  57. package/docs/components/input.md +250 -0
  58. package/docs/components/install.md +59 -0
  59. package/docs/components/intro.md +32 -0
  60. package/docs/components/keyboard.md +226 -0
  61. package/docs/components/layout.md +310 -0
  62. package/docs/components/line.md +85 -0
  63. package/docs/components/lineProgress.md +141 -0
  64. package/docs/components/link.md +89 -0
  65. package/docs/components/list.md +223 -0
  66. package/docs/components/loadMore.md +140 -0
  67. package/docs/components/loadingIcon.md +144 -0
  68. package/docs/components/loadingPage.md +92 -0
  69. package/docs/components/modal.md +230 -0
  70. package/docs/components/more.md +13 -0
  71. package/docs/components/navbar.md +192 -0
  72. package/docs/components/noNetwork.md +116 -0
  73. package/docs/components/noticeBar.md +131 -0
  74. package/docs/components/notify.md +204 -0
  75. package/docs/components/npmSetting.md +64 -0
  76. package/docs/components/numberBox.md +257 -0
  77. package/docs/components/nvue.md +170 -0
  78. package/docs/components/overlay.md +117 -0
  79. package/docs/components/parse.md +204 -0
  80. package/docs/components/pickColor.md +112 -0
  81. package/docs/components/picker.md +357 -0
  82. package/docs/components/popup.md +221 -0
  83. package/docs/components/problem.md +300 -0
  84. package/docs/components/qrcode.md +169 -0
  85. package/docs/components/quickstart.md +33 -0
  86. package/docs/components/radio.md +256 -0
  87. package/docs/components/rate.md +128 -0
  88. package/docs/components/read.md +163 -0
  89. package/docs/components/readMore.md +227 -0
  90. package/docs/components/resource.md +17 -0
  91. package/docs/components/scrollList.md +218 -0
  92. package/docs/components/search.md +160 -0
  93. package/docs/components/setting.md +111 -0
  94. package/docs/components/settingDesc.md +66 -0
  95. package/docs/components/skeleton.md +105 -0
  96. package/docs/components/skeletons.md +323 -0
  97. package/docs/components/slider.md +157 -0
  98. package/docs/components/steps.md +189 -0
  99. package/docs/components/sticky.md +76 -0
  100. package/docs/components/subsection.md +183 -0
  101. package/docs/components/swipeAction.md +279 -0
  102. package/docs/components/swiper.md +352 -0
  103. package/docs/components/switch.md +216 -0
  104. package/docs/components/tabbar.md +263 -0
  105. package/docs/components/table.md +5 -0
  106. package/docs/components/tabs.md +364 -0
  107. package/docs/components/tag.md +227 -0
  108. package/docs/components/testPic.md +20 -0
  109. package/docs/components/text.md +157 -0
  110. package/docs/components/textarea.md +121 -0
  111. package/docs/components/toast.md +124 -0
  112. package/docs/components/tooltip.md +98 -0
  113. package/docs/components/transition.md +404 -0
  114. package/docs/components/upload.md +253 -0
  115. package/docs/components/vtabs.md +332 -0
  116. package/docs/components/vueUse.md +45 -0
  117. package/docs/components/vuexDetail.md +103 -0
  118. package/docs/components/waterfall.md +651 -0
  119. package/docs/faq/index.md +53 -0
  120. package/docs/guide/codeHint.md +44 -0
  121. package/docs/guide/customIcon.md +168 -0
  122. package/docs/guide/demo.md +92 -0
  123. package/docs/guide/design.md +56 -0
  124. package/docs/guide/globalVariable.md +239 -0
  125. package/docs/guide/i18n.md +194 -0
  126. package/docs/guide/index.md +28 -0
  127. package/docs/guide/note.md +74 -0
  128. package/docs/guide/safeAreaInset.md +64 -0
  129. package/docs/guide/theme.md +67 -0
  130. package/docs/index.md +88 -0
  131. package/libs/config/config.js +0 -10
  132. package/libs/css/color.scss +15 -14
  133. package/package.json +7 -2
  134. package/theme.scss +2 -1
@@ -0,0 +1,404 @@
1
+ ## Transition 动画 <to-api/>
2
+
3
+ <demo-model url="/pages/componentsA/transition/transition"></demo-model>
4
+
5
+ ::: tip ✈
6
+
7
+ **组件名:uv-transition**
8
+
9
+ [点击下载&安装](https://ext.dcloud.net.cn/plugin?name=uv-transition)
10
+
11
+ :::
12
+
13
+ 该组件用于元素的动画过渡效果,丰富的内置动画,支持自定义动画。
14
+
15
+ ### 平台兼容性
16
+
17
+ |App(vue)|App(nvue)|H5|小程序|VUE2|VUE3|
18
+ |:-:|:-:|:-:|:-:|:-:|:-:|
19
+ |√|√|√|√|√|√|
20
+
21
+ ### 基本使用
22
+
23
+ 通过`show`属性设置动画的打开和关闭
24
+
25
+ ```vue
26
+ <template>
27
+ <button type="default" @click="open">fade</button>
28
+ <uv-transition
29
+ :show="show"
30
+ :custom-style="{'width':'100px','height':'100px','backgroundColor':'#3c9cff'}"
31
+ @change="change">
32
+ </uv-transition>
33
+ </template>
34
+ <script setup>
35
+ import { ref } from 'vue';
36
+
37
+ const show = ref(false);
38
+ function open() {
39
+ show.value = !show.value;
40
+ }
41
+ function change(e) {
42
+ console.log('动画触发:', e);
43
+ }
44
+
45
+ </script>
46
+
47
+ ```
48
+
49
+ ### 动画模式
50
+
51
+ 通过`mode`属性设置动画的模式,默认`fade`。 比如设置`mode="zoom-in"`能达到由小到大过渡
52
+ 效果,更多模式见下[Mode Options](/components/transition.html#mode-options)
53
+
54
+ ```vue
55
+ <template>
56
+ <button type="default" @click="open">fade</button>
57
+ <uv-transition
58
+ :show="show"
59
+ mode="zoom-in"
60
+ :custom-style="{'width':'100px','height':'100px','backgroundColor':'#3c9cff'}"
61
+ @change="change">
62
+ </uv-transition>
63
+ </template>
64
+ <script setup>
65
+ import { ref } from 'vue';
66
+
67
+ const show = ref(false);
68
+ function open() {
69
+ show.value = !show.value;
70
+ }
71
+ function change(e) {
72
+ console.log('动画触发:', e);
73
+ }
74
+
75
+ </script>
76
+ ```
77
+
78
+ ### 自定义动画
79
+
80
+ 当内置动画类型不能满足需求的时候,可以使用 `step()` 和 `run()` 自定义动画,入参以及具体用法参考下方属性说明
81
+
82
+ `init()` 方法可以覆盖默认配置。方法及属性详情[参考下方](/components/transition.html#transition-methods)。
83
+
84
+ ```vue
85
+ <template>
86
+ <view>
87
+ <button type="primary" @click="run">执行动画</button>
88
+ <uv-transition
89
+ ref="ani"
90
+ :custom-style="{'width':'100px','height':'100px','backgroundColor':'#3c9cff'}"
91
+ :show="show" />
92
+ </view>
93
+ </template>
94
+
95
+ <script setup>
96
+ import { ref } from 'vue';
97
+ import { onReady } from '@dcloudio/uni-app';
98
+
99
+ const ani = ref(null);
100
+ const show = ref(true);
101
+ onReady(() => {
102
+ ani.value.init({
103
+ duration: 1000,
104
+ timingFunction: 'linear',
105
+ transformOrigin: '50% 50%',
106
+ delay: 500
107
+ });
108
+ });
109
+ function run() {
110
+ // 同时右平移到 100px,旋转 360 读
111
+ ani.value.step({
112
+ translateX: '100px',
113
+ rotate: '360'
114
+ });
115
+ // 上面的动画执行完成后,等待200毫秒平移到 0px,旋转到 0 读
116
+ ani.value.step({
117
+ translateX: '0px',
118
+ rotate: '0'
119
+ }, {
120
+ timingFunction: 'ease-in',
121
+ duration: 200
122
+ });
123
+ // 开始执行动画
124
+ ani.value.run(() => {
125
+ console.log('动画支持完毕');
126
+ });
127
+ }
128
+
129
+ </script>
130
+ ```
131
+
132
+ ### 完整示例
133
+
134
+ ::: tip 完整示例下载地址
135
+
136
+ [https://ext.dcloud.net.cn/plugin?name=uv-ui](https://ext.dcloud.net.cn/plugin?name=uv-ui)
137
+
138
+ :::
139
+
140
+ ### API
141
+ ---
142
+
143
+ ### Transition Props
144
+
145
+ | 参数 | 说明 | 类型 | 默认值 | 可选值 |
146
+ |:- |:- |:- |:- |:- |
147
+ | show | 控制组件显示或关闭 | Boolean | false | true &#124; false |
148
+ | mode | 内置过渡动画类型 | String | fade | 见下[Mode Options](/components/transition.html#mode-options) |
149
+ | duration | 动画的执行时间,单位`ms` | String &#124; Number | 300 | - |
150
+ | timingFunction| 使用的动画过渡函数,[详见](/components/transition.html#timingfunction属性说明) | String | ease-out | - |
151
+ | customClass | 自定义类名 | String | - | - |
152
+ | cellChild | 是否属于cell节点下。`nvue`模式下的该组件在cell或uv-list等组件下使用,该值最好是设置成true,避免回收后不显示的BUG。 | Boolean | false | true &#124; false|
153
+ | customStyle | 自定义样式 | Object | - | - |
154
+
155
+ ### Mode Options
156
+
157
+ **格式为:** `'fade'` 或者 `['fade','slide-top']`
158
+
159
+ **注意:** 组合使用时,同一种类型相反的过渡动画如(slide-top、slide-bottom)同时使用时,只有最后一个生效
160
+
161
+ | 属性值 | 说明 |
162
+ | :- | :- |
163
+ | fade | 渐隐渐出过渡 |
164
+ | slide-top | 由上至下过渡 |
165
+ | slide-bottom | 由下至上过渡 |
166
+ | slide-left | 由左至右过渡 |
167
+ | slide-right | 由右至左过渡 |
168
+ | zoom-in | 由小到大过渡 |
169
+ | zoom-out | 由大到小过渡 |
170
+
171
+ ### Transition Events
172
+
173
+ | 事件名 | 说明 | 回调参数 |
174
+ | :- | :- | :- |
175
+ | @click | 点击组件触发 | - |
176
+ | @change | 过渡动画结束时触发 | e = {detail:true &#124; false} |
177
+
178
+ ### Transition Methods
179
+
180
+ | 方法名 | 说明 | 回调参数 |
181
+ | :- | :- | :- |
182
+ | init() | 手动初始化配置 | Function(OBJECT:config) |
183
+ | step() | 动画队列 | Function(OBJECT:type,OBJECT:config) |
184
+ | run() | 执行动画 | Function(FUNCTION:callback) |
185
+
186
+ ### init(OBJECT:config) 初始化
187
+
188
+ - 通过`ref`调用该方法
189
+ - 手动设置动画配置,需要在页面渲染完毕后调用
190
+
191
+ ```js
192
+ const ani = ref(null);
193
+
194
+ ani.value?.init({
195
+ duration: 1000,
196
+ timingFunction: 'linear',
197
+ transformOrigin: '50% 50%',
198
+ delay: 500
199
+ })
200
+ ```
201
+
202
+ ### step(OBJECT:type,OBJECT:config) 动画队列
203
+
204
+ - 通过`ref`调用该方法
205
+ - 调用 `step()` 来表示一组动画完成,`step` 第一个参数可以传入任意多个动画方法,一组动画中的所有动画会同时开始,一组动画完成后才会进行下一组动画。`step` 第二个参数可以传入一个跟 `uni.createAnimation()` 一样的配置参数用于指定当前组动画的配置。
206
+ - 第一个参数支持的动画参考下面的 [支持的动画](/components/transition.html#timingfunction属性说明)
207
+ - 第二个参数参考下面的 [动画配置](/components/transition.html#动画配置),可省略,如果省略继承`init()`的配置
208
+ ```js
209
+ // 上平移到 100px,同时旋转到 90 度
210
+ const ani = ref(null);
211
+
212
+ ani.value?.step({
213
+ translateX: '100px',
214
+ rotate: '90'
215
+ },
216
+ {
217
+ timingFunction: 'ease-in',
218
+ duration: 200
219
+ })
220
+ ```
221
+
222
+ ### run(FUNCTION:callback) 执行动画
223
+
224
+ - 通过`ref`调用该方法
225
+ - 在执行 `step()` 后,需要调用 `run()` 来运行动画 ,否则动画会一直等待
226
+ - `run()` 方法可以传入一个 `callback` 函数 ,会在所有动画执行完毕后回调
227
+
228
+ ```js
229
+ // 开始执行动画,结束回调
230
+ const ani = ref(null);
231
+
232
+ ani.value?.run(() => {
233
+ console.log('动画支持完毕')
234
+ })
235
+ ```
236
+
237
+ ### 动画配置
238
+
239
+ 动画配置 , `init()` 与 `step()` 第二个参数配置相同 ,如果配置`step()`第二个参数,将会覆盖 `init()` 的配置
240
+
241
+ | 属性名 | 类型 | 默认值 | 说明 | 平台差异 |
242
+ | :- | :- | :- | :- | :- |
243
+ | duration | Number | 400 | 动画持续时间,单位`ms` | - |
244
+ | timingFunction | String | "linear" | - |
245
+ | delay | Number | 0 | 动画延迟时间,单位`ms` | - |
246
+ | needLayout | Boolean | false | 动画执行是否影响布局 | 仅 nvue 支持 |
247
+ | transformOrigin | String | "center center" | 设置 [transform-origin](https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin) | - |
248
+
249
+ ### timingFunction属性说明
250
+
251
+ | 属性名 | 说明 | 平台差异 |
252
+ | :- | :- | :- |
253
+ | linear | 动画从头到尾的速度是相同的 | - |
254
+ | ease | 动画以低速开始,然后加快,在结束前变慢 | - |
255
+ | ease-in | 动画以低速开始 | - |
256
+ | ease-in-out | 动画以低速开始和结束 | - |
257
+ | ease-out | 动画以低速结束 | - |
258
+ | step-start | 动画第一帧就跳至结束状态直到结束 | nvue不支持 |
259
+ | step-end | 动画一直保持开始状态,最后一帧跳到结束状态 | nvue不支持 |
260
+
261
+ ### 支持的动画
262
+
263
+ - 调用 `step()` 来表示一组动画完成
264
+ - 如果同一个动画方法有多个值,多个值使用数组分隔
265
+
266
+ ```js
267
+ const ani = ref(null);
268
+
269
+ ani.value?.step({
270
+ width:'100px',
271
+ scale: [1.2,0.8],
272
+ })
273
+ ```
274
+
275
+ #### **样式:**
276
+
277
+ |属性名|类型|说明|平台差异|
278
+ |:-|:-|:-|:-|
279
+ |opacity |Number| 透明度,参数范围 0~1| -|
280
+ |backgroundColor |Number &#124; String| 颜色值| -|
281
+ |width |Number &#124; String| 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值| -|
282
+ |height |Number &#124; String| 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值| -|
283
+ |top |Number &#124; String| 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值| nvue 不支持|
284
+ |left |Number &#124; String| 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值| nvue 不支持|
285
+ |bottom |Number &#124; String| 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值| nvue 不支持|
286
+ |right |Number &#124; String| 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值| nvue 不支持|
287
+
288
+ ```js
289
+ const ani = ref(null);
290
+
291
+ ani.value?.step({
292
+ opacity: 1,
293
+ backgroundColor: '#3c9cff',
294
+ widht:'100px',
295
+ height:'50rpx',
296
+ })
297
+ ```
298
+
299
+ #### **旋转:**
300
+
301
+ 旋转属性的值不需要填写单位
302
+
303
+ |属性名|值|说明|平台差异|
304
+ |:-|:-|:-|:-|
305
+ |rotate| deg |deg的范围-180~180,从原点顺时针旋转一个deg角度| -|
306
+ |rotateX| deg| deg的范围-180~180,在X轴旋转一个deg角度| -|
307
+ |rotateY| deg| deg的范围-180~180,在Y轴旋转一个deg角度| -|
308
+ |rotateZ deg| deg的范围-180~180,在Z轴旋转一个deg角度| nvue不支持|
309
+ |rotate3d| x,y,z,deg| 同 transform-function rotate3d| nvue不支持|
310
+
311
+ ```js
312
+ const ani = ref(null);
313
+
314
+ ani.value?.step({
315
+ rotateX: 45,
316
+ rotateY: 45
317
+ })
318
+ ```
319
+
320
+ #### **缩放:**
321
+
322
+ |属性名|值|说明|平台差异|
323
+ |:-|:-|:-|:-|
324
+ |scale| sx,[sy]| 一个参数时,表示在X轴、Y轴同时缩放sx倍数;两个参数时表示在X轴缩放sx倍数,在Y轴缩放sy倍数| -|
325
+ |scaleX| sx| 在X轴缩放sx倍数| -|
326
+ |scaleY| sy| 在Y轴缩放sy倍数| -|
327
+ |scaleZ| sz| 在Z轴缩放sy倍数 |nvue不支持|
328
+ |scale3d| sx,sy,sz| 在X轴缩放sx倍数,在Y轴缩放sy倍数,在Z轴缩放sz倍数| nvue不支持|
329
+
330
+ ```js
331
+ const ani = ref(null);
332
+
333
+ ani.value?.step({
334
+ scale: [1.2,0.8]
335
+ })
336
+ ```
337
+
338
+ #### **偏移:**
339
+
340
+ |属性名|值|说明|平台差异|
341
+ |:-|:-|:-|:-|
342
+ |translate| tx,[ty]| 一个参数时,表示在X轴偏移tx,单位px;两个参数时,表示在X轴偏移tx,在Y轴偏移ty,单位px。 |-|
343
+ |translateX| tx| 在X轴偏移tx,单位px| -|
344
+ |translateY| ty| 在Y轴偏移tx,单位px| -|
345
+ |translateZ| tz| 在Z轴偏移tx,单位px| nvue不支持|
346
+ |translate3d| tx,ty,tz| 在X轴偏移tx,在Y轴偏移ty,在Z轴偏移tz,单位px| nvue不支持|
347
+
348
+ ```js
349
+ const ani = ref(null);
350
+
351
+ ani.value?.step({
352
+ translateX: '100px'
353
+ })
354
+ ```
355
+ <style scoped>
356
+ h3[id=transition-events] + table thead tr th:nth-child(2){
357
+ width: 40%;
358
+ }
359
+ h3[id=mode-options] + table {
360
+ width: auto;
361
+ }
362
+ h3[id=mode-options] + p + p + table thead tr th:nth-child(2){
363
+ width: 60%;
364
+ }
365
+ h3[id=动画配置] + p + table thead tr th:nth-child(2){
366
+ width: 20%;
367
+ }
368
+ h3[id=动画配置] + p + table thead tr th:nth-child(4){
369
+ width: 25%;
370
+ }
371
+ h3[id=timingfunction属性说明] + table thead tr th:nth-child(2){
372
+ width: 50%;
373
+ }
374
+ h4[id=样式] + table thead tr th:nth-child(2){
375
+ width: 15%;
376
+ }
377
+ h4[id=样式] + table thead tr th:nth-child(3){
378
+ width: 50%;
379
+ }
380
+ h4[id=旋转] + p + table thead tr th:nth-child(2){
381
+ width: 15%;
382
+ }
383
+ h4[id=旋转] + p + table thead tr th:nth-child(3){
384
+ width: 50%;
385
+ }
386
+ h4[id=旋转] + p + table thead tr th:nth-child(2){
387
+ width: 15%;
388
+ }
389
+ h4[id=旋转] + p + table thead tr th:nth-child(3){
390
+ width: 50%;
391
+ }
392
+ h4[id=缩放] + table thead tr th:nth-child(2){
393
+ width: 15%;
394
+ }
395
+ h4[id=缩放] + table thead tr th:nth-child(3){
396
+ width: 50%;
397
+ }
398
+ h4[id=偏移] + table thead tr th:nth-child(2){
399
+ width: 15%;
400
+ }
401
+ h4[id=偏移] + table thead tr th:nth-child(3){
402
+ width: 50%;
403
+ }
404
+ </style>
@@ -0,0 +1,253 @@
1
+ ## Upload 上传 <to-api/>
2
+
3
+ <demo-model url="/pages/componentsB/upload/upload"></demo-model>
4
+
5
+ ::: tip ✈
6
+
7
+ **组件名:uv-upload**
8
+
9
+ [点击下载&安装](https://ext.dcloud.net.cn/plugin?name=uv-upload)
10
+
11
+ :::
12
+
13
+ 该组件用于上传图片、视频等文件场景。
14
+
15
+ 一般用于表单处的情况较多,可以配合表单使用,具体案例参考:[实战案例-配合uv-upload上传进行验证-4](https://www.uvui.cn/components/form.html#实战案例-配合uv-upload上传进行验证-4)
16
+
17
+ ### 平台兼容性
18
+
19
+ |App(vue)|App(nvue)|H5|小程序|VUE2|VUE3|
20
+ |:-:|:-:|:-:|:-:|:-:|:-:|
21
+ |√|√|√|√|√|√|
22
+
23
+ ### 基础用法
24
+
25
+ 可以通过设置`fileList`参数(数组,元素为对象),显示预置的图片。其中元素的`url`属性为图片路径
26
+
27
+ ```vue
28
+ <template>
29
+ <uv-upload
30
+ :fileList="fileList1"
31
+ name="1"
32
+ multiple
33
+ :maxCount="10"
34
+ @afterRead="afterRead"
35
+ @delete="deletePic"
36
+ ></uv-upload>
37
+ </template>
38
+ <script setup>
39
+ import { ref } from 'vue';
40
+
41
+ const fileList1 = ref([]);
42
+ function deletePic(event) {
43
+ this[`fileList${event.name}`].splice(event.index, 1);
44
+ }
45
+ async function afterRead(event) {
46
+ // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
47
+ let lists = [].concat(event.file);
48
+ let fileListLen = this[`fileList${event.name}`].length;
49
+ lists.map(item => {
50
+ this[`fileList${event.name}`].push({
51
+ ...item,
52
+ status: 'uploading',
53
+ message: '上传中'
54
+ });
55
+ });
56
+ for (let i = 0; i < lists.length; i++) {
57
+ const result = await uploadFilePromise(lists[i].url);
58
+ let item = this[`fileList${event.name}`][fileListLen];
59
+ this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
60
+ status: 'success',
61
+ message: '',
62
+ url: result
63
+ }));
64
+ fileListLen++;
65
+ }
66
+ }
67
+ function uploadFilePromise(url) {
68
+ return new Promise((resolve, reject) => {
69
+ let a = uni.uploadFile({
70
+ url: 'http://192.168.2.21:7001/upload',
71
+ // 仅为示例,非真实的接口地址
72
+ filePath: url,
73
+ name: 'file',
74
+ formData: {
75
+ user: 'test'
76
+ },
77
+ success: res => {
78
+ setTimeout(() => {
79
+ resolve(res.data.data);
80
+ }, 1000);
81
+ }
82
+ });
83
+ });
84
+ }
85
+
86
+ </script>
87
+ ```
88
+
89
+ ### 上传视频
90
+
91
+ 通过设置`accept='video'`属性,将上传改为视频上传。
92
+
93
+ ```vue
94
+ <template>
95
+ <uv-upload :fileList="[]" name="2" multiple :maxCount="10" accept="video"></uv-upload>
96
+ </template>
97
+ ```
98
+
99
+ ### 文件预览
100
+
101
+ 通过设置`:previewFullImage="true"'`属性,达到文件预览的目的。
102
+
103
+ ```vue
104
+ <template>
105
+ <uv-upload :fileList="fileList" name="3" multiple :maxCount="10" :previewFullImage="true"></uv-upload>
106
+ </template>
107
+ <script setup>
108
+ import { ref } from 'vue';
109
+
110
+ const fileList = ref([{
111
+ url: 'https://cdn.uviewui.com/uview/swiper/1.jpg'
112
+ }]);
113
+
114
+ </script>
115
+ ```
116
+
117
+ ### 隐藏上传按钮 / 限制上传数量
118
+
119
+ 上传数量等于`maxCount`所规定的数据时,隐藏上传按钮。
120
+
121
+ ```vue
122
+ <template>
123
+ <uv-upload :fileList="fileList" name="3" :maxCount="1" multiple :previewFullImage="true"></uv-upload>
124
+ </template>
125
+ <script setup>
126
+ import { ref } from 'vue';
127
+
128
+ const fileList = ref([{
129
+ url: 'https://cdn.uviewui.com/uview/swiper/1.jpg'
130
+ }, {
131
+ url: 'https://cdn.uviewui.com/uview/swiper/2.jpg'
132
+ }]);
133
+
134
+ </script>
135
+ ```
136
+
137
+ ### 自定义上传样式
138
+
139
+ 添加`image`以自定义上传样式,达到身份证,银行卡等不同场景需求。
140
+
141
+ ```vue
142
+ <template>
143
+ <uv-upload
144
+ :fileList="[]"
145
+ name="6"
146
+ multiple
147
+ :maxCount="1"
148
+ width="250"
149
+ height="150">
150
+ <image
151
+ src="https://cdn.uviewui.com/uview/demo/upload/positive.png"
152
+ mode="widthFix"
153
+ style="width: 250px;height: 150px;"
154
+ ></image>
155
+ </uv-upload>
156
+ </template>
157
+ ```
158
+
159
+ ### 完整示例
160
+
161
+ ::: tip 完整示例下载地址
162
+
163
+ [https://ext.dcloud.net.cn/plugin?name=uv-ui](https://ext.dcloud.net.cn/plugin?name=uv-ui)
164
+
165
+ :::
166
+
167
+ ### API
168
+ ---
169
+
170
+ ### Upload Props
171
+
172
+ | 参数 | 说明 | 类型 | 默认值 | 可选值 |
173
+ |:- |:- |:- |:- |:- |
174
+ | fileList | 显示已上传的文件列表,列表中具体参数参考[FileList Options](/components/upload.html#filelist-options) | Array | - | - |
175
+ | accept | 接受的文件类型,`file`只支持`H5`(只有微信小程序才支持把accept配置为all、media) | String | image | all &#124; media &#124; image &#124; file &#124; video|
176
+ | capture | 图片或视频拾取模式,当accept为image类型时设置capture可选额外camera可以直接调起摄像头 | String &#124; Array | ['album', 'camera'] | - |
177
+ | compressed | 当accept为video时生效,是否压缩视频,默认为true | Boolean | true | true &#124; false |
178
+ | camera | 当accept为video时生效,可选值为back或front | String | back | - |
179
+ | maxDuration | 当accept为video时生效,拍摄视频最长拍摄时间,单位秒 | Number | 60 | true &#124; false |
180
+ | uploadIcon | 上传区域的图标,只能内置图标 | String | camera-fill | - |
181
+ | uploadIconColor | 上传区域的图标的颜色 | String | #D3D4D6 | - |
182
+ | useBeforeRead | 是否开启读取前的处理函数功能,使用@beforeRead必须设置为true | Boolean | false | true &#124; false |
183
+ | previewFullImage | 是否开启图片预览功能 | Boolean | true | true &#124; false |
184
+ | previewFullVideo | 是否开启视频预览功能 | Boolean | true | true &#124; false |
185
+ | maxCount | 最大选择图片的数量 | String &#124; Number | 52 | - |
186
+ | disabled | 是否启用(显示/隐藏)组件 | Boolean | false | true &#124; false |
187
+ | imageMode | 预览上传的图片时的裁剪模式,和image组件mode属性一致 | String | aspectFill | - |
188
+ | name | 标识符,可以在回调函数的第二项参数中获取 | String | file | - |
189
+ | sizeType | original 原图,compressed 压缩图,默认二者都有,H5无效 | Array\<String\> | ['original', 'compressed']| - |
190
+ | multiple | 是否开启图片多选,部分安卓机型不支持 | Boolean | false | true &#124; false |
191
+ | deletable | 是否显示删除按钮 | Boolean | true | true &#124; false |
192
+ | maxSize | 选择单个文件的最大大小,单位B(byte),默认不限制 | String &#124; Number | Number.MAX_VALUE | - |
193
+ | uploadText | 上传区域的提示文字 | String | - | - |
194
+ | width | 内部预览图片区域和选择图片按钮的区域宽度,单位rpx,不能是百分比,或者`auto` | String &#124; Number | 80 | - |
195
+ | height | 内部预览图片区域和选择图片按钮的区域高度,单位rpx,不能是百分比,或者`auto` | String &#124; Number | 80 | - |
196
+ | previewImage | 是否在上传完成后展示预览图 | Boolean | true | true &#124; false |
197
+ | customStyle | 自定义外部样式 | Object | - | - |
198
+
199
+ ### FileList Options
200
+
201
+ |属性名|说明|
202
+ |:-|:-|
203
+ | status | 上传状态,uploading - 上传中 &nbsp; success - 上传成功 &nbsp; failed - 上传失败 |
204
+ | message | 提示文本 |
205
+ | url | 图片地址 |
206
+
207
+
208
+ ### Upload Methods
209
+
210
+ 此方法如要通过ref手动调用
211
+
212
+ | 名称 | 说明 |
213
+ |------------- |---------------- |
214
+ | beforeRead | 读取前的处理函数|
215
+ | afterRead | 读取后的处理函数 |
216
+
217
+ ### Upload Events
218
+
219
+ 回调参数中的`event`参数,为当前删除元素的所有信息,`index`为当前操作的图片的索引,`name`为删除名称,`file`包含删除的url信息
220
+
221
+ |事件名|说明|回调参数|
222
+ |:-|:-|:-|:-|
223
+ | @beforeRead | 读取前的处理函数,使用之前必须设置 `useBeforeRead` 为 `true` | (file, lists, name),错误信息 |
224
+ | @afterRead | 读取后的处理函数 | (file, lists, name),错误信息 |
225
+ | @oversize | 图片大小超出最大允许大小 | (file, lists, name), name为通过`props`传递的`index`参数 |
226
+ | @clickPreview | 全屏预览图片时触发 | e={deletable,index,isImage,isVideo,name,url} 是否展示删除按钮,索引,是否是图片,是否是视频,通过 props 传递的name,文件地址|
227
+ | @delete | 删除图片 | e={file,index,name},文件,索引,通过 props 传递的name |
228
+
229
+ ### Upload Slots
230
+
231
+ slot中您可以内置任何您所需要的样式。
232
+
233
+ |名称|说明|
234
+ |:-|:-|
235
+ | -(default) | 自定义上传样式 |
236
+
237
+ <style scoped>
238
+ h3[id=upload-slots] + p + table thead tr th:nth-child(2){
239
+ width: 70%;
240
+ }
241
+ h3[id=upload-methods] + p + table thead tr th:nth-child(2){
242
+ width: 70%;
243
+ }
244
+ h3[id=upload-events] + p + table thead tr th:nth-child(2){
245
+ width: 40%;
246
+ }
247
+ h3[id=upload-events] + p + table thead tr th:nth-child(3){
248
+ width: 40%;
249
+ }
250
+ h3[id=filelist-options] + table thead tr th:nth-child(2){
251
+ width: 70%;
252
+ }
253
+ </style>