uview-pro 0.0.18 → 0.0.19

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 (232) hide show
  1. package/changelog.md +269 -249
  2. package/components/u-action-sheet/types.ts +35 -35
  3. package/components/u-action-sheet/u-action-sheet.vue +160 -160
  4. package/components/u-alert-tips/types.ts +39 -39
  5. package/components/u-alert-tips/u-alert-tips.vue +212 -212
  6. package/components/u-avatar/types.ts +34 -34
  7. package/components/u-avatar/u-avatar.vue +193 -193
  8. package/components/u-avatar-cropper/types.ts +23 -23
  9. package/components/u-avatar-cropper/u-avatar-cropper.vue +286 -286
  10. package/components/u-avatar-cropper/weCropper.d.ts +62 -62
  11. package/components/u-avatar-cropper/weCropper.js +1253 -1253
  12. package/components/u-avatar-cropper/weCropper.ts +1255 -1255
  13. package/components/u-back-top/types.ts +39 -39
  14. package/components/u-back-top/u-back-top.vue +125 -125
  15. package/components/u-badge/types.ts +36 -36
  16. package/components/u-badge/u-badge.vue +165 -165
  17. package/components/u-button/types.ts +66 -66
  18. package/components/u-button/u-button.vue +554 -554
  19. package/components/u-calendar/types.ts +63 -63
  20. package/components/u-calendar/u-calendar.vue +592 -592
  21. package/components/u-car-keyboard/types.ts +12 -12
  22. package/components/u-car-keyboard/u-car-keyboard.vue +234 -234
  23. package/components/u-card/types.ts +59 -59
  24. package/components/u-card/u-card.vue +194 -194
  25. package/components/u-cell-group/types.ts +17 -17
  26. package/components/u-cell-group/u-cell-group.vue +50 -50
  27. package/components/u-cell-item/types.ts +54 -54
  28. package/components/u-cell-item/u-cell-item.vue +202 -202
  29. package/components/u-checkbox/types.ts +31 -31
  30. package/components/u-checkbox/u-checkbox.vue +267 -267
  31. package/components/u-checkbox-group/types.ts +32 -32
  32. package/components/u-checkbox-group/u-checkbox-group.vue +79 -79
  33. package/components/u-circle-progress/types.ts +52 -52
  34. package/components/u-circle-progress/u-circle-progress.vue +189 -189
  35. package/components/u-city-select/types.ts +20 -20
  36. package/components/u-city-select/u-city-select.vue +236 -236
  37. package/components/u-col/types.ts +30 -30
  38. package/components/u-col/u-col.vue +123 -123
  39. package/components/u-collapse/types.ts +31 -31
  40. package/components/u-collapse/u-collapse.vue +68 -68
  41. package/components/u-collapse-item/types.ts +25 -25
  42. package/components/u-collapse-item/u-collapse-item.vue +176 -176
  43. package/components/u-column-notice/types.ts +48 -48
  44. package/components/u-column-notice/u-column-notice.vue +176 -176
  45. package/components/u-count-down/types.ts +42 -42
  46. package/components/u-count-down/u-count-down.vue +258 -258
  47. package/components/u-count-to/types.ts +32 -32
  48. package/components/u-count-to/u-count-to.vue +241 -241
  49. package/components/u-divider/types.ts +31 -31
  50. package/components/u-divider/u-divider.vue +121 -121
  51. package/components/u-dropdown/types.ts +32 -32
  52. package/components/u-dropdown/u-dropdown.vue +289 -289
  53. package/components/u-dropdown-item/types.ts +27 -27
  54. package/components/u-dropdown-item/u-dropdown-item.vue +123 -123
  55. package/components/u-empty/types.ts +36 -36
  56. package/components/u-empty/u-empty.vue +88 -88
  57. package/components/u-field/types.ts +69 -69
  58. package/components/u-field/u-field.vue +354 -354
  59. package/components/u-full-screen/types.ts +14 -14
  60. package/components/u-full-screen/u-full-screen.vue +82 -82
  61. package/components/u-gap/types.ts +18 -18
  62. package/components/u-gap/u-gap.vue +40 -40
  63. package/components/u-grid/types.ts +19 -19
  64. package/components/u-grid/u-grid.vue +93 -93
  65. package/components/u-grid-item/types.ts +16 -16
  66. package/components/u-grid-item/u-grid-item.vue +130 -130
  67. package/components/u-icon/types.ts +62 -62
  68. package/components/u-icon/u-icon.vue +274 -274
  69. package/components/u-image/types.ts +51 -51
  70. package/components/u-image/u-image.vue +222 -222
  71. package/components/u-index-anchor/types.ts +16 -16
  72. package/components/u-index-anchor/u-index-anchor.vue +86 -86
  73. package/components/u-index-list/types.ts +43 -43
  74. package/components/u-index-list/u-index-list.vue +355 -355
  75. package/components/u-input/types.ts +140 -140
  76. package/components/u-input/u-input.vue +255 -255
  77. package/components/u-keyboard/types.ts +40 -40
  78. package/components/u-keyboard/u-keyboard.vue +158 -158
  79. package/components/u-lazy-load/types.ts +37 -37
  80. package/components/u-lazy-load/u-lazy-load.vue +233 -233
  81. package/components/u-line/types.ts +44 -44
  82. package/components/u-line/u-line.vue +59 -59
  83. package/components/u-line-progress/types.ts +58 -58
  84. package/components/u-line-progress/u-line-progress.vue +109 -109
  85. package/components/u-link/types.ts +43 -43
  86. package/components/u-link/u-link.vue +75 -75
  87. package/components/u-loading/types.ts +35 -35
  88. package/components/u-loading/u-loading.vue +90 -90
  89. package/components/u-loading-popup/types.ts +26 -26
  90. package/components/u-loading-popup/u-loading-popup.vue +239 -239
  91. package/components/u-loadmore/types.ts +79 -79
  92. package/components/u-loadmore/u-loadmore.vue +140 -140
  93. package/components/u-mask/types.ts +43 -43
  94. package/components/u-mask/u-mask.vue +106 -106
  95. package/components/u-message-input/types.ts +74 -74
  96. package/components/u-message-input/u-message-input.vue +255 -255
  97. package/components/u-modal/types.ts +118 -118
  98. package/components/u-modal/u-modal.vue +200 -200
  99. package/components/u-navbar/types.ts +103 -103
  100. package/components/u-navbar/u-navbar.vue +226 -226
  101. package/components/u-no-network/image.ts +2 -2
  102. package/components/u-no-network/types.ts +28 -28
  103. package/components/u-no-network/u-no-network.vue +290 -290
  104. package/components/u-notice-bar/types.ts +111 -111
  105. package/components/u-notice-bar/u-notice-bar.vue +174 -174
  106. package/components/u-number-box/types.ts +42 -42
  107. package/components/u-number-box/u-number-box.vue +312 -312
  108. package/components/u-number-keyboard/types.ts +26 -26
  109. package/components/u-number-keyboard/u-number-keyboard.vue +166 -166
  110. package/components/u-picker/types.ts +111 -111
  111. package/components/u-picker/u-picker.vue +637 -637
  112. package/components/u-popup/types.ts +59 -59
  113. package/components/u-popup/u-popup.vue +359 -359
  114. package/components/u-radio/types.ts +25 -25
  115. package/components/u-radio/u-radio.vue +258 -258
  116. package/components/u-radio-group/types.ts +29 -29
  117. package/components/u-radio-group/u-radio-group.vue +98 -98
  118. package/components/u-rate/types.ts +40 -40
  119. package/components/u-rate/u-rate.vue +234 -234
  120. package/components/u-read-more/types.ts +35 -35
  121. package/components/u-read-more/u-read-more.vue +150 -150
  122. package/components/u-row/types.ts +20 -20
  123. package/components/u-row/u-row.vue +87 -87
  124. package/components/u-row-notice/types.ts +39 -39
  125. package/components/u-row-notice/u-row-notice.vue +213 -213
  126. package/components/u-search/types.ts +53 -53
  127. package/components/u-search/u-search.vue +256 -256
  128. package/components/u-section/types.ts +32 -32
  129. package/components/u-section/u-section.vue +125 -125
  130. package/components/u-select/types.ts +43 -43
  131. package/components/u-select/u-select.vue +361 -361
  132. package/components/u-skeleton/types.ts +20 -20
  133. package/components/u-skeleton/u-skeleton.vue +205 -205
  134. package/components/u-slider/types.ts +32 -32
  135. package/components/u-slider/u-slider.vue +238 -238
  136. package/components/u-steps/types.ts +28 -28
  137. package/components/u-steps/u-steps.vue +160 -160
  138. package/components/u-sticky/types.ts +22 -22
  139. package/components/u-sticky/u-sticky.vue +159 -159
  140. package/components/u-subsection/types.ts +36 -36
  141. package/components/u-subsection/u-subsection.vue +328 -328
  142. package/components/u-swipe-action/types.ts +50 -50
  143. package/components/u-swipe-action/u-swipe-action.vue +253 -253
  144. package/components/u-swiper/types.ts +47 -47
  145. package/components/u-swiper/u-swiper.vue +266 -266
  146. package/components/u-switch/types.ts +28 -28
  147. package/components/u-switch/u-switch.vue +128 -128
  148. package/components/u-tabbar/types.ts +36 -36
  149. package/components/u-tabbar/u-tabbar.vue +280 -280
  150. package/components/u-table/types.ts +25 -25
  151. package/components/u-table/u-table.vue +55 -55
  152. package/components/u-tabs/types.ts +51 -51
  153. package/components/u-tabs/u-tabs.vue +284 -284
  154. package/components/u-tabs-swiper/types.ts +53 -53
  155. package/components/u-tabs-swiper/u-tabs-swiper.vue +379 -379
  156. package/components/u-tag/types.ts +37 -37
  157. package/components/u-tag/u-tag.vue +244 -244
  158. package/components/u-td/types.ts +12 -12
  159. package/components/u-td/u-td.vue +69 -69
  160. package/components/u-th/types.ts +12 -12
  161. package/components/u-th/u-th.vue +63 -63
  162. package/components/u-time-line/u-time-line.vue +39 -39
  163. package/components/u-time-line-item/types.ts +14 -14
  164. package/components/u-time-line-item/u-time-line-item.vue +78 -78
  165. package/components/u-toast/types.ts +36 -36
  166. package/components/u-toast/u-toast.vue +233 -233
  167. package/components/u-top-tips/types.ts +14 -14
  168. package/components/u-top-tips/u-top-tips.vue +113 -113
  169. package/components/u-tr/types.ts +8 -8
  170. package/components/u-tr/u-tr.vue +24 -24
  171. package/components/u-upload/types.ts +71 -71
  172. package/components/u-upload/u-upload.vue +545 -545
  173. package/components/u-verification-code/types.ts +22 -22
  174. package/components/u-verification-code/u-verification-code.vue +164 -164
  175. package/components/u-waterfall/types.ts +16 -16
  176. package/components/u-waterfall/u-waterfall.vue +175 -175
  177. package/iconfont.css +910 -910
  178. package/index.scss +22 -22
  179. package/index.ts +195 -202
  180. package/libs/config/config.ts +26 -26
  181. package/libs/config/zIndex.ts +37 -37
  182. package/libs/css/color.scss +155 -155
  183. package/libs/css/common.scss +175 -175
  184. package/libs/css/style.components.scss +6 -6
  185. package/libs/css/style.h5.scss +8 -8
  186. package/libs/css/style.mp.scss +72 -72
  187. package/libs/css/style.nvue.scss +2 -2
  188. package/libs/css/style.vue.scss +175 -175
  189. package/libs/function/$parent.ts +22 -22
  190. package/libs/function/addUnit.ts +13 -13
  191. package/libs/function/color.ts +36 -36
  192. package/libs/function/colorGradient.ts +125 -125
  193. package/libs/function/debounce.ts +28 -28
  194. package/libs/function/deepClone.ts +39 -39
  195. package/libs/function/deepMerge.ts +34 -34
  196. package/libs/function/getParent.ts +58 -58
  197. package/libs/function/getRect.ts +26 -26
  198. package/libs/function/guid.ts +42 -42
  199. package/libs/function/md5.ts +398 -398
  200. package/libs/function/parent.ts +21 -21
  201. package/libs/function/queryParams.ts +60 -60
  202. package/libs/function/random.ts +16 -16
  203. package/libs/function/randomArray.ts +11 -11
  204. package/libs/function/route.ts +118 -118
  205. package/libs/function/sys.ts +15 -15
  206. package/libs/function/test.ts +229 -229
  207. package/libs/function/throttle.ts +31 -31
  208. package/libs/function/timeFormat.ts +54 -54
  209. package/libs/function/timeFrom.ts +48 -48
  210. package/libs/function/toast.ts +14 -14
  211. package/libs/function/trim.ts +21 -21
  212. package/libs/function/type2icon.ts +36 -36
  213. package/libs/hooks/useEmitter.ts +77 -77
  214. package/libs/hooks/useParent.ts +29 -29
  215. package/libs/request/auto-http.ts +76 -76
  216. package/libs/request/index.ts +223 -237
  217. package/libs/store/index.ts +88 -88
  218. package/libs/util/async-validator.d.ts +62 -62
  219. package/libs/util/async-validator.js +1356 -1356
  220. package/libs/util/emitter.ts +112 -112
  221. package/libs/util/mitt.ts +118 -118
  222. package/libs/util/parent.ts +20 -20
  223. package/package.json +1 -1
  224. package/readme.md +231 -231
  225. package/theme.scss +38 -38
  226. package/types/components.d.ts +95 -95
  227. package/types/global.d.ts +221 -221
  228. package/types/ignore-errors.d.ts +30 -30
  229. package/types/index.d.ts +90 -90
  230. package/types/uni-app.d.ts +63 -63
  231. package/libs/request/uni-http.md +0 -156
  232. package/libs/request/uni-http.ts +0 -434
