uview-plus 3.1.52 → 3.2.5

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/changelog.md +51 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +1 -1
  3. package/components/u-album/u-album.vue +261 -261
  4. package/components/u-avatar/u-avatar.vue +3 -2
  5. package/components/u-avatar-group/u-avatar-group.vue +106 -106
  6. package/components/u-button/u-button.vue +6 -1
  7. package/components/u-calendar/u-calendar.vue +4 -3
  8. package/components/u-cell/u-cell.vue +4 -2
  9. package/components/u-checkbox/props.js +5 -0
  10. package/components/u-checkbox/u-checkbox.vue +29 -17
  11. package/components/u-code/u-code.vue +1 -1
  12. package/components/u-dropdown/props.js +8 -14
  13. package/components/u-dropdown/u-dropdown.vue +202 -77
  14. package/components/u-dropdown-item/props.js +45 -36
  15. package/components/u-dropdown-item/u-dropdown-item.vue +121 -148
  16. package/components/u-form/u-form.vue +1 -1
  17. package/components/u-form-item/props.js +6 -1
  18. package/components/u-form-item/u-form-item.vue +1 -1
  19. package/components/u-grid/u-grid.vue +4 -2
  20. package/components/u-grid-item/u-grid-item.vue +8 -7
  21. package/components/u-input/u-input.vue +1 -1
  22. package/components/u-lazy-load/u-lazy-load.vue +251 -0
  23. package/components/u-number-box/u-number-box.vue +4 -4
  24. package/components/u-picker/u-picker.vue +5 -2
  25. package/components/u-popup/u-popup.vue +1 -1
  26. package/components/u-radio/u-radio.vue +2 -2
  27. package/components/u-rate/u-rate.vue +1 -1
  28. package/components/u-read-more/u-read-more.vue +164 -160
  29. package/components/u-slider/u-slider.vue +6 -6
  30. package/components/u-steps-item/u-steps-item.vue +318 -318
  31. package/components/u-subsection/u-subsection.vue +35 -21
  32. package/components/u-swiper/u-swiper.vue +6 -8
  33. package/components/u-switch/u-switch.vue +1 -1
  34. package/components/u-tabbar-item/u-tabbar-item.vue +1 -1
  35. package/components/u-tabs/u-tabs.vue +1 -0
  36. package/components/u-tag/props.js +5 -2
  37. package/components/u-tag/u-tag.vue +1 -1
  38. package/components/u-text/u-text.vue +226 -226
  39. package/components/u-textarea/u-textarea.vue +275 -275
  40. package/components/u-transition/u-transition.vue +1 -1
  41. package/components/u-waterfall/u-waterfall.vue +225 -0
  42. package/index.js +5 -2
  43. package/libs/config/props/formItem.js +1 -0
  44. package/libs/config/props/tag.js +30 -29
  45. package/libs/css/common.scss +4 -1
  46. package/libs/css/components.scss +5 -5
  47. package/libs/css/flex.scss +45 -45
  48. package/libs/mixin/mixin.js +2 -2
  49. package/libs/mixin/mpShare.js +15 -13
  50. package/package.json +1 -1
  51. package/types/comps/_common.d.ts +9 -0
  52. package/types/comps/actionSheet.d.ts +121 -0
  53. package/types/comps/album.d.ts +72 -0
  54. package/types/comps/alert.d.ts +55 -0
  55. package/types/comps/avatar.d.ts +85 -0
  56. package/types/comps/avatarGroup.d.ts +62 -0
  57. package/types/comps/backTop.d.ts +74 -0
  58. package/types/comps/badge.d.ts +76 -0
  59. package/types/comps/button.d.ts +169 -0
  60. package/types/comps/calendar.d.ts +164 -0
  61. package/types/comps/cell.d.ts +133 -0
  62. package/types/comps/cellGroup.d.ts +27 -0
  63. package/types/comps/checkbox.d.ts +69 -0
  64. package/types/comps/checkboxGroup.d.ts +93 -0
  65. package/types/comps/code.d.ts +69 -0
  66. package/types/comps/codeInput.d.ts +98 -0
  67. package/types/comps/col.d.ts +43 -0
  68. package/types/comps/collapse.d.ts +52 -0
  69. package/types/comps/collapseItem.d.ts +83 -0
  70. package/types/comps/countDown.d.ts +60 -0
  71. package/types/comps/countTo.d.ts +88 -0
  72. package/types/comps/datetimePicker.d.ts +146 -0
  73. package/types/comps/divider.d.ts +58 -0
  74. package/types/comps/empty.d.ts +72 -0
  75. package/types/comps/form.d.ts +76 -0
  76. package/types/comps/formItem.d.ts +68 -0
  77. package/types/comps/gap.d.ts +35 -0
  78. package/types/comps/grid.d.ts +34 -0
  79. package/types/comps/gridItem.d.ts +28 -0
  80. package/types/comps/icon.d.ts +93 -0
  81. package/types/comps/image.d.ts +119 -0
  82. package/types/comps/indexAnchor.d.ts +38 -0
  83. package/types/comps/indexItem.d.ts +18 -0
  84. package/types/comps/indexList.d.ts +39 -0
  85. package/types/comps/input.d.ts +234 -0
  86. package/types/comps/keyboard.d.ts +125 -0
  87. package/types/comps/line.d.ts +44 -0
  88. package/types/comps/lineProgress.d.ts +51 -0
  89. package/types/comps/link.d.ts +51 -0
  90. package/types/comps/list.d.ts +92 -0
  91. package/types/comps/listItem.d.ts +18 -0
  92. package/types/comps/loadMore.d.ts +108 -0
  93. package/types/comps/loadingIcon.d.ts +68 -0
  94. package/types/comps/loadingPage.d.ts +58 -0
  95. package/types/comps/modal.d.ts +115 -0
  96. package/types/comps/navbar.d.ts +113 -0
  97. package/types/comps/noNetwork.d.ts +40 -0
  98. package/types/comps/noticeBar.d.ts +85 -0
  99. package/types/comps/notify.d.ts +73 -0
  100. package/types/comps/numberBox.d.ts +155 -0
  101. package/types/comps/overlay.d.ts +46 -0
  102. package/types/comps/parse.d.ts +101 -0
  103. package/types/comps/picker.d.ts +115 -0
  104. package/types/comps/popup.d.ts +103 -0
  105. package/types/comps/radio.d.ts +77 -0
  106. package/types/comps/radioGroup.d.ts +97 -0
  107. package/types/comps/rate.d.ts +85 -0
  108. package/types/comps/readMore.d.ts +80 -0
  109. package/types/comps/row.d.ts +34 -0
  110. package/types/comps/scrollList.d.ts +51 -0
  111. package/types/comps/search.d.ts +167 -0
  112. package/types/comps/skeleton.d.ts +70 -0
  113. package/types/comps/slider.d.ts +79 -0
  114. package/types/comps/steps.d.ts +48 -0
  115. package/types/comps/stepsItem.d.ts +41 -0
  116. package/types/comps/sticky.d.ts +48 -0
  117. package/types/comps/subsection.d.ts +64 -0
  118. package/types/comps/swipeAction.d.ts +24 -0
  119. package/types/comps/swipeActionItem.d.ts +58 -0
  120. package/types/comps/swiper.d.ts +142 -0
  121. package/types/comps/swiperIndicator.d.ts +37 -0
  122. package/types/comps/switch.d.ts +73 -0
  123. package/types/comps/tabbar.d.ts +54 -0
  124. package/types/comps/tabbarItem.d.ts +52 -0
  125. package/types/comps/tabs.d.ts +85 -0
  126. package/types/comps/tag.d.ts +93 -0
  127. package/types/comps/text.d.ts +110 -0
  128. package/types/comps/textarea.d.ts +158 -0
  129. package/types/comps/toast.d.ts +59 -0
  130. package/types/comps/tooltip.d.ts +71 -0
  131. package/types/comps/transition.d.ts +61 -0
  132. package/types/comps/upload.d.ts +163 -0
  133. package/types/comps.d.ts +99 -0
  134. package/types/index.d.ts +47 -0
