@didaoktv/didaoui-uniapp 2.12.0 → 2.14.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 (60) hide show
  1. package/README.md +7 -7
  2. package/components/dd-album/dd-album.vue +280 -228
  3. package/components/dd-avatar/dd-avatar.vue +132 -75
  4. package/components/dd-avatar-group/dd-avatar-group.vue +52 -30
  5. package/components/dd-barcode/dd-barcode.vue +884 -947
  6. package/components/dd-button/dd-button.vue +47 -21
  7. package/components/dd-canvas/dd-canvas.vue +1156 -985
  8. package/components/dd-car-keyboard/dd-car-keyboard.vue +12 -12
  9. package/components/dd-champion-card/dd-champion-card.vue +49 -21
  10. package/components/dd-checkbox-group/dd-checkbox-group.vue +2 -0
  11. package/components/dd-copy/dd-copy.vue +51 -56
  12. package/components/dd-cropper/dd-cropper.vue +1224 -1135
  13. package/components/dd-divider/dd-divider.vue +9 -2
  14. package/components/dd-fold/dd-fold.vue +133 -0
  15. package/components/dd-form/dd-form.vue +2 -0
  16. package/components/dd-icon/dd-icon.vue +1 -1
  17. package/components/dd-keyboard/dd-keyboard.vue +95 -46
  18. package/components/dd-link/dd-link.vue +72 -49
  19. package/components/dd-markdown/dd-markdown.vue +154 -154
  20. package/components/dd-number-keyboard/dd-number-keyboard.vue +109 -94
  21. package/components/dd-parse/dd-parse.vue +473 -442
  22. package/components/dd-poster/dd-poster.vue +579 -567
  23. package/components/dd-pull-refresh/dd-pull-refresh.vue +1 -9
  24. package/components/dd-qrcode/dd-qrcode.vue +431 -405
  25. package/components/dd-radio-group/dd-radio-group.vue +1 -1
  26. package/components/dd-segmented-tab/dd-segmented-tab.vue +22 -14
  27. package/components/dd-signature/dd-signature.vue +377 -357
  28. package/components/dd-step/dd-step.vue +1 -1
  29. package/components/dd-sticky/dd-sticky.vue +5 -10
  30. package/components/dd-swipe-action/dd-swipe-action.vue +1 -9
  31. package/components/dd-swipe-item/dd-swipe-item.vue +2 -0
  32. package/components/dd-swipeable-tab/dd-swipeable-tab.vue +1 -5
  33. package/components/dd-switch/dd-switch.vue +1 -1
  34. package/components/dd-text/dd-text.vue +304 -82
  35. package/components/dd-waterfall/dd-waterfall.vue +89 -0
  36. package/index.ts +8 -6
  37. package/libs/function/index.d.ts +88 -0
  38. package/libs/function/index.js +14 -0
  39. package/libs/function/test.d.ts +65 -0
  40. package/package.json +1 -1
  41. package/scss/_mixins.scss +8 -0
  42. package/scss/_theme-tokens.scss +7 -0
  43. package/scss/_variables.scss +283 -156
  44. package/components/dd-album/album.js +0 -19
  45. package/components/dd-album/props.js +0 -89
  46. package/components/dd-avatar/avatar.js +0 -19
  47. package/components/dd-avatar/props.js +0 -84
  48. package/components/dd-avatar-group/avatarGroup.js +0 -14
  49. package/components/dd-avatar-group/props.js +0 -57
  50. package/components/dd-keyboard/keyboard.js +0 -19
  51. package/components/dd-keyboard/props.js +0 -79
  52. package/components/dd-link/link.js +0 -17
  53. package/components/dd-link/props.js +0 -44
  54. package/components/dd-number-keyboard/numberKeyboard.js +0 -8
  55. package/components/dd-number-keyboard/props.js +0 -24
  56. package/components/dd-parse/props.js +0 -57
  57. package/components/dd-text/props.js +0 -120
  58. package/components/dd-text/text.js +0 -30
  59. package/components/dd-text/value.js +0 -87
  60. package/scss/_dd-shared.scss +0 -40
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  - **帝王级配色** — 帝王金 `#F5A623` + 皇家蓝 `#2D4BA0` 双主色,暗色主题默认
8
8
  - **玻璃拟态设计** — 多层级玻璃拟态效果,打造高端夜店沉浸感
