uview-plus 3.8.49 → 3.8.86

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 (170) hide show
  1. package/changelog.md +2043 -1827
  2. package/components/u-action-sheet/props.js +3 -1
  3. package/components/u-action-sheet/u-action-sheet.vue +1 -0
  4. package/components/u-album/props.js +3 -1
  5. package/components/u-alert/props.js +4 -2
  6. package/components/u-avatar/props.js +4 -1
  7. package/components/u-avatar-group/props.js +4 -1
  8. package/components/u-back-top/props.js +4 -1
  9. package/components/u-badge/props.js +4 -1
  10. package/components/u-barcode/u-barcode.vue +46 -15
  11. package/components/u-box/props.js +5 -2
  12. package/components/u-button/props.js +4 -1
  13. package/components/u-button/vue.scss +3 -3
  14. package/components/u-calendar/calendar.js +14 -2
  15. package/components/u-calendar/month.vue +41 -6
  16. package/components/u-calendar/props.js +63 -1
  17. package/components/u-calendar/u-calendar.vue +311 -2
  18. package/components/u-calendar-strip/props.js +3 -1
  19. package/components/u-canvas/u-canvas.vue +734 -423
  20. package/components/u-car-keyboard/props.js +3 -1
  21. package/components/u-card/props.js +3 -1
  22. package/components/u-cell/props.js +4 -1
  23. package/components/u-cell/u-cell.vue +1 -1
  24. package/components/u-cell-group/props.js +4 -1
  25. package/components/u-checkbox/props.js +4 -1
  26. package/components/u-checkbox/u-checkbox.vue +7 -3
  27. package/components/u-checkbox-group/props.js +3 -1
  28. package/components/u-circle-progress/props.js +4 -1
  29. package/components/u-code/props.js +4 -1
  30. package/components/u-code-input/props.js +4 -1
  31. package/components/u-col/props.js +4 -1
  32. package/components/u-collapse/props.js +4 -1
  33. package/components/u-collapse-item/props.js +4 -1
  34. package/components/u-color-picker/u-color-picker.vue +1 -0
  35. package/components/u-column-notice/props.js +4 -1
  36. package/components/u-count-down/props.js +4 -1
  37. package/components/u-count-to/props.js +4 -1
  38. package/components/u-cropper/u-cropper.vue +95 -51
  39. package/components/u-datetime-picker/props.js +4 -1
  40. package/components/u-divider/props.js +4 -1
  41. package/components/u-dragsort/u-dragsort.vue +2 -1
  42. package/components/u-dropdown/props.js +3 -1
  43. package/components/u-dropdown-item/props.js +3 -1
  44. package/components/u-empty/props.js +4 -1
  45. package/components/u-form/props.js +4 -1
  46. package/components/u-form-item/props.js +4 -1
  47. package/components/u-gap/props.js +4 -1
  48. package/components/u-grid/props.js +4 -1
  49. package/components/u-grid-item/props.js +4 -1
  50. package/components/u-guide/props.js +3 -1
  51. package/components/u-icon/props.js +4 -1
  52. package/components/u-icon/u-icon.vue +2 -2
  53. package/components/u-icon/upicon.ttf +0 -0
  54. package/components/u-icon/util.js +29 -7
  55. package/components/u-image/props.js +4 -1
  56. package/components/u-image/u-image.vue +280 -267
  57. package/components/u-index-anchor/props.js +4 -1
  58. package/components/u-index-item/props.js +2 -1
  59. package/components/u-index-list/props.js +4 -1
  60. package/components/u-input/props.js +3 -1
  61. package/components/u-input/u-input.vue +10 -1
  62. package/components/u-keyboard/props.js +4 -1
  63. package/components/u-line/props.js +4 -1
  64. package/components/u-line-progress/props.js +6 -3
  65. package/components/u-link/props.js +4 -1
  66. package/components/u-list/props.js +4 -1
  67. package/components/u-list-item/props.js +4 -1
  68. package/components/u-loading-icon/props.js +4 -1
  69. package/components/u-loading-page/props.js +3 -1
  70. package/components/u-loadmore/props.js +4 -1
  71. package/components/u-markdown/u-markdown.vue +45 -3
  72. package/components/u-modal/props.js +4 -1
  73. package/components/u-navbar/props.js +4 -2
  74. package/components/u-navbar/u-navbar.vue +15 -9
  75. package/components/u-no-network/props.js +4 -1
  76. package/components/u-notice-bar/props.js +4 -1
  77. package/components/u-notify/props.js +4 -1
  78. package/components/u-number-box/props.js +4 -1
  79. package/components/u-number-box/u-number-box.vue +2 -2
  80. package/components/u-number-keyboard/props.js +4 -1
  81. package/components/u-overlay/props.js +4 -1
  82. package/components/u-pagination/u-pagination.vue +60 -39
  83. package/components/u-parse/props.js +4 -1
  84. package/components/u-picker/props.js +4 -1
  85. package/components/u-picker/u-picker.vue +15 -0
  86. package/components/u-picker-column/props.js +3 -1
  87. package/components/u-popover/props.js +2 -1
  88. package/components/u-popup/props.js +4 -1
  89. package/components/u-poster/u-poster.vue +29 -14
  90. package/components/u-qrcode/qrcode.js +88 -87
  91. package/components/u-qrcode/u-qrcode.vue +138 -256
  92. package/components/u-radio/props.js +4 -1
  93. package/components/u-radio/u-radio.vue +7 -3
  94. package/components/u-radio-group/props.js +4 -1
  95. package/components/u-rate/props.js +4 -1
  96. package/components/u-read-more/props.js +4 -1
  97. package/components/u-row/props.js +4 -1
  98. package/components/u-row-notice/props.js +4 -1
  99. package/components/u-safe-bottom/props.js +2 -1
  100. package/components/u-scroll-list/props.js +4 -1
  101. package/components/u-search/props.js +3 -1
  102. package/components/u-skeleton/props.js +4 -1
  103. package/components/u-slider/props.js +3 -1
  104. package/components/u-slider/u-slider.vue +70 -28
  105. package/components/u-status-bar/props.js +4 -1
  106. package/components/u-steps/props.js +4 -1
  107. package/components/u-steps-item/props.js +4 -1
  108. package/components/u-sticky/props.js +4 -1
  109. package/components/u-sticky/u-sticky.vue +11 -0
  110. package/components/u-subsection/props.js +3 -1
  111. package/components/u-swipe-action/props.js +4 -1
  112. package/components/u-swipe-action-item/props.js +4 -1
  113. package/components/u-swipe-action-item/u-swipe-action-item.vue +14 -0
  114. package/components/u-swiper/props.js +9 -1
  115. package/components/u-swiper/swiper.js +1 -0
  116. package/components/u-swiper/u-swiper.vue +2 -0
  117. package/components/u-swiper-indicator/props.js +4 -1
  118. package/components/u-switch/props.js +4 -1
  119. package/components/u-tabbar/props.js +3 -1
  120. package/components/u-tabbar-item/props.js +4 -1
  121. package/components/u-table/props.js +3 -1
  122. package/components/u-table2/tableRow.vue +155 -69
  123. package/components/u-table2/u-table2.vue +328 -140
  124. package/components/u-tabs/props.js +4 -1
  125. package/components/u-tabs-item/props.js +3 -1
  126. package/components/u-tag/props.js +4 -1
  127. package/components/u-td/props.js +3 -1
  128. package/components/u-text/props.js +4 -1
  129. package/components/u-textarea/props.js +3 -1
  130. package/components/u-textarea/u-textarea.vue +16 -5
  131. package/components/u-th/props.js +3 -1
  132. package/components/u-toolbar/props.js +4 -1
  133. package/components/u-tooltip/props.js +10 -2
  134. package/components/u-tooltip/tooltip.js +2 -1
  135. package/components/u-tooltip/u-tooltip.vue +31 -3
  136. package/components/u-tr/props.js +3 -1
  137. package/components/u-transition/nvue-ani-map.js +75 -68
  138. package/components/u-transition/props.js +4 -1
  139. package/components/u-transition/transitionMixin.js +164 -163
  140. package/components/u-upload/props.js +4 -1
  141. package/components/u-upload/u-upload.vue +47 -40
  142. package/components/u-waterfall/u-waterfall.vue +50 -51
  143. package/index.js +65 -8
  144. package/libs/config/props.js +179 -204
  145. package/libs/css/components.scss +3 -0
  146. package/libs/function/uni-api-shims.js +29 -0
  147. package/libs/i18n/index.js +71 -36
  148. package/libs/i18n/locale-packs.js +11 -0
  149. package/libs/i18n/locales/all.js +23 -0
  150. package/libs/i18n/locales/{de.json → de.js} +1 -1
  151. package/libs/i18n/locales/{en.json → en.js} +2 -2
  152. package/libs/i18n/locales/{es.json → es.js} +1 -1
  153. package/libs/i18n/locales/{fr.json → fr.js} +2 -2
  154. package/libs/i18n/locales/{ja.json → ja.js} +1 -1
  155. package/libs/i18n/locales/{ko.json → ko.js} +1 -1
  156. package/libs/i18n/locales/{ru.json → ru.js} +1 -1
  157. package/libs/i18n/locales/{th.json → th.js} +1 -1
  158. package/libs/i18n/locales/{zh-Hans.json → zh-Hans.js} +1 -1
  159. package/libs/i18n/locales/{zh-Hant.json → zh-Hant.js} +1 -1
  160. package/libs/mixin/mixin.js +14 -4
  161. package/libs/util/gcanvas/bridge/bridge-weex.js +10 -5
  162. package/package.json +4 -5
  163. package/tsconfig.json +18 -0
  164. package/types/comps/calendar.d.ts +57 -0
  165. package/types/comps/checkbox.d.ts +12 -0
  166. package/types/comps/lineProgress.d.ts +5 -0
  167. package/types/comps/navbar.d.ts +3 -3
  168. package/types/comps/swiper.d.ts +5 -0
  169. package/types/comps/tooltip.d.ts +36 -1
  170. /package/components/u-markdown/{marked.esm.js → marked.esm.mjs} +0 -0