package/changelog.md CHANGED
@@ -1,3 +1,54 @@
1
+ ## 3.2.5(2024-04-13)
2
+ 调整分段器尺寸及修复窗口大小改变时重新计算尺寸
3
+
4
+ 多个组件支持cursor-pointer增强PC端体验
5
+
6
+ ## 3.2.4(2024-04-12)
7
+ 初步支持typescript
8
+ ## 3.2.3(2024-04-12)
9
+ fix: 修复square属性在小程序下无效问题
10
+
11
+ fix:修复lastIndex异常导致的column异常问题
12
+
13
+ fix: alipayapp picker style
14
+
15
+ feat(button): 添加用户同意隐私协议事件回调
16
+
17
+ fix: input switch password
18
+
19
+ fix: 修复u-code组件keepRuning失效问题
20
+
21
+ feat: form-item添加labelPosition属性
22
+
23
+ 新增dropdown组件
24
+
25
+ 分段器支持内部current值
26
+
27
+ 优化cell和action-sheet视觉大小
28
+
29
+ 修复tabs文字换行
30
+
31
+ ## 3.2.2(2024-04-11)
32
+ 修复换行符问题
33
+ ## 3.2.1(2024-04-11)
34
+ 修复演示H5二维码
35
+
36
+ fix: #270 ReadMore 展开阅读更多内容变化兼容
37
+
38
+ fix: #238Calendar组件maxDate修改为不能小于minDate
39
+
40
+ checkbox支持独立使用
41
+
42
+ 修复popup中在微信小程序中真机调试滚动失效
43
+
44
+ ## 3.2.0(2024-04-10)
45
+ 修复轮播图在nvue显示
46
+ 修复疑似u-slider名称被占用导致slider在App下不显示
47
+ 解决微信小程序提示 Some selectors are not allowed in component wxss
48
+ 示例中u-前缀统一为up-
49
+ 增加瀑布流与图片懒加载组件
50
+ fix: #308修复tag组件缺失iconColor参数
51
+ fix: #297使用grid布局解决目前编译为抖音小程序无法开启virtualHost
1
52
  ## 3.1.52(2024-04-07)