9
- - **98 个精心打磨的组件** — 覆盖表单、导航、布局卡片、数据展示、浮层反馈、交互、画布七大类,含 KTV 业务组件(房态卡、账单明细、工单卡、日历、二维码)
9
+ - **101 个精心打磨的组件** — 覆盖表单、导航、布局卡片、数据展示、浮层反馈、交互、画布七大类,含 KTV 业务组件(房态卡、账单明细、工单卡、日历、二维码)
10
10
  - **Vue3 + TypeScript** — 完整类型定义,Composition API
11
11
  - **多端兼容** — H5 / 微信小程序 / 抖音小程序 / Android / iOS
12
12
 
@@ -52,8 +52,8 @@ import { DdButton, DdInput } from '@didaoktv/didaoui-uniapp'
52
52
  | ----- | -- | --------------------------------------------------------------------------------------------------------------------------------------------- |
53
53
  | 表单输入 | 25 | Button, CodeButton, Input, Form, Field, Switch, Checkbox, CheckboxGroup, Radio, RadioGroup, Stepper, SearchBar, Slider, DatePicker, Picker, Rate, Upload, Icon, Keyboard, NumberKeyboard, CarKeyboard, Cascader, GoodsSku, PackageSku, TreeSelect |
54
54
  | 导航 | 14 | Navigation, TopNavbar, SegmentedTab, SwipeableTab, Drawer, Tabbar, TabbarItem, Backtop, Collapse, CollapseItem, DropdownMenu, DropdownItem, Sidebar, SidebarItem | |
55
- | 布局/卡片 | 11 | Card, RoomCard, GoodsCard, FeatureGrid, Sticky, BillDetail, WorkorderCard, Calendar, Qrcode, SubmitBar, CartBar |
56
- | 数据展示 | 25 | Tag, StatCard, ChampionCard, Avatar, AvatarGroup, Badge, ListCell, Cell, CellGroup, CountDown, Divider, Image, Progress, Skeleton, EmptyState, Step, Steps, Text, Link, Copy, Album, Coupon, Parse, Markdown, Price |
55
+ | 布局/卡片 | 12 | Card, RoomCard, GoodsCard, FeatureGrid, Waterfall, Sticky, BillDetail, WorkorderCard, Calendar, Qrcode, SubmitBar, CartBar |
56
+ | 数据展示 | 26 | Tag, StatCard, ChampionCard, Avatar, AvatarGroup, Badge, ListCell, Cell, CellGroup, Fold, CountDown, Divider, Image, Progress, Skeleton, EmptyState, Step, Steps, Text, Link, Copy, Album, Coupon, Parse, Markdown, Price |
57
57
  | 浮层反馈 | 11 | Modal, ActionSheet, Toast, Alert, Loading, Dialog, Overlay, Popup, Popover, PopoverItem, Portal |
58
58
  | 交互 | 5 | SwipeAction, Swipe, SwipeItem, PullRefresh, Loadmore |
59
59
  | 小程序专属 | 2 | CapsuleButton, MiniProgramNavbar |
@@ -73,15 +73,15 @@ import { DdButton, DdInput } from '@didaoktv/didaoui-uniapp'
73
73
  - 主字体: 'Noto Sans SC', sans-serif
74
74
  - 展示字体: 'Playfair Display', serif
75
75
  - 等宽字体: 'JetBrains Mono', monospace