@@ -1,163 +1,164 @@
1
- // 定义一个一定时间后自动成功的promise,让调用nextTick方法处,进入下一个then方法
2
- const waitTick = () => new Promise(resolve => setTimeout(resolve, 1000 / 50))
3
- // nvue动画模块实现细节抽离在外部文件
4
- // #ifdef APP-NVUE
5
- import animationMap from './nvue-ani-map.js'
6
- // #endif
7
-
8
- // #ifndef APP-NVUE
9
- // 定义类名,通过给元素动态切换类名,赋予元素一定的css动画样式
10
- const getClassNames = (name) => ({
11
- enter: `u-${name}-enter u-${name}-enter-active`,
12
- 'enter-to': `u-${name}-enter-to u-${name}-enter-active`,
13
- leave: `u-${name}-leave u-${name}-leave-active`,
14
- 'leave-to': `u-${name}-leave-to u-${name}-leave-active`
15
- })
16
- // #endif
17
-
18
- // #ifdef APP-NVUE
19
- // 引入nvue(weex)的animation动画模块,文档见:
20
- // https://weex.apache.org/zh/docs/modules/animation.html#transition
21
- const animation = uni.requireNativePlugin('animation')
22
- const getStyle = (name) => animationMap[name]
23
- // #endif
24
-
25
- import { nextTick } from 'vue'
26
- import { sleep } from '../../libs/function/index';
27
- export default {
28
- methods: {
29
- // 组件被点击发出事件
30
- clickHandler() {
31
- this.$emit('click')
32
- },
33
- // #ifndef APP-NVUE
34
- // vue版本的组件进场处理
35
- async vueEnter() {
36
- // 动画进入时的类名
37
- const classNames = getClassNames(this.mode)
38
- // 定义状态和发出动画进入前事件
39
- this.status = 'enter'
40
- this.$emit('beforeEnter')
41
- this.inited = true
42
- this.display = true
43
- this.classes = classNames.enter
44
- await nextTick();
45
- {
46
- // https://github.com/umicro/uView2.0/issues/545
47
- await sleep(20)
48
- // 标识动画尚未结束
49
- this.$emit('enter')
50
- this.transitionEnded = false
51
- // 组件动画进入后触发的事件
52
- this.$emit('afterEnter')
53
- // 赋予组件enter-to类名
54
- this.classes = classNames['enter-to']
55
- }
56
- },
57
- // 动画离场处理
58
- async vueLeave() {
59
- // 如果不是展示状态,无需执行逻辑
60
- if (!this.display) return
61
- const classNames = getClassNames(this.mode)
62
- // 标记离开状态和发出事件
63
- this.status = 'leave'
64
- this.$emit('beforeLeave')
65
- // 获得类名
66
- this.classes = classNames.leave
67
-
68
- await nextTick();
69
- {
70
- // 动画正在离场的状态
71
- this.transitionEnded = false
72
- this.$emit('leave')
73
- // 组件执行动画,到了执行的执行时间后,执行一些额外处理
74
- setTimeout(this.onTransitionEnd, this.duration)
75
- this.classes = classNames['leave-to']
76
- }
77
- },
78
- // #endif
79
- // #ifdef APP-NVUE
80
- // nvue版本动画进场
81
- async nvueEnter() {
82
- // 获得样式的名称
83
- const currentStyle = getStyle(this.mode)
84
- // 组件动画状态和发出事件
85
- this.status = 'enter'
86
- this.$emit('beforeEnter')
87
- // 展示生成组件元素
88
- this.inited = true
89
- this.display = true
90
- // 在nvue安卓上,由于渲染速度慢,在弹窗,键盘,日历等组件中,渲染其中的内容需要时间
91
- // 导致出现弹窗卡顿,这里让其一开始为透明状态,等一定时间渲染完成后,再让其隐藏起来,再让其按正常逻辑出现
92
- this.viewStyle = {
93
- opacity: 0
94
- }
95
- // 等待弹窗内容渲染完成
96
- await nextTick();
97
- {
98
- // 合并样式
99
- this.viewStyle = currentStyle.enter
100
- Promise.resolve()
101
- .then(waitTick)
102
- .then(() => {
103
- // 组件开始进入前的事件
104
- this.$emit('enter')
105
- // nvue的transition动画模块需要通过ref调用组件,注意此处的ref不同于vue的this.$refs['u-transition']用法
106
- animation.transition(this.$refs['u-transition'].ref, {
107
- styles: currentStyle['enter-to'],
108
- duration: this.duration,
109
- timingFunction: this.timingFunction,
110
- needLayout: false,
111
- delay: 0
112
- }, () => {
113
- // 动画执行完毕,发出事件
114
- this.$emit('afterEnter')
115
- })
116
- })
117
- .catch(() => {})
118
- }
119
- },
120
- nvueLeave() {
121
- if (!this.display) {
122
- return
123
- }
124
- const currentStyle = getStyle(this.mode)
125
- // 定义状态和事件
126
- this.status = 'leave'
127
- this.$emit('beforeLeave')
128
- // 合并样式
129
- this.viewStyle = currentStyle.leave
130
- // 放到promise中处理执行过程
131
- Promise.resolve()
132
- .then(waitTick) // 等待几十ms
133
- .then(() => {
134
- this.transitionEnded = false
135
- // 动画正在离场的状态
136
- this.$emit('leave')
137
- animation.transition(this.$refs['u-transition'].ref, {
138
- styles: currentStyle['leave-to'],
139
- duration: this.duration,
140
- timingFunction: this.timingFunction,
141
- needLayout: false,
142
- delay: 0
143
- }, () => {
144
- this.onTransitionEnd()
145
- })
146
- })
147
- .catch(() => {})
148
- },
149
- // #endif
150
- // 完成过渡后触发
151
- onTransitionEnd() {
152
- // 如果已经是结束的状态,无需再处理
153
- if (this.transitionEnded) return
154
- this.transitionEnded = true
155
- // 发出组件动画执行后的事件
156
- this.$emit(this.status === 'leave' ? 'afterLeave' : 'afterEnter')
157
- if (!this.show && this.display) {
158
- this.display = false
159
- this.inited = false
160
- }
161
- }
162
- }
163
- }
1
+ // 定义一个一定时间后自动成功的promise,让调用nextTick方法处,进入下一个then方法
2
+ const waitTick = () => new Promise(resolve => setTimeout(resolve, 1000 / 50))
3
+ // nvue动画模块实现细节抽离在外部文件
4
+ // #ifdef APP-NVUE
5
+ import animationMap from './nvue-ani-map.js'
6
+ // #endif
7
+
8
+ // #ifndef APP-NVUE
9
+ // 定义类名,通过给元素动态切换类名,赋予元素一定的css动画样式
10
+ const getClassNames = (name) => ({
11
+ enter: `u-${name}-enter u-${name}-enter-active`,
12
+ 'enter-to': `u-${name}-enter-to u-${name}-enter-active`,
13
+ leave: `u-${name}-leave u-${name}-leave-active`,
14
+ 'leave-to': `u-${name}-leave-to u-${name}-leave-active`
15
+ })
16
+ // #endif
17
+
18
+ // #ifdef APP-NVUE
19
+ // 引入nvue(weex)的animation动画模块,文档见:
20
+ // https://weex.apache.org/zh/docs/modules/animation.html#transition
21
+ const animation = uni.requireNativePlugin('animation')
22
+ const getStyle = (name) => animationMap[name]
23
+ // #endif
24
+
25
+ import { nextTick } from 'vue'
26
+ import { sleep } from '../../libs/function/index';
27
+ export default {
28
+ methods: {
29
+ // 组件被点击发出事件
30
+ clickHandler() {
31
+ this.$emit('click')
32
+ },
33
+ // #ifndef APP-NVUE
34
+ // vue版本的组件进场处理
35
+ async vueEnter() {
36
+ // 动画进入时的类名
37
+ const classNames = getClassNames(this.mode)
38
+ // 定义状态和发出动画进入前事件
39
+ this.status = 'enter'
40
+ this.$emit('beforeEnter')
41
+ this.inited = true
42
+ this.display = true
43
+ this.classes = classNames.enter
44
+ await nextTick();
45
+ {
46
+ // https://github.com/umicro/uView2.0/issues/545
47
+ await sleep(20)
48
+ // 标识动画尚未结束
49
+ this.$emit('enter')
50
+ this.transitionEnded = false
51
+ // 组件动画进入后触发的事件
52
+ this.$emit('afterEnter')
53
+ // 赋予组件enter-to类名
54
+ this.classes = classNames['enter-to']
55
+ }
56
+ },
57
+ // 动画离场处理
58
+ async vueLeave() {
59
+ // 如果不是展示状态,无需执行逻辑
60
+ if (!this.display) return
61
+ const classNames = getClassNames(this.mode)
62
+ // 标记离开状态和发出事件
63
+ this.status = 'leave'
64
+ this.$emit('beforeLeave')
65
+ // 获得类名
66
+ this.classes = classNames.leave
67
+
68
+ await nextTick();
69
+ {
70
+ // 动画正在离场的状态
71
+ this.transitionEnded = false
72
+ this.$emit('leave')
73
+ // 组件执行动画,到了执行的执行时间后,执行一些额外处理
74
+ setTimeout(this.onTransitionEnd, this.duration)
75
+ this.classes = classNames['leave-to']
76
+ }
77
+ },
78
+ // #endif
79
+ // #ifdef APP-NVUE
80
+ // nvue版本动画进场
81
+ async nvueEnter() {
82
+ // 获得样式的名称
83
+ const currentStyle = getStyle(this.mode) || getStyle('none')
84
+ // 组件动画状态和发出事件
85
+ this.status = 'enter'
86
+ this.$emit('beforeEnter')
87
+ // 展示生成组件元素
88
+ this.inited = true
89
+ this.display = true
90
+ // 在nvue安卓上,由于渲染速度慢,在弹窗,键盘,日历等组件中,渲染其中的内容需要时间
91
+ // 导致出现弹窗卡顿,这里让其一开始为透明状态,等一定时间渲染完成后,再让其隐藏起来,再让其按正常逻辑出现
92
+ // none 模式为页面内常驻展示,不需要预置透明
93
+ this.viewStyle = this.mode === 'none' ? { opacity: 1 } : {
94
+ opacity: 0
95
+ }
96
+ // 等待弹窗内容渲染完成
97
+ await nextTick();
98
+ {
99
+ // 合并样式
100
+ this.viewStyle = currentStyle.enter
101
+ Promise.resolve()
102
+ .then(waitTick)
103
+ .then(() => {
104
+ // 组件开始进入前的事件
105
+ this.$emit('enter')
106
+ // nvue的transition动画模块需要通过ref调用组件,注意此处的ref不同于vue的this.$refs['u-transition']用法
107
+ animation.transition(this.$refs['u-transition'].ref, {
108
+ styles: currentStyle['enter-to'],
109
+ duration: this.mode === 'none' ? 0 : this.duration,
110
+ timingFunction: this.timingFunction,
111
+ needLayout: false,
112
+ delay: 0
113
+ }, () => {
114
+ // 动画执行完毕,发出事件
115
+ this.$emit('afterEnter')
116
+ })
117
+ })
118
+ .catch(() => {})
119
+ }
120
+ },
121
+ nvueLeave() {
122
+ if (!this.display) {
123
+ return
124
+ }
125
+ const currentStyle = getStyle(this.mode) || getStyle('none')
126
+ // 定义状态和事件
127
+ this.status = 'leave'
128
+ this.$emit('beforeLeave')
129
+ // 合并样式
130
+ this.viewStyle = currentStyle.leave
131
+ // 放到promise中处理执行过程
132
+ Promise.resolve()
133
+ .then(waitTick) // 等待几十ms
134
+ .then(() => {
135
+ this.transitionEnded = false
136
+ // 动画正在离场的状态
137
+ this.$emit('leave')
138
+ animation.transition(this.$refs['u-transition'].ref, {
139
+ styles: currentStyle['leave-to'],
140
+ duration: this.mode === 'none' ? 0 : this.duration,
141
+ timingFunction: this.timingFunction,
142
+ needLayout: false,
143
+ delay: 0
144
+ }, () => {
145
+ this.onTransitionEnd()
146
+ })
147
+ })
148
+ .catch(() => {})
149
+ },
150
+ // #endif
151
+ // 完成过渡后触发
152
+ onTransitionEnd() {
153
+ // 如果已经是结束的状态,无需再处理
154
+ if (this.transitionEnded) return
155
+ this.transitionEnded = true
156
+ // 发出组件动画执行后的事件
157
+ this.$emit(this.status === 'leave' ? 'afterLeave' : 'afterEnter')
158
+ if (!this.show && this.display) {
159
+ this.display = false
160
+ this.inited = false
161
+ }
162
+ }
163
+ }
164
+ }
@@ -1,5 +1,8 @@
1
1
  import { defineMixin } from '../../libs/vue'