2
53
  工具类方法调用import化改造
3
54
  新增up-copy复制组件
@@ -202,7 +202,7 @@
202
202
  $u-action-sheet-description-font-size:13px !default;
203
203
  $u-action-sheet-description-color:14px !default;
204
204
  $u-action-sheet-description-margin: 18px 15px !default;
205
- $u-action-sheet-item-wrap-item-padding:15px !default;
205
+ $u-action-sheet-item-wrap-item-padding:17px !default;
206
206
  $u-action-sheet-item-wrap-name-font-size:16px !default;
207
207
  $u-action-sheet-item-wrap-subname-font-size:13px !default;
208
208
  $u-action-sheet-item-wrap-subname-color: #c0c4cc !default;
@@ -1,262 +1,262 @@
1
- <template>
2
- <view class="u-album">
3
- <view
4
- class="u-album__row"
5
- ref="u-album__row"
6
- v-for="(arr, index) in showUrls"
7
- :forComputedUse="albumWidth"
8
- :key="index"
9
- >
10
- <view
11
- class="u-album__row__wrapper"
12
- v-for="(item, index1) in arr"
13
- :key="index1"
14
- :style="[imageStyle(index + 1, index1 + 1)]"
15
- @tap="previewFullImage ? onPreviewTap(getSrc(item)) : ''"
16
- >
17
- <image
18
- :src="getSrc(item)"
19
- :mode="
20
- urls.length === 1
21
- ? imageHeight > 0
22
- ? singleMode
23
- : 'widthFix'
24
- : multipleMode
25
- "
26
- :style="[
27
- {
28
- width: imageWidth,
29
- height: imageHeight
30
- }
31
- ]"
32
- ></image>
33
- <view
34
- v-if="
35
- showMore &&
36
- urls.length > rowCount * showUrls.length &&
37
- index === showUrls.length - 1 &&
38
- index1 === showUrls[showUrls.length - 1].length - 1
39
- "
40
- class="u-album__row__wrapper__text"
41
- >
42
- <u--text
43
- :text="`+${urls.length - maxCount}`"
44
- color="#fff"
45
- :size="multipleSize * 0.3"
46
- align="center"
47
- customStyle="justify-content: center"
48
- ></u--text>
49
- </view>
50
- </view>
51
- </view>
52
- </view>
53
- </template>
54
-
55
- <script>
56
- import props from './props.js';
57
- import mpMixin from '../../libs/mixin/mpMixin.js';
58
- import mixin from '../../libs/mixin/mixin.js';
59
- // #ifdef APP-NVUE
60
- // 由于weex为阿里的KPI业绩考核的产物,所以不支持百分比单位,这里需要通过dom查询组件的宽度
61
- const dom = uni.requireNativePlugin('dom')
62
- // #endif
63
-
64
- /**
65
- * Album 相册
66
- * @description 本组件提供一个类似相册的功能,让开发者开发起来更加得心应手。减少重复的模板代码
67
- * @tutorial https://ijry.github.io/uview-plus/components/album.html
68
- *
69
- * @property {Array} urls 图片地址列表 Array<String>|Array<Object>形式
70
- * @property {String} keyName 指定从数组的对象元素中读取哪个属性作为图片地址
71
- * @property {String | Number} singleSize 单图时,图片长边的长度 (默认 180 )
72
- * @property {String | Number} multipleSize 多图时,图片边长 (默认 70 )
73
- * @property {String | Number} space 多图时,图片水平和垂直之间的间隔 (默认 6 )
74
- * @property {String} singleMode 单图时,图片缩放裁剪的模式 (默认 'scaleToFill' )
75
- * @property {String} multipleMode 多图时,图片缩放裁剪的模式 (默认 'aspectFill' )
76
- * @property {String | Number} maxCount 取消按钮的提示文字 (默认 9 )
77
- * @property {Boolean} previewFullImage 是否可以预览图片 (默认 true )
78
- * @property {String | Number} rowCount 每行展示图片数量,如设置,singleSize和multipleSize将会无效 (默认 3 )
79
- * @property {Boolean} showMore 超出maxCount时是否显示查看更多的提示 (默认 true )
80
- *
81
- * @event {Function} albumWidth 某些特殊的情况下,需要让文字与相册的宽度相等,这里事件的形式对外发送 (回调参数 width )
82
- * @example <u-album :urls="urls2" @albumWidth="width => albumWidth = width" multipleSize="68" ></u-album>
83
- */
84
- export default {
85
- name: 'u-album',
86
- mixins: [mpMixin, mixin, props],
87
- data() {
88
- return {
89
- // 单图的宽度
90
- singleWidth: 0,
91
- // 单图的高度
92
- singleHeight: 0,
93
- // 单图时,如果无法获取图片的尺寸信息,让图片宽度默认为容器的一定百分比
94
- singlePercent: 0.6
95
- }
96
- },
97
- watch: {
98
- urls: {
99
- immediate: true,
100
- handler(newVal) {
101
- if (newVal.length === 1) {
102
- this.getImageRect()
103
- }
104
- }
105
- }
106
- },
107
- emits: ["albumWidth"],
108
- computed: {
109
- imageStyle() {
110
- return (index1, index2) => {
111
- const { space, rowCount, multipleSize, urls } = this,
112
- { addUnit, addStyle } = uni.$u,
113
- rowLen = this.showUrls.length,
114
- allLen = this.urls.length
115
- const style = {
116
- marginRight: addUnit(space),
117
- marginBottom: addUnit(space)
118
- }
119
- // 如果为最后一行,则每个图片都无需下边框
120
- if (index1 === rowLen) style.marginBottom = 0
121
- // 每行的最右边一张和总长度的最后一张无需右边框
122
- if (
123
- index2 === rowCount ||
124
- (index1 === rowLen &&
125
- index2 === this.showUrls[index1 - 1].length)
126
- )
127
- style.marginRight = 0
128
- return style
129
- }
130
- },
131
- // 将数组划分为二维数组
132
- showUrls() {
133
- const arr = []
134
- this.urls.map((item, index) => {
135
- // 限制最大展示数量
136
- if (index + 1 <= this.maxCount) {
137
- // 计算该元素为第几个素组内
138
- const itemIndex = Math.floor(index / this.rowCount)
139
- // 判断对应的索引是否存在
140
- if (!arr[itemIndex]) {
141
- arr[itemIndex] = []
142
- }
143
- arr[itemIndex].push(item)
144
- }
145
- })
146
- return arr
147
- },
148
- imageWidth() {
149
- return uni.$u.addUnit(
150
- this.urls.length === 1 ? this.singleWidth : this.multipleSize
151
- )
152
- },
153
- imageHeight() {
154
- return uni.$u.addUnit(
155
- this.urls.length === 1 ? this.singleHeight : this.multipleSize
156
- )
157
- },
158
- // 此变量无实际用途,仅仅是为了利用computed特性,让其在urls长度等变化时,重新计算图片的宽度
159
- // 因为用户在某些特殊的情况下,需要让文字与相册的宽度相等,所以这里事件的形式对外发送
160
- albumWidth() {
161
- let width = 0
162
- if (this.urls.length === 1) {
163
- width = this.singleWidth
164
- } else {
165
- width =
166
- this.showUrls[0].length * this.multipleSize +
167
- this.space * (this.showUrls[0].length - 1)
168
- }
169
- this.$emit('albumWidth', width)
170
- return width
171
- }
172
- },
173
- methods: {
174
- // 预览图片
175
- onPreviewTap(url) {
176
- const urls = this.urls.map((item) => {
177
- return this.getSrc(item)
178
- })
179
- uni.previewImage({
180
- current: url,
181
- urls
182
- })
183
- },
184
- // 获取图片的路径
185
- getSrc(item) {
186
- return uni.$u.test.object(item)
187
- ? (this.keyName && item[this.keyName]) || item.src
188
- : item
189
- },
190
- // 单图时,获取图片的尺寸
191
- // 在小程序中,需要将网络图片的的域名添加到小程序的download域名才可能获取尺寸
192
- // 在没有添加的情况下,让单图宽度默认为盒子的一定宽度(singlePercent)
193
- getImageRect() {
194
- const src = this.getSrc(this.urls[0])
195
- uni.getImageInfo({
196
- src,
197
- success: (res) => {
198
- // 判断图片横向还是竖向展示方式
199
- const isHorizotal = res.width >= res.height
200
- this.singleWidth = isHorizotal
201
- ? this.singleSize
202
- : (res.width / res.height) * this.singleSize
203
- this.singleHeight = !isHorizotal
204
- ? this.singleSize
205
- : (res.height / res.width) * this.singleWidth
206
- },
207
- fail: () => {
208
- this.getComponentWidth()
209
- }
210
- })
211
- },
212
- // 获取组件的宽度
213
- async getComponentWidth() {
214
- // 延时一定时间,以获取dom尺寸
215
- await uni.$u.sleep(30)
216
- // #ifndef APP-NVUE
217
- this.$uGetRect('.u-album__row').then((size) => {
218
- this.singleWidth = size.width * this.singlePercent
219
- })
220
- // #endif
221
-
222
- // #ifdef APP-NVUE
223
- // 这里ref="u-album__row"所在的标签为通过for循环出来,导致this.$refs['u-album__row']是一个数组
224
- const ref = this.$refs['u-album__row'][0]
225
- ref &&
226
- dom.getComponentRect(ref, (res) => {
227
- this.singleWidth = res.size.width * this.singlePercent
228
- })
229
- // #endif
230
- }
231
- }
232
- }
233
- </script>
234
-
235
- <style lang="scss" scoped>
236
- @import '../../libs/css/components.scss';
237
-
238
- .u-album {
239
- @include flex(column);
240
-
241
- &__row {
242
- @include flex(row);
243
- flex-wrap: wrap;
244
-
245
- &__wrapper {
246
- position: relative;
247
-
248
- &__text {
249
- position: absolute;
250
- top: 0;
251
- left: 0;
252
- right: 0;
253
- bottom: 0;
254
- background-color: rgba(0, 0, 0, 0.3);
255
- @include flex(row);
256
- justify-content: center;
257
- align-items: center;
258
- }
259
- }
260
- }
261
- }
1
+ <template>
2
+ <view class="u-album">
3
+ <view
4
+ class="u-album__row"
5
+ ref="u-album__row"
6
+ v-for="(arr, index) in showUrls"
7
+ :forComputedUse="albumWidth"
8
+ :key="index"
9
+ >
10
+ <view
11
+ class="u-album__row__wrapper"
12
+ v-for="(item, index1) in arr"
13
+ :key="index1"
14
+ :style="[imageStyle(index + 1, index1 + 1)]"
15
+ @tap="previewFullImage ? onPreviewTap(getSrc(item)) : ''"
16
+ >
17
+ <image
18
+ :src="getSrc(item)"
19
+ :mode="
20
+ urls.length === 1
21
+ ? imageHeight > 0
22
+ ? singleMode
23
+ : 'widthFix'
24
+ : multipleMode
25
+ "
26
+ :style="[
27
+ {
28
+ width: imageWidth,
29
+ height: imageHeight
30
+ }
31
+ ]"
32
+ ></image>
33
+ <view
34
+ v-if="
35
+ showMore &&
36
+ urls.length > rowCount * showUrls.length &&
37
+ index === showUrls.length - 1 &&
38
+ index1 === showUrls[showUrls.length - 1].length - 1
39
+ "
40
+ class="u-album__row__wrapper__text"
41
+ >
42
+ <up-text
43
+ :text="`+${urls.length - maxCount}`"
44
+ color="#fff"
45
+ :size="multipleSize * 0.3"
46
+ align="center"
47
+ customStyle="justify-content: center"
48
+ ></up-text>
49
+ </view>
50
+ </view>
51
+ </view>
52
+ </view>
53
+ </template>
54
+
55
+ <script>
56
+ import props from './props.js';
57
+ import mpMixin from '../../libs/mixin/mpMixin.js';
58
+ import mixin from '../../libs/mixin/mixin.js';
59
+ // #ifdef APP-NVUE
60
+ // 由于weex为阿里的KPI业绩考核的产物,所以不支持百分比单位,这里需要通过dom查询组件的宽度
61
+ const dom = uni.requireNativePlugin('dom')
62
+ // #endif
63
+
64
+ /**
65
+ * Album 相册
66
+ * @description 本组件提供一个类似相册的功能,让开发者开发起来更加得心应手。减少重复的模板代码
67
+ * @tutorial https://ijry.github.io/uview-plus/components/album.html
68
+ *
69
+ * @property {Array} urls 图片地址列表 Array<String>|Array<Object>形式
70
+ * @property {String} keyName 指定从数组的对象元素中读取哪个属性作为图片地址
71
+ * @property {String | Number} singleSize 单图时,图片长边的长度 (默认 180 )
72
+ * @property {String | Number} multipleSize 多图时,图片边长 (默认 70 )
73
+ * @property {String | Number} space 多图时,图片水平和垂直之间的间隔 (默认 6 )
74
+ * @property {String} singleMode 单图时,图片缩放裁剪的模式 (默认 'scaleToFill' )
75
+ * @property {String} multipleMode 多图时,图片缩放裁剪的模式 (默认 'aspectFill' )
76
+ * @property {String | Number} maxCount 取消按钮的提示文字 (默认 9 )
77
+ * @property {Boolean} previewFullImage 是否可以预览图片 (默认 true )
78
+ * @property {String | Number} rowCount 每行展示图片数量,如设置,singleSize和multipleSize将会无效 (默认 3 )
79
+ * @property {Boolean} showMore 超出maxCount时是否显示查看更多的提示 (默认 true )
80
+ *
81
+ * @event {Function} albumWidth 某些特殊的情况下,需要让文字与相册的宽度相等,这里事件的形式对外发送 (回调参数 width )
82
+ * @example <u-album :urls="urls2" @albumWidth="width => albumWidth = width" multipleSize="68" ></u-album>
83
+ */
84
+ export default {
85
+ name: 'u-album',
86
+ mixins: [mpMixin, mixin, props],
87
+ data() {
88
+ return {
89
+ // 单图的宽度
90
+ singleWidth: 0,
91
+ // 单图的高度
92
+ singleHeight: 0,
93
+ // 单图时,如果无法获取图片的尺寸信息,让图片宽度默认为容器的一定百分比
94
+ singlePercent: 0.6
95
+ }
96
+ },
97
+ watch: {
98
+ urls: {
99
+ immediate: true,
100
+ handler(newVal) {
101
+ if (newVal.length === 1) {
102
+ this.getImageRect()
103
+ }
104
+ }
105
+ }
106
+ },
107
+ emits: ["albumWidth"],
108
+ computed: {
109
+ imageStyle() {
110
+ return (index1, index2) => {
111
+ const { space, rowCount, multipleSize, urls } = this,
112
+ { addUnit, addStyle } = uni.$u,
113
+ rowLen = this.showUrls.length,
114
+ allLen = this.urls.length
115
+ const style = {
116
+ marginRight: addUnit(space),
117
+ marginBottom: addUnit(space)
118
+ }
119
+ // 如果为最后一行,则每个图片都无需下边框
120
+ if (index1 === rowLen) style.marginBottom = 0
121
+ // 每行的最右边一张和总长度的最后一张无需右边框
122
+ if (
123
+ index2 === rowCount ||
124
+ (index1 === rowLen &&
125
+ index2 === this.showUrls[index1 - 1].length)
126
+ )
127
+ style.marginRight = 0
128
+ return style
129
+ }
130
+ },
131
+ // 将数组划分为二维数组
132
+ showUrls() {
133
+ const arr = []
134
+ this.urls.map((item, index) => {
135
+ // 限制最大展示数量
136
+ if (index + 1 <= this.maxCount) {
137
+ // 计算该元素为第几个素组内
138
+ const itemIndex = Math.floor(index / this.rowCount)
139
+ // 判断对应的索引是否存在
140
+ if (!arr[itemIndex]) {
141
+ arr[itemIndex] = []
142
+ }
143
+ arr[itemIndex].push(item)
144
+ }
145
+ })
146
+ return arr
147
+ },
148
+ imageWidth() {
149
+ return uni.$u.addUnit(
150
+ this.urls.length === 1 ? this.singleWidth : this.multipleSize
151
+ )
152
+ },
153
+ imageHeight() {
154
+ return uni.$u.addUnit(
155
+ this.urls.length === 1 ? this.singleHeight : this.multipleSize
156
+ )
157
+ },
158
+ // 此变量无实际用途,仅仅是为了利用computed特性,让其在urls长度等变化时,重新计算图片的宽度
159
+ // 因为用户在某些特殊的情况下,需要让文字与相册的宽度相等,所以这里事件的形式对外发送
160
+ albumWidth() {
161
+ let width = 0
162
+ if (this.urls.length === 1) {
163
+ width = this.singleWidth
164
+ } else {
165
+ width =
166
+ this.showUrls[0].length * this.multipleSize +
167
+ this.space * (this.showUrls[0].length - 1)
168
+ }
169
+ this.$emit('albumWidth', width)
170
+ return width
171
+ }
172
+ },
173
+ methods: {
174
+ // 预览图片
175
+ onPreviewTap(url) {
176
+ const urls = this.urls.map((item) => {
177
+ return this.getSrc(item)
178
+ })
179
+ uni.previewImage({
180
+ current: url,
181
+ urls
182
+ })
183
+ },
184
+ // 获取图片的路径
185
+ getSrc(item) {
186
+ return uni.$u.test.object(item)
187
+ ? (this.keyName && item[this.keyName]) || item.src
188
+ : item
189
+ },
190
+ // 单图时,获取图片的尺寸
191
+ // 在小程序中,需要将网络图片的的域名添加到小程序的download域名才可能获取尺寸
192
+ // 在没有添加的情况下,让单图宽度默认为盒子的一定宽度(singlePercent)
193
+ getImageRect() {
194
+ const src = this.getSrc(this.urls[0])
195
+ uni.getImageInfo({
196
+ src,
197
+ success: (res) => {
198
+ // 判断图片横向还是竖向展示方式
199
+ const isHorizotal = res.width >= res.height
200
+ this.singleWidth = isHorizotal
201
+ ? this.singleSize
202
+ : (res.width / res.height) * this.singleSize
203
+ this.singleHeight = !isHorizotal
204
+ ? this.singleSize
205
+ : (res.height / res.width) * this.singleWidth
206
+ },
207
+ fail: () => {
208
+ this.getComponentWidth()
209
+ }
210
+ })
211
+ },
212
+ // 获取组件的宽度
213
+ async getComponentWidth() {
214
+ // 延时一定时间,以获取dom尺寸
215
+ await uni.$u.sleep(30)
216
+ // #ifndef APP-NVUE
217
+ this.$uGetRect('.u-album__row').then((size) => {
218
+ this.singleWidth = size.width * this.singlePercent
219
+ })
220
+ // #endif
221
+
222
+ // #ifdef APP-NVUE
223
+ // 这里ref="u-album__row"所在的标签为通过for循环出来,导致this.$refs['u-album__row']是一个数组
224
+ const ref = this.$refs['u-album__row'][0]
225
+ ref &&
226
+ dom.getComponentRect(ref, (res) => {
227
+ this.singleWidth = res.size.width * this.singlePercent
228
+ })
229
+ // #endif
230
+ }
231
+ }
232
+ }
233
+ </script>
234
+
235
+ <style lang="scss" scoped>
236
+ @import '../../libs/css/components.scss';
237
+
238
+ .u-album {
239
+ @include flex(column);
240
+
241
+ &__row {
242
+ @include flex(row);
243
+ flex-wrap: wrap;
244
+
245
+ &__wrapper {
246
+ position: relative;
247
+
248
+ &__text {
249
+ position: absolute;
250
+ top: 0;
251
+ left: 0;
252
+ right: 0;
253
+ bottom: 0;
254
+ background-color: rgba(0, 0, 0, 0.3);
255
+ @include flex(row);
256
+ justify-content: center;
257
+ align-items: center;
258
+ }
259
+ }
260
+ }
261
+ }
262
262
  </style>
@@ -29,14 +29,14 @@
29
29
  :size="fontSize"
30
30
  :color="color"
31
31
  ></u-icon>
32
- <u--text
32
+ <up-text
33
33
  v-else-if="text"
34
34
  :text="text"
35
35
  :size="fontSize"
36
36
  :color="color"
37
37
  align="center"
38
38
  customStyle="justify-content: center"
39
- ></u--text>
39
+ ></up-text>
40
40
  <image
41
41
  class="u-avatar__image"
42
42
  v-else
@@ -165,6 +165,7 @@
165
165
  &__image {
166
166
  &--circle {
167
167
  border-radius: 100px;
168
+ overflow: hidden;
168
169
  }
169
170
 
170
171
  &--square {