76
- - 字号阶梯: 12 / 14 / 16 / 18 / 20 / 24 / 32 px
76
+ - 字号阶梯: 24 / 28 / 32 / 36 / 40 / 48 / 64 rpx(1px=2rpx,对应设计稿 12~32px)
77
77
 
78
78
  ### 圆角
79
79
 
80
- 2 / 4 / 8 / 12 / 16 / 9999 px
80
+ 4 / 8 / 16 / 24 / 32 / 9999 rpx(1px=2rpx)
81
81
 
82
82
  ### 间距
83
83
 
84
- 4 / 8 / 12 / 16 / 24 / 32 / 48 / 64 px (8pt 基础网格)
84
+ 8 / 16 / 24 / 32 / 48 / 64 / 96 / 128 rpx(1px=2rpx,8pt 基础网格)
85
85
 
86
86
  ### 主题与浅色模式(v1.3.0+)
87
87
 
@@ -91,7 +91,7 @@ import { DdButton, DdInput } from '@didaoktv/didaoui-uniapp'
91
91
  |----|------|---------|
92
92
  | SCSS 编译期 | `_variables.scss` 全量 `!default`,消费者先声明变量再引入即可覆盖 | 整个 App 固定品牌换肤 |
93
93
  | CSS 变量运行时 | 组件消费 `var(--dd-x, #{$dd-x})`,SCSS 值为兜底(不引入主题文件时与旧版渲染一致) | 明暗切换、多主题共存 |
94
- | delta 级联 | `:root`/`page` 发射全量默认值(base 59 + 暗色 44),主题类只声明与默认不同的变量,未声明自动继承 | 快速配置新主题 |
94
+ | delta 级联 | `:root`/`page` 发射全量默认值(base 65 + 暗色 45),主题类只声明与默认不同的变量,未声明自动继承 | 快速配置新主题 |
95
95
 
96
96
  **启用运行时主题**:在 `App.vue` 全局样式引入:
97
97
 
@@ -3,7 +3,7 @@
3
3
  <!-- 相册行容器,每行显示 rowCount 个图片 -->
4
4
  <view
5
5
  class="dd-album__row"
6
- ref="dd-album__row"
6
+ ref="albumRowRef"
7
7
  v-for="(arr, index) in showUrls"
8
8
  :forComputedUse="albumWidth"
9
9
  :key="index"
@@ -45,8 +45,8 @@
45
45
  "
46
46
  class="dd-album__row__wrapper__text"
47
47
  :style="{
48
- borderRadius: shape == 'circle' ? '50%' : addUnit(radius),
49
- }"
48
+ borderRadius: shape == 'circle' ? '50%' : addUnit(radius),
49
+ }"
50
50
  >
51
51
  <dd-text
52
52
  :text="`+${urls.length - maxCount}`"
@@ -61,12 +61,10 @@
61
61
  </view>
62
62
  </template>
63
63
 
64
- <script>
65
- import { props } from './props';
66
- import { mpMixin } from '../../libs/mixin/mpMixin';
67
- import { mixin } from '../../libs/mixin/mixin';
68
- import { addUnit, sleep } from '../../libs/function/index';
69
- import test from '../../libs/function/test';
64
+ <script setup lang="ts">
65
+ import { computed, getCurrentInstance, ref, watch } from 'vue'
66
+ import { addUnit, getRect, sleep } from '../../libs/function/index.js'
67
+ import test from '../../libs/function/test'
70
68
  // #ifdef APP-NVUE
71
69
  // 不支持百分比单位,这里需要通过dom查询组件的宽度
72
70
  const dom = uni.requireNativePlugin('dom')
@@ -94,236 +92,290 @@ const dom = uni.requireNativePlugin('dom')
94
92
  * @event {Function} albumWidth 某些特殊的情况下,需要让文字与相册的宽度相等,这里事件的形式对外发送 (回调参数 width )
95
93
  * @example <dd-album :urls="urls2" @albumWidth="width => albumWidth = width" multipleSize="68" ></dd-album>