2
- import defProps from '../../libs/config/props.js'
2
+ import UploadDefaultProps from './upload'
3
+ import { registerComponentProps } from '../../libs/config/props.js'
4
+
5
+ const defProps = registerComponentProps(UploadDefaultProps)
3
6
  export const props = defineMixin({
4
7
  props: {
5
8
  // 接受的文件类型, 可选值为all media image file video
@@ -141,8 +141,14 @@
141
141
  </slot>
142
142
  </view>
143
143
  </template>
144
- <canvas id="myCanvas" type="2d"
145
- style="width: 100px; height: 150px;display: none;"></canvas>
144
+ <up-canvas
145
+ ref="videoThumbCanvas"
146
+ class="u-upload__hidden-canvas"
147
+ :canvas-id="videoThumbCanvasId"
148
+ :width="videoThumbCanvasWidth"
149
+ :height="videoThumbCanvasHeight"
150
+ bg-color="transparent"
151
+ ></up-canvas>
146
152
  <template v-if="isInCount">
147
153
  <view
148
154
  v-if="$slots.trigger"
@@ -257,7 +263,10 @@
257
263
  lists: [],
258
264
  isInCount: true,
259
265
  popupShow: false,
260
- currentItemIndex: -1
266
+ currentItemIndex: -1,
267
+ videoThumbCanvasId: 'u-upload-video-thumb-' + Math.random().toString(36).substr(2, 9),
268
+ videoThumbCanvasWidth: 100,
269
+ videoThumbCanvasHeight: 150
261
270
  }
262
271
  },
263
272
  watch: {
@@ -314,47 +323,37 @@
314
323
  return;
315
324
  }
316
325
  // 截取第一帧作为封面,oss等云存储场景直接使用拼接参数。
317
- let w = this.lists[this.currentItemIndex].width;
318
- let h = this.lists[this.currentItemIndex].height;
326
+ const w = this.lists[this.currentItemIndex].width;
327
+ const h = this.lists[this.currentItemIndex].height;
319
328
  const dpr = uni.getSystemInfoSync().pixelRatio;
320
329
  uni.createSelectorQuery().select('#myVideo').context(res => {
321
330
  console.log('select video', res)
322
331
  const myVideo = res.context
323
- uni.createSelectorQuery()
324
- .select('#myCanvas')
325
- .fields({ node: true, size: true })
326
- .exec(([res]) => {
327
- console.log('select canvas', res)
328
- const ctx1 = res[0].node.getContext('2d')
329
- res[0].node.width = w * dpr
330
- res[0].node.height = h * dpr
331
- // Draw the first frame and export it as an image
332
- // myVideo.onPlay(() => {
333
- setTimeout(() => {
334
- captureFirstFrame()
335
- }, 500)
336
- // })
337
- const captureFirstFrame = () => {
338
- ctx1.drawImage(myVideo, 0, 0, w * dpr, h * dpr)
339
- wx.canvasToTempFilePath({
340
- canvas: res[0].node,
341
- success: (result) => {
342
- console.log('First frame image path:', result
343
- .tempFilePath)
344
- // Now you can use the image path (result.tempFilePath)
345
- this.fileList['currentItemIndex'].thumb = result.tempFilePath
346
- },
347
- fail: (err) => {
348
- console.error('Failed to export image:', err)
349
- }
350
- })
351
- }
352
-
353
- // Capture the first frame
354
- setInterval(() => {
355
- ctx1.drawImage(myVideo, 0, 0, w * dpr, h * dpr);
356
- }, 1000 / 24)
357
- }).exec()
332
+ this.videoThumbCanvasWidth = w
333
+ this.videoThumbCanvasHeight = h
334
+ this.$nextTick(async () => {
335
+ const canvas = this.$refs.videoThumbCanvas
336
+ if (!canvas || !myVideo) return
337
+ await canvas.initCanvas(true)
338
+ const ctx1 = canvas.getRawContext()
339
+ if (!ctx1) return
340
+ setTimeout(async () => {
341
+ try {
342
+ ctx1.drawImage(myVideo, 0, 0, w, h)
343
+ const result = await canvas.toTempFilePath({
344
+ width: w,
345
+ height: h,
346
+ destWidth: w * dpr,
347
+ destHeight: h * dpr
348
+ })
349
+ console.log('First frame image path:', result.tempFilePath)
350
+ this.fileList[this.currentItemIndex].thumb = result.tempFilePath
351
+ this.$emit('update:fileList', this.fileList)
352
+ } catch (err) {
353
+ console.error('Failed to export image:', err)
354
+ }
355
+ }, 500)
356
+ })
358
357
  }).exec()
359
358
  },