@@ -1,47 +1,47 @@
1
- import type { ExtractPropTypes, PropType } from 'vue';
2
- import type { ImgMode, SwiperIndicatorPosition, SwiperMode } from '../../types/global';
3
-
4
- /**
5
- * SwiperProps 轮播图 props 类型定义
6
- * @description 轮播图,支持多种指示器、3D、自动播放等
7
- */
8
- export const SwiperProps = {
9
- /** 轮播数据列表,数组对象 */
10
- list: { type: Array as PropType<Array<Record<string, any>>>, default: () => [] },
11
- /** 是否显示标题 */
12
- title: { type: Boolean, default: false },
13
- /** 指示器配置对象 */
14
- indicator: { type: Object as PropType<Record<string, any>>, default: () => ({}) },
15
- /** 圆角,单位rpx */
16
- borderRadius: { type: [Number, String] as PropType<number | string>, default: 8 },
17
- /** 自动切换时间间隔,单位ms */
18
- interval: { type: [String, Number] as PropType<number | string>, default: 3000 },
19
- /** 指示器类型,round/dot/line等 */
20
- mode: { type: String as PropType<SwiperMode>, default: 'round' },
21
- /** 轮播高度,单位rpx */
22
- height: { type: [Number, String] as PropType<number | string>, default: 250 },
23
- /** 指示器位置 */
24
- indicatorPos: { type: String as PropType<SwiperIndicatorPosition>, default: 'bottomCenter' },
25
- /** 是否开启3D效果 */
26
- effect3d: { type: Boolean, default: false },
27
- /** 3D模式下前一项的边距,单位rpx */
28
- effect3dPreviousMargin: { type: [Number, String] as PropType<number | string>, default: 50 },
29
- /** 是否自动播放 */
30
- autoplay: { type: Boolean, default: true },
31
- /** 切换动画时长,单位ms */
32
- duration: { type: [Number, String] as PropType<number | string>, default: 500 },
33
- /** 是否循环播放 */
34
- circular: { type: Boolean, default: true },
35
- /** 图片裁剪模式 */
36
- imgMode: { type: String as PropType<ImgMode>, default: 'aspectFill' },
37
- /** 轮播项对象的图片字段名 */
38
- name: { type: String, default: 'image' },
39
- /** 轮播背景色 */
40
- bgColor: { type: String, default: '#f3f4f6' },
41
- /** 当前激活项索引 */
42
- current: { type: [Number, String] as PropType<number | string>, default: 0 },
43
- /** 标题样式对象 */
44
- titleStyle: { type: Object as PropType<Record<string, any>>, default: () => ({}) }
45
- };
46
-
47
- export type SwiperProps = ExtractPropTypes<typeof SwiperProps>;
1
+ import type { ExtractPropTypes, PropType } from 'vue';
2
+ import type { ImgMode, SwiperIndicatorPosition, SwiperMode } from '../../types/global';
3
+
4
+ /**
5
+ * SwiperProps 轮播图 props 类型定义
6
+ * @description 轮播图,支持多种指示器、3D、自动播放等
7
+ */
8
+ export const SwiperProps = {
9
+ /** 轮播数据列表,数组对象 */
10
+ list: { type: Array as PropType<Array<Record<string, any>>>, default: () => [] },
11
+ /** 是否显示标题 */
12
+ title: { type: Boolean, default: false },
13
+ /** 指示器配置对象 */
14
+ indicator: { type: Object as PropType<Record<string, any>>, default: () => ({}) },
15
+ /** 圆角,单位rpx */
16
+ borderRadius: { type: [Number, String] as PropType<number | string>, default: 8 },
17
+ /** 自动切换时间间隔,单位ms */
18
+ interval: { type: [String, Number] as PropType<number | string>, default: 3000 },
19
+ /** 指示器类型,round/dot/line等 */
20
+ mode: { type: String as PropType<SwiperMode>, default: 'round' },
21
+ /** 轮播高度,单位rpx */
22
+ height: { type: [Number, String] as PropType<number | string>, default: 250 },
23
+ /** 指示器位置 */
24
+ indicatorPos: { type: String as PropType<SwiperIndicatorPosition>, default: 'bottomCenter' },
25
+ /** 是否开启3D效果 */
26
+ effect3d: { type: Boolean, default: false },
27
+ /** 3D模式下前一项的边距,单位rpx */
28
+ effect3dPreviousMargin: { type: [Number, String] as PropType<number | string>, default: 50 },
29
+ /** 是否自动播放 */
30
+ autoplay: { type: Boolean, default: true },
31
+ /** 切换动画时长,单位ms */
32
+ duration: { type: [Number, String] as PropType<number | string>, default: 500 },
33
+ /** 是否循环播放 */
34
+ circular: { type: Boolean, default: true },
35
+ /** 图片裁剪模式 */
36
+ imgMode: { type: String as PropType<ImgMode>, default: 'aspectFill' },
37
+ /** 轮播项对象的图片字段名 */
38
+ name: { type: String, default: 'image' },
39
+ /** 轮播背景色 */
40
+ bgColor: { type: String, default: '#f3f4f6' },
41
+ /** 当前激活项索引 */
42
+ current: { type: [Number, String] as PropType<number | string>, default: 0 },
43
+ /** 标题样式对象 */
44
+ titleStyle: { type: Object as PropType<Record<string, any>>, default: () => ({}) }
45
+ };
46
+
47
+ export type SwiperProps = ExtractPropTypes<typeof SwiperProps>;
@@ -1,266 +1,266 @@
1
- <template>
2
- <view class="u-swiper-wrap" :style="{ borderRadius: `${borderRadius}rpx` }">
3
- <swiper
4
- :current="elCurrent"
5
- @change="change"
6
- @animationfinish="animationfinish"
7
- :interval="interval"
8
- :circular="circular"
9
- :duration="duration"
10
- :autoplay="autoplay"
11
- :previous-margin="effect3d ? effect3dPreviousMargin + 'rpx' : '0'"
12
- :next-margin="effect3d ? effect3dPreviousMargin + 'rpx' : '0'"
13
- :style="{ height: height + 'rpx', backgroundColor: bgColor }"
14
- >
15
- <swiper-item class="u-swiper-item" v-for="(item, index) in list" :key="index">
16
- <view
17
- class="u-list-image-wrap"
18
- @tap.stop.prevent="listClick(index)"
19
- :class="[uCurrent != index ? 'u-list-scale' : '']"
20
- :style="{
21
- borderRadius: `${borderRadius}rpx`,
22
- transform: effect3d && uCurrent != index ? 'scaleY(0.9)' : 'scaleY(1)',
23
- margin: effect3d && uCurrent != index ? '0 20rpx' : 0
24
- }"
25
- >
26
- <image class="u-swiper-image" :src="item[name] || item" :mode="imgMode"></image>
27
- <view v-if="title && item.title" class="u-swiper-title u-line-1" :style="[{ 'padding-bottom': titlePaddingBottom }, titleStyle]">
28
- {{ item.title }}
29
- </view>
30
- </view>
31
- </swiper-item>
32
- </swiper>
33
- <view
34
- class="u-swiper-indicator"
35
- :style="{
36
- top: indicatorPos == 'topLeft' || indicatorPos == 'topCenter' || indicatorPos == 'topRight' ? '12rpx' : 'auto',
37
- bottom: indicatorPos == 'bottomLeft' || indicatorPos == 'bottomCenter' || indicatorPos == 'bottomRight' ? '12rpx' : 'auto',
38
- justifyContent: justifyContent,
39
- padding: `0 ${effect3d ? '74rpx' : '24rpx'}`
40
- }"
41
- >
42
- <block v-if="mode == 'rect'">
43
- <view class="u-indicator-item-rect" :class="{ 'u-indicator-item-rect-active': index == uCurrent }" v-for="(item, index) in list" :key="index"></view>
44
- </block>
45
- <block v-if="mode == 'dot'">
46
- <view class="u-indicator-item-dot" :class="{ 'u-indicator-item-dot-active': index == uCurrent }" v-for="(item, index) in list" :key="index"></view>
47
- </block>
48
- <block v-if="mode == 'round'">
49
- <view class="u-indicator-item-round" :class="{ 'u-indicator-item-round-active': index == uCurrent }" v-for="(item, index) in list" :key="index"></view>
50
- </block>
51
- <block v-if="mode == 'number'">
52
- <view class="u-indicator-item-number">{{ uCurrent + 1 }}/{{ list.length }}</view>
53
- </block>
54
- </view>
55
- </view>
56
- </template>
57
-
58
- <script setup lang="ts">
59
- import { ref, computed, watch } from 'vue';
60
- import { SwiperProps } from './types';
61
-
62
- defineOptions({ name: 'u-swiper' });
63
- /**
64
- * swiper 轮播图
65
- * @description 该组件一般用于导航轮播,广告展示等场景,可开箱即用
66
- * @tutorial https://uview-pro.netlify.app/components/swiper.html
67
- * @property {Array} list 轮播图数据,见官网"基本使用"说明
68
- * @property {Boolean} title 是否显示标题文字,需要配合list参数,见官网说明(默认false)
69
- * @property {String} mode 指示器模式,见官网说明(默认round)
70
- * @property {String|Number} height 轮播图组件高度,单位rpx(默认250)
71
- * @property {String} indicator-pos 指示器的位置(默认bottomCenter)
72
- * @property {Boolean} effect3d 是否开启3D效果(默认false)
73
- * @property {Boolean} autoplay 是否自动播放(默认true)
74
- * @property {String|Number} interval 自动轮播时间间隔,单位ms(默认2500)
75
- * @property {Boolean} circular 是否衔接播放,见官网说明(默认true)
76
- * @property {String} bg-color 背景颜色(默认#f3f4f6)
77
- * @property {String|Number} border-radius 轮播图圆角值,单位rpx(默认8)
78
- * @property {Object} title-style 自定义标题样式
79
- * @property {String|Number} effect3d-previous-margin mode = true模式的情况下,激活项与前后项之间的距离,单位rpx(默认50)
80
- * @property {String} img-mode 图片的裁剪模式,详见image组件裁剪模式(默认aspectFill)
81
- * @event {Function} click 点击轮播图时触发
82
- * @example <u-swiper :list="list" mode="dot" indicator-pos="bottomRight"></u-swiper>
83
- */
84
-
85
- const props = defineProps(SwiperProps);
86
- const emit = defineEmits(['click', 'change']);
87
-
88
- // 当前活跃的swiper-item的index
89
- const uCurrent = ref(Number(props.current));
90
-
91
- // 监听list变化,重置uCurrent值,避免溢出
92
- watch(
93
- () => props.list,
94
- (nVal, oVal) => {
95
- if (nVal.length !== oVal.length) uCurrent.value = 0;
96
- }
97
- );
98
- // 监听外部current的变化,实时修改内部依赖于此测uCurrent值
99
- watch(
100
- () => props.current,
101
- n => {
102
- uCurrent.value = Number(n);
103
- }
104
- );
105
-
106
- // 容器 justifyContent
107
- const justifyContent = computed(() => {
108
- if (props.indicatorPos == 'topLeft' || props.indicatorPos == 'bottomLeft') return 'flex-start';
109
- if (props.indicatorPos == 'topCenter' || props.indicatorPos == 'bottomCenter') return 'center';
110
- if (props.indicatorPos == 'topRight' || props.indicatorPos == 'bottomRight') return 'flex-end';
111
- return 'center';
112
- });
113
-
114
- // 标题下边距
115
- const titlePaddingBottom = computed(() => {
116
- if (props.mode == 'none') return '12rpx';
117
- if (['bottomLeft', 'bottomCenter', 'bottomRight'].includes(props.indicatorPos) && props.mode == 'number') {
118
- return '60rpx';
119
- } else if (['bottomLeft', 'bottomCenter', 'bottomRight'].includes(props.indicatorPos) && props.mode != 'number') {
120
- return '40rpx';
121
- } else {
122
- return '12rpx';
123
- }
124
- });
125
-
126
- // swiper组件current参数只接受Number类型
127
- const elCurrent = computed(() => Number(props.current));
128
-
129
- /**
130
- * 点击轮播图项
131
- */
132
- function listClick(index: number) {
133
- emit('click', index);
134
- }
135
-
136
- /**
137
- * swiper change事件
138
- */
139
- function change(e: any) {
140
- const current = e.detail.current;
141
- uCurrent.value = current;
142
- emit('change', current);
143
- }
144
-
145
- /**
146
- * swiper animationfinish事件
147
- * 头条小程序不支持animationfinish事件,改由change事件
148
- * 暂不监听此事件,因为不再给swiper绑定uCurrent属性
149
- */
150
- function animationfinish(e: any) {
151
- // #ifndef MP-TOUTIAO
152
- // uCurrent.value = e.detail.current
153
- // #endif
154
- }
155
-
156
- defineExpose({ listClick, change, animationfinish });
157
- </script>
158
-
159
- <style lang="scss" scoped>
160
- @import '../../libs/css/style.components.scss';
161
-
162
- .u-swiper-wrap {
163
- position: relative;
164
- overflow: hidden;
165
- transform: translateY(0);
166
- }
167
-
168
- .u-swiper-image {
169
- width: 100%;
170
- will-change: transform;
171
- height: 100%;
172
- /* #ifndef APP-NVUE */
173
- display: block;
174
- /* #endif */
175
- /* #ifdef H5 */
176
- pointer-events: none;
177
- /* #endif */
178
- }
179
-
180
- .u-swiper-indicator {
181
- padding: 0 24rpx;
182
- position: absolute;
183
- @include vue-flex;
184
- width: 100%;
185
- z-index: 1;
186
- }
187
-
188
- .u-indicator-item-rect {
189
- width: 26rpx;
190
- height: 8rpx;
191
- margin: 0 6rpx;
192
- transition: all 0.5s;
193
- background-color: rgba(0, 0, 0, 0.3);
194
- }
195
-
196
- .u-indicator-item-rect-active {
197
- background-color: rgba(255, 255, 255, 0.8);
198
- }
199
-
200
- .u-indicator-item-dot {
201
- width: 14rpx;
202
- height: 14rpx;
203
- margin: 0 6rpx;
204
- border-radius: 20rpx;
205
- transition: all 0.5s;
206
- background-color: rgba(0, 0, 0, 0.3);
207
- }
208
-
209
- .u-indicator-item-dot-active {
210
- background-color: rgba(255, 255, 255, 0.8);
211
- }
212
-
213
- .u-indicator-item-round {
214
- width: 14rpx;
215
- height: 14rpx;
216
- margin: 0 6rpx;
217
- border-radius: 20rpx;
218
- transition: all 0.5s;
219
- background-color: rgba(0, 0, 0, 0.3);
220
- }
221
-
222
- .u-indicator-item-round-active {
223
- width: 34rpx;
224
- background-color: rgba(255, 255, 255, 0.8);
225
- }
226
-
227
- .u-indicator-item-number {
228
- padding: 6rpx 16rpx;
229
- line-height: 1;
230
- background-color: rgba(0, 0, 0, 0.3);
231
- border-radius: 100rpx;
232
- font-size: 26rpx;
233
- color: rgba(255, 255, 255, 0.8);
234
- }
235
-
236
- .u-list-scale {
237
- transform-origin: center center;
238
- }
239
-
240
- .u-list-image-wrap {
241
- width: 100%;
242
- height: 100%;
243
- flex: 1;
244
- transition: all 0.5s;
245
- overflow: hidden;
246
- box-sizing: content-box;
247
- position: relative;
248
- }
249
-
250
- .u-swiper-title {
251
- position: absolute;
252
- background-color: rgba(0, 0, 0, 0.3);
253
- bottom: 0;
254
- left: 0;
255
- width: 100%;
256
- font-size: 28rpx;
257
- padding: 12rpx 24rpx;
258
- color: rgba(255, 255, 255, 0.9);
259
- }
260
-
261
- .u-swiper-item {
262
- @include vue-flex;
263
- overflow: hidden;
264
- align-items: center;
265
- }
266
- </style>
1
+ <template>
2
+ <view class="u-swiper-wrap" :style="{ borderRadius: `${borderRadius}rpx` }">
3
+ <swiper
4
+ :current="elCurrent"
5
+ @change="change"
6
+ @animationfinish="animationfinish"
7
+ :interval="interval"
8
+ :circular="circular"
9
+ :duration="duration"
10
+ :autoplay="autoplay"
11
+ :previous-margin="effect3d ? effect3dPreviousMargin + 'rpx' : '0'"
12
+ :next-margin="effect3d ? effect3dPreviousMargin + 'rpx' : '0'"
13
+ :style="{ height: height + 'rpx', backgroundColor: bgColor }"
14
+ >
15
+ <swiper-item class="u-swiper-item" v-for="(item, index) in list" :key="index">
16
+ <view
17
+ class="u-list-image-wrap"
18
+ @tap.stop.prevent="listClick(index)"
19
+ :class="[uCurrent != index ? 'u-list-scale' : '']"
20
+ :style="{
21
+ borderRadius: `${borderRadius}rpx`,
22
+ transform: effect3d && uCurrent != index ? 'scaleY(0.9)' : 'scaleY(1)',
23
+ margin: effect3d && uCurrent != index ? '0 20rpx' : 0
24
+ }"
25
+ >
26
+ <image class="u-swiper-image" :src="item[name] || item" :mode="imgMode"></image>
27
+ <view v-if="title && item.title" class="u-swiper-title u-line-1" :style="[{ 'padding-bottom': titlePaddingBottom }, titleStyle]">
28
+ {{ item.title }}
29
+ </view>
30
+ </view>
31
+ </swiper-item>
32
+ </swiper>
33
+ <view
34
+ class="u-swiper-indicator"
35
+ :style="{
36
+ top: indicatorPos == 'topLeft' || indicatorPos == 'topCenter' || indicatorPos == 'topRight' ? '12rpx' : 'auto',
37
+ bottom: indicatorPos == 'bottomLeft' || indicatorPos == 'bottomCenter' || indicatorPos == 'bottomRight' ? '12rpx' : 'auto',
38
+ justifyContent: justifyContent,
39
+ padding: `0 ${effect3d ? '74rpx' : '24rpx'}`
40
+ }"
41
+ >
42
+ <block v-if="mode == 'rect'">
43
+ <view class="u-indicator-item-rect" :class="{ 'u-indicator-item-rect-active': index == uCurrent }" v-for="(item, index) in list" :key="index"></view>
44
+ </block>
45
+ <block v-if="mode == 'dot'">
46
+ <view class="u-indicator-item-dot" :class="{ 'u-indicator-item-dot-active': index == uCurrent }" v-for="(item, index) in list" :key="index"></view>
47
+ </block>
48
+ <block v-if="mode == 'round'">
49
+ <view class="u-indicator-item-round" :class="{ 'u-indicator-item-round-active': index == uCurrent }" v-for="(item, index) in list" :key="index"></view>
50
+ </block>
51
+ <block v-if="mode == 'number'">
52
+ <view class="u-indicator-item-number">{{ uCurrent + 1 }}/{{ list.length }}</view>
53
+ </block>
54
+ </view>
55
+ </view>
56
+ </template>
57
+
58
+ <script setup lang="ts">
59
+ import { ref, computed, watch } from 'vue';
60
+ import { SwiperProps } from './types';
61
+
62
+ defineOptions({ name: 'u-swiper' });
63
+ /**
64
+ * swiper 轮播图
65
+ * @description 该组件一般用于导航轮播,广告展示等场景,可开箱即用
66
+ * @tutorial https://uview-pro.netlify.app/components/swiper.html
67
+ * @property {Array} list 轮播图数据,见官网"基本使用"说明
68
+ * @property {Boolean} title 是否显示标题文字,需要配合list参数,见官网说明(默认false)
69
+ * @property {String} mode 指示器模式,见官网说明(默认round)
70
+ * @property {String|Number} height 轮播图组件高度,单位rpx(默认250)
71
+ * @property {String} indicator-pos 指示器的位置(默认bottomCenter)
72
+ * @property {Boolean} effect3d 是否开启3D效果(默认false)
73
+ * @property {Boolean} autoplay 是否自动播放(默认true)
74
+ * @property {String|Number} interval 自动轮播时间间隔,单位ms(默认2500)
75
+ * @property {Boolean} circular 是否衔接播放,见官网说明(默认true)
76
+ * @property {String} bg-color 背景颜色(默认#f3f4f6)
77
+ * @property {String|Number} border-radius 轮播图圆角值,单位rpx(默认8)
78
+ * @property {Object} title-style 自定义标题样式
79
+ * @property {String|Number} effect3d-previous-margin mode = true模式的情况下,激活项与前后项之间的距离,单位rpx(默认50)
80
+ * @property {String} img-mode 图片的裁剪模式,详见image组件裁剪模式(默认aspectFill)
81
+ * @event {Function} click 点击轮播图时触发
82
+ * @example <u-swiper :list="list" mode="dot" indicator-pos="bottomRight"></u-swiper>
83
+ */
84
+
85
+ const props = defineProps(SwiperProps);
86
+ const emit = defineEmits(['click', 'change']);
87
+
88
+ // 当前活跃的swiper-item的index
89
+ const uCurrent = ref(Number(props.current));
90
+
91
+ // 监听list变化,重置uCurrent值,避免溢出
92
+ watch(
93
+ () => props.list,
94
+ (nVal, oVal) => {
95
+ if (nVal.length !== oVal.length) uCurrent.value = 0;
96
+ }
97
+ );
98
+ // 监听外部current的变化,实时修改内部依赖于此测uCurrent值
99
+ watch(
100
+ () => props.current,
101
+ n => {
102
+ uCurrent.value = Number(n);
103
+ }
104
+ );
105
+
106
+ // 容器 justifyContent
107
+ const justifyContent = computed(() => {
108
+ if (props.indicatorPos == 'topLeft' || props.indicatorPos == 'bottomLeft') return 'flex-start';
109
+ if (props.indicatorPos == 'topCenter' || props.indicatorPos == 'bottomCenter') return 'center';
110
+ if (props.indicatorPos == 'topRight' || props.indicatorPos == 'bottomRight') return 'flex-end';
111
+ return 'center';
112
+ });
113
+
114
+ // 标题下边距
115
+ const titlePaddingBottom = computed(() => {
116
+ if (props.mode == 'none') return '12rpx';
117
+ if (['bottomLeft', 'bottomCenter', 'bottomRight'].includes(props.indicatorPos) && props.mode == 'number') {
118
+ return '60rpx';
119
+ } else if (['bottomLeft', 'bottomCenter', 'bottomRight'].includes(props.indicatorPos) && props.mode != 'number') {
120
+ return '40rpx';
121
+ } else {
122
+ return '12rpx';
123
+ }
124
+ });
125
+
126
+ // swiper组件current参数只接受Number类型
127
+ const elCurrent = computed(() => Number(props.current));
128
+
129
+ /**
130
+ * 点击轮播图项
131
+ */
132
+ function listClick(index: number) {
133
+ emit('click', index);
134
+ }
135
+
136
+ /**
137
+ * swiper change事件
138
+ */
139
+ function change(e: any) {
140
+ const current = e.detail.current;
141
+ uCurrent.value = current;
142
+ emit('change', current);
143
+ }
144
+
145
+ /**
146
+ * swiper animationfinish事件
147
+ * 头条小程序不支持animationfinish事件,改由change事件
148
+ * 暂不监听此事件,因为不再给swiper绑定uCurrent属性
149
+ */
150
+ function animationfinish(e: any) {
151
+ // #ifndef MP-TOUTIAO
152
+ // uCurrent.value = e.detail.current
153
+ // #endif
154
+ }
155
+
156
+ defineExpose({ listClick, change, animationfinish });
157
+ </script>
158
+
159
+ <style lang="scss" scoped>
160
+ @import '../../libs/css/style.components.scss';
161
+
162
+ .u-swiper-wrap {
163
+ position: relative;
164
+ overflow: hidden;
165
+ transform: translateY(0);
166
+ }
167
+
168
+ .u-swiper-image {
169
+ width: 100%;
170
+ will-change: transform;
171
+ height: 100%;
172
+ /* #ifndef APP-NVUE */
173
+ display: block;
174
+ /* #endif */
175
+ /* #ifdef H5 */
176
+ pointer-events: none;
177
+ /* #endif */
178
+ }
179
+
180
+ .u-swiper-indicator {
181
+ padding: 0 24rpx;
182
+ position: absolute;
183
+ @include vue-flex;
184
+ width: 100%;
185
+ z-index: 1;
186
+ }
187
+
188
+ .u-indicator-item-rect {
189
+ width: 26rpx;
190
+ height: 8rpx;
191
+ margin: 0 6rpx;
192
+ transition: all 0.5s;
193
+ background-color: rgba(0, 0, 0, 0.3);
194
+ }
195
+
196
+ .u-indicator-item-rect-active {
197
+ background-color: rgba(255, 255, 255, 0.8);
198
+ }
199
+
200
+ .u-indicator-item-dot {
201
+ width: 14rpx;
202
+ height: 14rpx;
203
+ margin: 0 6rpx;
204
+ border-radius: 20rpx;
205
+ transition: all 0.5s;
206
+ background-color: rgba(0, 0, 0, 0.3);
207
+ }
208
+
209
+ .u-indicator-item-dot-active {
210
+ background-color: rgba(255, 255, 255, 0.8);
211
+ }
212
+
213
+ .u-indicator-item-round {
214
+ width: 14rpx;
215
+ height: 14rpx;
216
+ margin: 0 6rpx;
217
+ border-radius: 20rpx;
218
+ transition: all 0.5s;
219
+ background-color: rgba(0, 0, 0, 0.3);
220
+ }
221
+
222
+ .u-indicator-item-round-active {
223
+ width: 34rpx;
224
+ background-color: rgba(255, 255, 255, 0.8);
225
+ }
226
+
227
+ .u-indicator-item-number {
228
+ padding: 6rpx 16rpx;
229
+ line-height: 1;
230
+ background-color: rgba(0, 0, 0, 0.3);
231
+ border-radius: 100rpx;
232
+ font-size: 26rpx;
233
+ color: rgba(255, 255, 255, 0.8);
234
+ }
235
+
236
+ .u-list-scale {
237
+ transform-origin: center center;
238
+ }
239
+
240
+ .u-list-image-wrap {
241
+ width: 100%;
242
+ height: 100%;
243
+ flex: 1;
244
+ transition: all 0.5s;
245
+ overflow: hidden;
246
+ box-sizing: content-box;
247
+ position: relative;
248
+ }
249
+
250
+ .u-swiper-title {
251
+ position: absolute;
252
+ background-color: rgba(0, 0, 0, 0.3);
253
+ bottom: 0;
254
+ left: 0;
255
+ width: 100%;
256
+ font-size: 28rpx;
257
+ padding: 12rpx 24rpx;
258
+ color: rgba(255, 255, 255, 0.9);
259
+ }
260
+
261
+ .u-swiper-item {
262
+ @include vue-flex;
263
+ overflow: hidden;
264
+ align-items: center;
265
+ }
266
+ </style>