96
94
  */
97
- export default {
98
- name: 'dd-album',
99
- mixins: [mpMixin, mixin, props],
100
- data() {
101
- return {
102
- // 单图的宽度
103
- singleWidth: 0,
104
- // 单图的高度
105
- singleHeight: 0,
106
- // 单图时,如果无法获取图片的尺寸信息,让图片宽度默认为容器的一定百分比
107
- singlePercent: 0.6
108
- }
109
- },
110
- watch: {
111
- urls: {
112
- immediate: true,
113
- handler(newVal) {
114
- // 当只有一张图片时,获取图片尺寸信息
115
- if (newVal.length === 1) {
116
- this.getImageRect()
117
- }
118
- }
95
+
96
+ interface Props {
97
+ // 图片地址,Array<String>|Array<Object>形式
98
+ urls?: any[]
99
+ // 指定从数组的对象元素中读取哪个属性作为图片地址
100
+ keyName?: string
101
+ // 单图时,图片长边的长度
102
+ singleSize?: any
103
+ // 多图时,图片边长
104
+ multipleSize?: any
105
+ // 多图时,图片水平和垂直之间的间隔
106
+ space?: any
107
+ // 单图时,图片缩放裁剪的模式
108
+ singleMode?: string
109
+ // 多图时,图片缩放裁剪的模式
110
+ multipleMode?: string
111
+ // 最多展示的图片数量,超出时最后一个位置将会显示剩余图片数量
112
+ maxCount?: any
113
+ // 是否可以预览图片
114
+ previewFullImage?: boolean
115
+ // 每行展示图片数量,如设置,singleSize和multipleSize将会无效
116
+ rowCount?: any
117
+ // 超出maxCount时是否显示查看更多的提示
118
+ showMore?: boolean
119
+ // 图片形状,circle-圆形,square-方形(原 props.js 取自未注册的 image 默认值,实际为 undefined)
120
+ shape?: any
121
+ // 圆角,单位任意(同上,实际为 undefined)
122
+ radius?: any
123
+ // 自适应换行
124
+ autoWrap?: boolean
125
+ // 单位
126
+ unit?: string
127
+ // 阻止点击冒泡
128
+ stop?: boolean
129
+ }
130
+
131
+ const props = withDefaults(defineProps<Props>(), {
132
+ urls: () => [],
133
+ keyName: '',
134
+ singleSize: 180,
135
+ multipleSize: 70,
136
+ space: 6,
137
+ singleMode: 'scaleToFill',
138
+ multipleMode: 'aspectFill',
139
+ maxCount: 9,
140
+ previewFullImage: true,
141
+ rowCount: 3,
142
+ showMore: true,
143
+ autoWrap: false,
144
+ unit: 'px',
145
+ stop: true,
146
+ })
147
+
148
+ const emit = defineEmits<{
149
+ (e: 'preview', payload: { urls: any[]; currentIndex: number }): void
150
+ (e: 'albumWidth', width: any): void
151
+ }>()
152
+
153
+ const instance = getCurrentInstance()
154
+ const albumRowRef = ref<any>(null)
155
+
156
+ // 单图的宽度
157
+ const singleWidth = ref<any>(0)
158
+ // 单图的高度
159
+ const singleHeight = ref<any>(0)
160
+ // 单图时,如果无法获取图片的尺寸信息,让图片宽度默认为容器的一定百分比
161
+ const singlePercent = 0.6
162
+
163
+ watch(
164
+ () => props.urls,
165
+ (newVal: any[]) => {
166
+ // 当只有一张图片时,获取图片尺寸信息
167
+ if (newVal.length === 1) {
168
+ getImageRect()
169
+ }
170
+ },
171
+ { immediate: true }
172
+ )
173
+
174
+ /**
175
+ * 计算图片样式
176
+ * @param {Number} index1 - 行索引
177
+ * @param {Number} index2 - 列索引
178
+ * @returns {Object} 图片样式对象
179
+ */
180
+ const imageStyle = computed(() => {
181
+ return (index1: number, index2: number) => {
182
+ const { space, rowCount, multipleSize } = props,
183
+ rowLen = showUrls.value.length
184
+ const style: any = {
185
+ marginRight: addUnit(space),
186
+ marginBottom: addUnit(space),
187
+ }
188
+ // 如果为最后一行,则每个图片都无需下边框
189
+ if (index1 === rowLen && !props.autoWrap) style.marginBottom = 0
190
+ // 每行的最右边一张和总长度的最后一张无需右边框
191
+ if (!props.autoWrap) {
192
+ if (index2 === rowCount || (index1 === rowLen && index2 === showUrls.value[index1 - 1].length))
193
+ style.marginRight = 0
194
+ }
195
+ return style
196
+ }
197
+ })
198
+
199
+ /**
200
+ * 将图片地址数组划分为二维数组,用于按行显示
201
+ * @returns {Array} 二维数组,每个子数组代表一行图片
202
+ */
203
+ const showUrls = computed(() => {
204
+ if (props.autoWrap) {
205
+ // 自动换行模式下,所有图片放在一行中显示
206
+ return [props.urls.slice(0, props.maxCount)]
207
+ } else {
208
+ // 固定行数模式下,按 rowCount 分割图片
209
+ const arr: any[] = []
210
+ props.urls.map((item: any, index: number) => {
211
+ // 限制最大展示数量
212
+ if (index + 1 <= props.maxCount) {
213
+ // 计算该元素为第几个素组内
214
+ const itemIndex = Math.floor(index / props.rowCount)
215
+ // 判断对应的索引是否存在
216
+ if (!arr[itemIndex]) {
217
+ arr[itemIndex] = []
119
218
  }
219
+ arr[itemIndex].push(item)
220
+ }
221
+ })
222
+ return arr
223
+ }
224
+ })
225
+
226
+ /**
227
+ * 计算图片宽度
228
+ * @returns {String} 图片宽度样式值
229
+ */
230
+ const imageWidth = computed(() => addUnit(props.urls.length === 1 ? singleWidth.value : props.multipleSize, props.unit))
231
+
232
+ /**
233
+ * 计算图片高度
234
+ * @returns {String} 图片高度样式值
235
+ */
236
+ const imageHeight = computed(() => addUnit(props.urls.length === 1 ? singleHeight.value : props.multipleSize, props.unit))
237
+
238
+ /**
239
+ * 计算相册总宽度,用于外部组件对齐
240
+ * 此变量无实际用途,仅仅是为了利用computed特性,让其在urls长度等变化时,重新计算图片的宽度
241
+ * @returns {Number} 相册宽度
242
+ */
243
+ const albumWidth = computed(() => {
244
+ let width = 0
245
+ if (props.urls.length === 1) {
246
+ width = singleWidth.value
247
+ } else {
248
+ width = showUrls.value[0].length * props.multipleSize + props.space * (showUrls.value[0].length - 1)
249
+ }
250
+ emit('albumWidth', width)
251
+ return width
252
+ })
253
+
254
+ function noop(e: any) {
255
+ e && typeof e.stopPropagation === 'function' && e.stopPropagation()
256
+ }
257
+
258
+ /**
259
+ * 点击图片预览
260
+ * @param {Event} e - 点击事件对象
261
+ * @param {String} url - 当前点击图片的地址
262
+ */
263
+ function onPreviewTap(e: any, url: any) {
264
+ // 获取所有图片地址
265
+ const urls = props.urls.map((item: any) => {
266
+ return getSrc(item)
267
+ })
268
+ if (props.previewFullImage) {
269
+ // 使用系统默认预览图片功能
270
+ uni.previewImage({
271
+ current: url,
272
+ urls,
273
+ })
274
+ // 是否阻止事件传播(原 mixin 无 preventEvent,此处按 stopPropagation 语义补齐)
275
+ props.stop && noop(e)
276
+ } else {
277
+ // 发送自定义预览事件
278
+ emit('preview', {
279
+ urls,
280
+ currentIndex: urls.indexOf(url),
281
+ })
282
+ }
283
+ }
284
+
285
+ /**
286
+ * 获取图片地址
287
+ * @param {String|Object} item - 图片项,可以是字符串或对象
288
+ * @returns {String} 图片地址
289
+ */
290
+ function getSrc(item: any) {
291
+ return test.object(item) ? (props.keyName && item[props.keyName]) || item.src : item
292
+ }
293
+
294
+ /**
295
+ * 单图时,获取图片的尺寸
296
+ * 在小程序中,需要将网络图片的的域名添加到小程序的download域名才可能获取尺寸
297
+ * 在没有添加的情况下,让单图宽度默认为盒子的一定宽度(singlePercent)
298
+ */
299
+ function getImageRect() {
300
+ const src = getSrc(props.urls[0])
301
+ uni.getImageInfo({
302
+ src,
303
+ success: (res) => {
304
+ let singleSize = props.singleSize
305
+ // 单位
306
+ let unit = ''
307
+ if (Number.isNaN(Number(props.singleSize))) {
308
+ // 大小中有字符 则记录字符
309
+ unit = props.singleSize.replace(/\d+/g, '') // 单位
310
+ singleSize = Number(props.singleSize.replace(/\D+/g, '')) // 具体值
311
+ }
312
+
313
+ // 判断图片横向还是竖向展示方式
314
+ const isHorizotal = res.width >= res.height
315
+ singleWidth.value = isHorizotal ? singleSize : (res.width / res.height) * singleSize
316
+ singleHeight.value = !isHorizotal ? singleSize : (res.height / res.width) * singleWidth.value
317
+
318
+ // 如果有单位统一设置单位
319
+ if (unit != null && unit !== '') {
320
+ singleWidth.value = singleWidth.value + unit
321
+ singleHeight.value = singleHeight.value + unit
322
+ }
120
323
  },
121
- computed: {
122
- /**
123
- * 计算图片样式
124
- * @param {Number} index1 - 行索引
125
- * @param {Number} index2 - 列索引
126
- * @returns {Object} 图片样式对象
127
- */
128
- imageStyle() {
129
- return (index1, index2) => {
130
- const { space, rowCount, multipleSize, urls } = this,
131
- rowLen = this.showUrls.length,
132
- allLen = this.urls.length
133
- const style = {
134
- marginRight: addUnit(space),
135
- marginBottom: addUnit(space)
136
- }
137
- // 如果为最后一行,则每个图片都无需下边框
138
- if (index1 === rowLen && !this.autoWrap) style.marginBottom = 0
139
- // 每行的最右边一张和总长度的最后一张无需右边框
140
- if (!this.autoWrap) {
141
- if (
142
- index2 === rowCount ||
143
- (index1 === rowLen &&
144
- index2 === this.showUrls[index1 - 1].length)
145
- )
146
- style.marginRight = 0
147
- }
148
- return style
149
- }
150
- },
151
- /**
152
- * 将图片地址数组划分为二维数组,用于按行显示
153
- * @returns {Array} 二维数组,每个子数组代表一行图片
154
- */
155
- showUrls() {
156
- if (this.autoWrap) {
157
- // 自动换行模式下,所有图片放在一行中显示
158
- return [ this.urls.slice(0, this.maxCount) ];
159
- } else {
160
- // 固定行数模式下,按 rowCount 分割图片
161
- const arr = []
162
- this.urls.map((item, index) => {
163
- // 限制最大展示数量
164
- if (index + 1 <= this.maxCount) {
165
- // 计算该元素为第几个素组内
166
- const itemIndex = Math.floor(index / this.rowCount)
167
- // 判断对应的索引是否存在
168
- if (!arr[itemIndex]) {
169
- arr[itemIndex] = []
170
- }
171
- arr[itemIndex].push(item)
172
- }
173
- })
174
- return arr
175
- }
176
- },
177
- /**
178
- * 计算图片宽度
179
- * @returns {String} 图片宽度样式值
180
- */
181
- imageWidth() {
182
- return addUnit(
183
- this.urls.length === 1 ? this.singleWidth : this.multipleSize, this.unit
184
- )
185
- },
186
- /**
187
- * 计算图片高度
188
- * @returns {String} 图片高度样式值
189
- */
190
- imageHeight() {
191
- return addUnit(
192
- this.urls.length === 1 ? this.singleHeight : this.multipleSize, this.unit
193
- )
194
- },
195
- /**
196
- * 计算相册总宽度,用于外部组件对齐
197
- * 此变量无实际用途,仅仅是为了利用computed特性,让其在urls长度等变化时,重新计算图片的宽度
198
- * @returns {Number} 相册宽度
199
- */
200
- albumWidth() {
201
- let width = 0
202
- if (this.urls.length === 1) {
203
- width = this.singleWidth
204
- } else {
205
- width =
206
- this.showUrls[0].length * this.multipleSize +
207
- this.space * (this.showUrls[0].length - 1)
208
- }
209
- this.$emit('albumWidth', width)
210
- return width
211
- }
324
+ fail: () => {
325
+ // 获取图片信息失败时,通过组件宽度计算
326
+ getComponentWidth()
212
327
  },
213
- emits: ['preview', 'albumWidth'],
214
- methods: {
215
- addUnit,
216
- /**
217
- * 点击图片预览
218
- * @param {Event} e - 点击事件对象
219
- * @param {String} url - 当前点击图片的地址
220
- */
221
- onPreviewTap(e, url) {
222
- // 获取所有图片地址
223
- const urls = this.urls.map((item) => {
224
- return this.getSrc(item)
225
- })
226
- if (this.previewFullImage) {
227
- // 使用系统默认预览图片功能
228
- uni.previewImage({
229
- current: url,
230
- urls
231
- })
232
- // 是否阻止事件传播
233
- this.stop && this.preventEvent(e)
234
- } else {
235
- // 发送自定义预览事件
236
- this.$emit('preview', {
237
- urls,
238
- currentIndex: urls.indexOf(url)
239
- })
240
- }
241
- },
242
- /**
243
- * 获取图片地址
244
- * @param {String|Object} item - 图片项,可以是字符串或对象
245
- * @returns {String} 图片地址
246
- */
247
- getSrc(item) {
248
- return test.object(item)
249
- ? (this.keyName && item[this.keyName]) || item.src
250
- : item
251
- },
252
- /**
253
- * 单图时,获取图片的尺寸
254
- * 在小程序中,需要将网络图片的的域名添加到小程序的download域名才可能获取尺寸
255
- * 在没有添加的情况下,让单图宽度默认为盒子的一定宽度(singlePercent)
256
- */
257
- getImageRect() {
258
- const src = this.getSrc(this.urls[0])
259
- uni.getImageInfo({
260
- src,
261
- success: (res) => {
262
- let singleSize = this.singleSize;
263
- // 单位
264
- let unit = '';
265
- if (Number.isNaN(Number(this.singleSize))) {
266
- // 大小中有字符 则记录字符
267
- unit = this.singleSize.replace(/\d+/g, ''); // 单位
268
- singleSize = Number(this.singleSize.replace(/\D+/g, ''), 10); // 具体值
269
- }
270
-
271
- // 判断图片横向还是竖向展示方式
272
- const isHorizotal = res.width >= res.height
273
- this.singleWidth = isHorizotal
274
- ? singleSize
275
- : (res.width / res.height) * singleSize
276
- this.singleHeight = !isHorizotal
277
- ? singleSize
278
- : (res.height / res.width) * this.singleWidth
328
+ })
329
+ }
279
330
 
280
- // 如果有单位统一设置单位
281
- if(unit != null && unit !== ''){
282
- this.singleWidth = this.singleWidth + unit
283
- this.singleHeight = this.singleHeight + unit
284
- }
285
- },
286
- fail: () => {
287
- // 获取图片信息失败时,通过组件宽度计算
288
- this.getComponentWidth()
289
- }
290
- })
291
- },
292
- /**
293
- * 获取组件的宽度,用于计算单图显示尺寸
294
- */
295
- async getComponentWidth() {
296
- // 延时一定时间,以获取dom尺寸
297
- await sleep(30)
298
- // #ifndef APP-NVUE
299
- // H5、小程序等平台通过 getRect 获取组件宽度
300
- this.getRect('.dd-album__row').then((size) => {
301
- this.singleWidth = size.width * this.singlePercent
302
- })
303
- // #endif
331
+ /**
332
+ * 获取组件的宽度,用于计算单图显示尺寸
333
+ */
334
+ async function getComponentWidth() {
335
+ // 延时一定时间,以获取dom尺寸
336
+ await sleep(30)
337
+ // #ifndef APP-NVUE
338
+ // H5、小程序等平台通过 getRect 获取组件宽度
339
+ getRect('.dd-album__row', false, instance).then((size: any) => {
340
+ singleWidth.value = size.width * singlePercent
341
+ })
342
+ // #endif
304
343
 
305
- // #ifdef APP-NVUE
306
- // NVUE 平台通过 dom 插件获取组件宽度
307
- // 这里ref="dd-album__row"所在的标签为通过for循环出来,导致this.$refs['dd-album__row']是一个数组
308
- const ref = this.$refs['dd-album__row'][0]
309
- ref &&
310
- dom.getComponentRect(ref, (res) => {
311
- this.singleWidth = res.size.width * this.singlePercent
312
- })
313
- // #endif
314
- }
315
- }
344
+ // #ifdef APP-NVUE
345
+ // NVUE 平台通过 dom 插件获取组件宽度
346
+ // 这里ref="albumRowRef"所在的标签为通过for循环出来,ref 值为数组,取第一个
347
+ const refs = albumRowRef.value
348
+ const ref = Array.isArray(refs) ? refs[0] : refs
349
+ ref &&
350
+ dom.getComponentRect(ref, (res: any) => {
351
+ singleWidth.value = res.size.width * singlePercent
352
+ })
353
+ // #endif
316
354
  }
355
+
356
+ defineExpose({
357
+ singleWidth,
358
+ singleHeight,
359
+ showUrls,
360
+ imageStyle,
361
+ imageWidth,
362
+ imageHeight,
363
+ albumWidth,
364
+ getSrc,
365
+ onPreviewTap,
366
+ getImageRect,
367
+ getComponentWidth,
368
+ })
317
369
  </script>
318
370
 
319
371
  <style lang="scss" scoped>
320
372
  @import '../../scss/variables';
321
- @import '../../scss/dd-shared';
373
+ @import '../../scss/mixins';
322
374
  .dd-album {
323
- @include flex(column);
375
+ @include dd-flex(column);
324
376
 
325
377
  &__row {
326
- @include flex(row);
378
+ @include dd-flex(row);
327
379
 
328
380
  &__wrapper {
329
381
  position: relative;
@@ -335,11 +387,11 @@ export default {
335
387
  right: 0;
336
388
  bottom: 0;
337
389
  background-color: rgba(0, 0, 0, 0.3);
338
- @include flex(row);
390
+ @include dd-flex(row);
339
391
  justify-content: center;
340
392
  align-items: center;
341
393
  }
342
394
  }
343
395
  }
344
396
  }
345
- </style>
397
+ </style>