360
359
  formatFileList() {
@@ -822,6 +821,14 @@
822
821
  }
823
822
  }
824
823
  }
824
+
825
+ &__hidden-canvas {
826
+ position: fixed;
827
+ top: -10000px;
828
+ left: -10000px;
829
+ z-index: -1;
830
+ }
831
+
825
832
  &__wrap__play {
826
833
  position: absolute;
827
834
  top: 0px;
@@ -247,59 +247,58 @@
247
247
 
248
248
  // 分配新数据到最短的列
249
249
  for (let item of newData) {
250
- const minHeightIndex = columnHeights.indexOf(Math.min(...columnHeights));
251
- // console.log('this.columnList', this.columnList)
252
- this.columnList[minHeightIndex].push(item);
253
-
254
- // 获取实际渲染后的元素高度而不是估算
255
- await sleep(this.addTime)
256
- await this.$nextTick(async () => {
257
- try {
258
- const rect = await this.$uGetRect(`#u-column-${minHeightIndex}`);
259
- // console.log(`#u-column-${minHeightIndex}`, rect.height)
260
- if (rect.height) {
261
- columnHeights[minHeightIndex] = rect.height;
262
- // 加载一个后置事件
263
- this.$emit('after-add-one', {
264
- ...item,
265
- height: rect.height
266
- });
267
- }
268
- } catch (e) {
269
- // console.log(e)
270
- // columnHeights[i] = 0;
271
- }
272
- });
273
- // this.$nextTick(async () => {
274
- // try {
275
- // // 等待DOM更新后获取实际高度
276
- // const lastIndex = this.columnList[minHeightIndex].length - 1;
277
- // const el = this.$refs[`u-column-${minHeightIndex}`][0].children[lastIndex];
278
- // if (el) {
279
- // const rect = await this.$uGetRect(el);
280
- // const actualHeight = rect.height || 100;
281
- // columnHeights[minHeightIndex] += actualHeight;
282
- // } else {
283
- // // 备用方案:如果无法获取实际高度,则使用默认值
284
- // columnHeights[minHeightIndex] += 100;
285
- // }
286
- // } catch (e) {
287
- // // 出错时使用默认高度
288
- // console.log(e)
289
- // columnHeights[minHeightIndex] += 100;
290
- // }
291
- // });
292
- }
250
+ const minHeightIndex = this.getMinHeightColumnIndex(columnHeights);
251
+ // console.log('this.columnList', this.columnList)
252
+ this.columnList[minHeightIndex].push(item);
253
+
254
+ // 获取实际渲染后的元素高度而不是估算
255
+ await sleep(this.addTime);
256
+ await this.$nextTick();
257
+ try {
258
+ const rect = await this.$uGetRect(`#u-column-${minHeightIndex}`);
259
+ // console.log(`#u-column-${minHeightIndex}`, rect.height)
260
+ if (rect.height) {
261
+ columnHeights[minHeightIndex] = rect.height;
262
+ // 加载一个后置事件
263
+ this.$emit('after-add-one', {
264
+ ...item,
265
+ height: rect.height
266
+ });
267
+ }
268
+ } catch (e) {
269
+ // console.log(e)
270
+ // columnHeights[i] = 0;
271
+ }
272
+ }
293
273
  // 加载所有后置事件
294
274
  this.$emit('after-add-all', {
295
275
  columnHeights: columnHeights,
296
- newData: newData
297
- });
298
- },
299
-
300
- // 复制而不是引用对象和数组
301
- cloneData(data) {
302
- return JSON.parse(JSON.stringify(data));
276
+ newData: newData
277
+ });
278
+ },
279
+
280
+ // 获取最短列;高度相同或暂不可测时按列数据量打散,避免全部落到第一列
281
+ getMinHeightColumnIndex(columnHeights) {
282
+ let minIndex = 0;
283
+ for (let i = 1; i < columnHeights.length; i++) {
284
+ const currentHeight = Number(columnHeights[i]) || 0;
285
+ const minHeight = Number(columnHeights[minIndex]) || 0;
286
+ if (currentHeight < minHeight) {
287
+ minIndex = i;
288
+ } else if (currentHeight === minHeight) {
289
+ const currentLength = this.columnList[i] ? this.columnList[i].length : 0;
290
+ const minLength = this.columnList[minIndex] ? this.columnList[minIndex].length : 0;
291
+ if (currentLength < minLength) {
292
+ minIndex = i;
293
+ }
294
+ }
295
+ }
296
+ return minIndex;
297
+ },
298
+
299
+ // 复制而不是引用对象和数组
300
+ cloneData(data) {
301
+ return JSON.parse(JSON.stringify(data));
303
302
  },
304
303
 
305
304
  // 清空数据列表
@@ -413,4 +412,4 @@
413
412
  max-width: 100%;
414
413
  /* #endif */
415
414
  }
416
- </style>
415
+ </style>