stellar-ui-v2 1.35.3

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 (141) hide show
  1. package/common/css/common.scss +61 -0
  2. package/components/ste-animate/README.md +117 -0
  3. package/components/ste-animate/animate.scss +247 -0
  4. package/components/ste-animate/ste-animate.vue +200 -0
  5. package/components/ste-badge/README.md +171 -0
  6. package/components/ste-badge/ste-badge.vue +238 -0
  7. package/components/ste-barcode/README.md +36 -0
  8. package/components/ste-barcode/encode2.js +317 -0
  9. package/components/ste-barcode/ste-barcode.vue +213 -0
  10. package/components/ste-button/README.md +129 -0
  11. package/components/ste-button/ste-button.vue +345 -0
  12. package/components/ste-calendar/README.md +304 -0
  13. package/components/ste-calendar/self-date.js +119 -0
  14. package/components/ste-calendar/ste-calendar.vue +578 -0
  15. package/components/ste-checkbox/README.md +297 -0
  16. package/components/ste-checkbox/ste-checkbox.vue +305 -0
  17. package/components/ste-checkbox-group/ste-checkbox-group.vue +133 -0
  18. package/components/ste-code-input/README.md +67 -0
  19. package/components/ste-code-input/ste-code-input.vue +302 -0
  20. package/components/ste-date-picker/README.md +135 -0
  21. package/components/ste-date-picker/ste-date-picker.vue +407 -0
  22. package/components/ste-drag/README.md +103 -0
  23. package/components/ste-drag/ste-drag.vue +203 -0
  24. package/components/ste-dropdown-menu/README.md +358 -0
  25. package/components/ste-dropdown-menu/ste-dropdown-menu.vue +405 -0
  26. package/components/ste-dropdown-menu-item/ste-dropdown-menu-item.vue +176 -0
  27. package/components/ste-icon/README.md +90 -0
  28. package/components/ste-icon/iconfont.css +8 -0
  29. package/components/ste-icon/ste-icon.vue +147 -0
  30. package/components/ste-image/README.md +154 -0
  31. package/components/ste-image/ste-image.vue +218 -0
  32. package/components/ste-index-item/ste-index-item.vue +96 -0
  33. package/components/ste-index-list/README.md +153 -0
  34. package/components/ste-index-list/ste-index-list.vue +128 -0
  35. package/components/ste-input/README.md +146 -0
  36. package/components/ste-input/ste-input.vue +480 -0
  37. package/components/ste-loading/README.md +81 -0
  38. package/components/ste-loading/ste-loading.vue +166 -0
  39. package/components/ste-media-preview/README.md +243 -0
  40. package/components/ste-media-preview/TouchScaleing.js +102 -0
  41. package/components/ste-media-preview/ste-media-preview.vue +267 -0
  42. package/components/ste-message-box/README.md +217 -0
  43. package/components/ste-message-box/ste-message-box.js +72 -0
  44. package/components/ste-message-box/ste-message-box.vue +380 -0
  45. package/components/ste-notice-bar/README.md +129 -0
  46. package/components/ste-notice-bar/ste-notice-bar.vue +331 -0
  47. package/components/ste-number-keyboard/README.md +246 -0
  48. package/components/ste-number-keyboard/keyboard.vue +140 -0
  49. package/components/ste-number-keyboard/ste-number-keyboard.vue +240 -0
  50. package/components/ste-picker/ste-picker.vue +258 -0
  51. package/components/ste-popup/README.md +148 -0
  52. package/components/ste-popup/ste-popup.vue +337 -0
  53. package/components/ste-price/README.md +129 -0
  54. package/components/ste-price/ste-price.vue +258 -0
  55. package/components/ste-progress/README.md +87 -0
  56. package/components/ste-progress/ste-progress.vue +200 -0
  57. package/components/ste-qrcode/README.md +50 -0
  58. package/components/ste-qrcode/ste-qrcode.vue +164 -0
  59. package/components/ste-qrcode/uqrcode.js +34 -0
  60. package/components/ste-radio/README.md +286 -0
  61. package/components/ste-radio/ste-radio.vue +293 -0
  62. package/components/ste-radio-group/ste-radio-group.vue +128 -0
  63. package/components/ste-rate/README.md +115 -0
  64. package/components/ste-rate/ste-rate.vue +202 -0
  65. package/components/ste-read-more/README.md +111 -0
  66. package/components/ste-read-more/ste-read-more.vue +133 -0
  67. package/components/ste-rich-text/README.md +31 -0
  68. package/components/ste-rich-text/ste-rich-text.vue +70 -0
  69. package/components/ste-scroll-to/README.md +68 -0
  70. package/components/ste-scroll-to/mixin.js +173 -0
  71. package/components/ste-scroll-to/ste-scroll-to.vue +45 -0
  72. package/components/ste-scroll-to-item/ste-scroll-to-item.vue +25 -0
  73. package/components/ste-search/README.md +262 -0
  74. package/components/ste-search/ste-search.vue +547 -0
  75. package/components/ste-select/README.md +434 -0
  76. package/components/ste-select/datapager.vue +62 -0
  77. package/components/ste-select/datetime.vue +106 -0
  78. package/components/ste-select/defaultDate.js +142 -0
  79. package/components/ste-select/ste-select.vue +843 -0
  80. package/components/ste-signature/README.md +105 -0
  81. package/components/ste-signature/ste-signature.vue +220 -0
  82. package/components/ste-slider/README.md +165 -0
  83. package/components/ste-slider/ste-slider.vue +544 -0
  84. package/components/ste-step/ste-step.vue +264 -0
  85. package/components/ste-stepper/README.md +170 -0
  86. package/components/ste-stepper/ste-stepper.vue +373 -0
  87. package/components/ste-steps/README.md +132 -0
  88. package/components/ste-steps/ste-steps.vue +65 -0
  89. package/components/ste-sticky/README.md +52 -0
  90. package/components/ste-sticky/ste-sticky.vue +127 -0
  91. package/components/ste-swipe-action/README.md +197 -0
  92. package/components/ste-swipe-action/ste-swipe-action.vue +303 -0
  93. package/components/ste-swipe-action-group/ste-swipe-action-group.vue +104 -0
  94. package/components/ste-swiper/README.md +173 -0
  95. package/components/ste-swiper/ste-swiper.vue +462 -0
  96. package/components/ste-swiper-item/ste-swiper-item.vue +41 -0
  97. package/components/ste-switch/README.md +110 -0
  98. package/components/ste-switch/ste-switch.vue +144 -0
  99. package/components/ste-tab/ste-tab.vue +87 -0
  100. package/components/ste-table/README.md +785 -0
  101. package/components/ste-table/common.js +8 -0
  102. package/components/ste-table/ste-table.vue +666 -0
  103. package/components/ste-table/utils.js +20 -0
  104. package/components/ste-table-column/checkbox-icon.vue +65 -0
  105. package/components/ste-table-column/common.scss +65 -0
  106. package/components/ste-table-column/radio-icon.vue +110 -0
  107. package/components/ste-table-column/ste-table-column.vue +255 -0
  108. package/components/ste-table-column/sub-table.vue +116 -0
  109. package/components/ste-table-column/table-popover.vue +204 -0
  110. package/components/ste-table-column/var.scss +1 -0
  111. package/components/ste-tabs/README.md +475 -0
  112. package/components/ste-tabs/props.js +212 -0
  113. package/components/ste-tabs/ste-tabs.vue +758 -0
  114. package/components/ste-text/README.md +66 -0
  115. package/components/ste-text/ste-text.vue +72 -0
  116. package/components/ste-toast/README.md +243 -0
  117. package/components/ste-toast/ste-toast.js +69 -0
  118. package/components/ste-toast/ste-toast.vue +231 -0
  119. package/components/ste-touch-swipe/README.md +104 -0
  120. package/components/ste-touch-swipe/TouchEvent.js +72 -0
  121. package/components/ste-touch-swipe/ste-touch-swipe.vue +327 -0
  122. package/components/ste-touch-swipe-item/ste-touch-swipe-item.vue +33 -0
  123. package/components/ste-tour/README.md +194 -0
  124. package/components/ste-tour/ste-tour.vue +355 -0
  125. package/components/ste-tree/README.md +240 -0
  126. package/components/ste-tree/ste-tree.vue +350 -0
  127. package/components/ste-upload/README.md +276 -0
  128. package/components/ste-upload/ReadFile.js +229 -0
  129. package/components/ste-upload/ste-upload.vue +526 -0
  130. package/components/ste-video/README.md +60 -0
  131. package/components/ste-video/props.js +149 -0
  132. package/components/ste-video/ste-video.vue +647 -0
  133. package/config/color.js +22 -0
  134. package/index.js +2 -0
  135. package/package.json +19 -0
  136. package/utils/Color.js +66 -0
  137. package/utils/System.js +110 -0
  138. package/utils/dayjs.min.js +1 -0
  139. package/utils/mixin.js +67 -0
  140. package/utils/store.js +7 -0
  141. package/utils/utils.js +604 -0
@@ -0,0 +1,276 @@
1
+ # Upload 上传
2
+ 支持图片上传、视频上传、其他文件上传(仅微信小程序和H5)。
3
+
4
+ ---$
5
+
6
+
7
+ #### 基础用法
8
+ - `v-model`双向绑定接收一个对象数组,对象包含以下属性
9
+ - `url`:文件路径(与path二选一必须)
10
+ - `path`:本地文件路径(与url二选一必须)
11
+ - `name`:文件名(可选)
12
+ - `type`:文件类型;可选值为`video`、`image`、`file`(可选)
13
+ - `size`:文件大小(可选)
14
+ - `status`:文件上传状态;可选值为`uploading`、`error`、`success`(可选,默认为`success`)
15
+ - `thumbPath`:视频首帧图片(类型为`video`时必需)
16
+ - `width`:视频宽度(可选)
17
+ - `height`:视频高度(可选)
18
+ - `duration`:视频时长(可选)
19
+ - `@read`事件在文件读取完成后调用,回调参数为选取到的文件对象列表,对象包含以下属性
20
+ - `path`:本地文件路径
21
+ - `name`:文件名称(小程序都是`null`)
22
+ - `type`:文件类型
23
+ - `size`:文件大小
24
+ - `thumbPath`:视频首帧图片(类型为`video`时提供)
25
+ - `width`:视频宽度(类型为`video`时提供)
26
+ - `height`:视频高度(类型为`video`时提供)
27
+ - `duration`:视频时长(类型为`video`时提供)
28
+ - `file`:当前文件对象(H5平台专属)
29
+
30
+
31
+ ```html
32
+ <ste-upload v-model="fileList" @read="onRead" />
33
+
34
+ <script>
35
+ export default {
36
+ data() {
37
+ return {
38
+ fileList: [],
39
+ };
40
+ },
41
+ methods: {
42
+ onRead(fileList) {
43
+ setTimeout(() => {
44
+ fileList.forEach((item) => {
45
+ if (Math.random() > 0.5) {
46
+ item.status = 'success';
47
+ } else {
48
+ item.status = 'error';
49
+ }
50
+ });
51
+ }, 1000);
52
+ },
53
+ }
54
+ };
55
+ </script>
56
+ ```
57
+
58
+
59
+ #### 文件类型,多选
60
+ - `accept`属性可以设置选择文件类型:可选值有
61
+ - `image`:图片类型(默认)
62
+ - `video`:视频类型
63
+ - `media`:视频和图片类型(支付宝需手动切换)
64
+ - `all`:所有类型(微信小程序和H5可用)
65
+ - `file`:除了图片和视频之外的其他类型(仅微信小程序可用)
66
+
67
+
68
+ ```html
69
+ <ste-upload v-model="fileList1" @read="onRead1" accept="media" multiple />
70
+
71
+ <script>
72
+ export default {
73
+ data() {
74
+ return {
75
+ fileList1: [],
76
+ };
77
+ },
78
+ methods: {
79
+ onRead1(fileList) {
80
+ setTimeout(() => {
81
+ fileList.forEach((item) => {
82
+ item.status = 'success';
83
+ });
84
+ }, 1000);
85
+ },
86
+ }
87
+ };
88
+ </script>
89
+ ```
90
+
91
+ #### 限制上传数量
92
+ - `maxCount`属性可以设置最大上传数量,超出数量后,无法继续选择文件
93
+ ```html
94
+ <ste-upload v-model="fileList2" :maxCount="2" />
95
+
96
+ <script>
97
+ export default {
98
+ data() {
99
+ return {
100
+ fileList2: [],
101
+ };
102
+ },
103
+ watch: {
104
+ fileList2(fileList) {
105
+ setTimeout(() => {
106
+ fileList.forEach((item) => {
107
+ item.status = 'success';
108
+ });
109
+ }, 1000);
110
+ },
111
+ }
112
+ };
113
+ </script>
114
+ ```
115
+ #### 限制文件大小
116
+ - `maxSize`属性可以设置可上传文件的大小,超出大小无法选择
117
+ ```html
118
+ <ste-upload v-model="fileList3" :maxSize="2048" />
119
+ ```
120
+ #### 自定义上传样式
121
+ - 默认插槽可自定义上传按钮样式
122
+ ```html
123
+ <ste-upload v-model="fileList4">
124
+ <button type="primary" size="mini" style="padding: 0 10px">上传文件</button>
125
+ </ste-upload>
126
+ ```
127
+ #### 自定义预览图层
128
+ - 具名插槽`preview-cover`可自定义每一份文件的预览图层样式
129
+ ```html
130
+ <ste-upload v-model="fileList5">
131
+ <template v-slot:preview-cover="{ item }">
132
+ <view class="item-preview">size:{{ item.size }}b</view>
133
+ </template>
134
+ </ste-upload>
135
+ <style>
136
+ .item-preview {
137
+ position: absolute;
138
+ z-index: 10;
139
+ bottom: 0;
140
+ left: 0;
141
+ width: 100%;
142
+ text-align: center;
143
+ background-color: rgba(0, 0, 0, 0.5);
144
+ color: #fff;
145
+ }
146
+ </style>
147
+ ```
148
+
149
+ #### 读取文件前置处理
150
+ - 事件`beforeRead`在文件选择前触发,参数如下:
151
+ - 第一个参数为正在读取的`fileList`
152
+ - 第二个参数是回调函数`suspend`,调用暂停读取
153
+ - 第三个参数是回调函数`next`,调用继续读取
154
+ - 第四个参数是回调函数`stop`,调用阻止读取
155
+ -
156
+ ```html
157
+ <ste-upload @beforeRead="beforeRead" @read="onSuccessRead"></ste-upload>
158
+
159
+ <script>
160
+ export default{
161
+ methods:{
162
+ beforeRead(fileList, suspend, next, stop) {
163
+ suspend();
164
+ this.showToast({ title: 'suspend-read', icon: 'none' });
165
+ setTimeout(() => {
166
+ next();
167
+ }, 2000);
168
+ },
169
+ onSuccessRead(fileList) {
170
+ this.showToast({ title: 'success-read', icon: 'none' });
171
+ },
172
+ }
173
+ }
174
+ </script>
175
+ ```
176
+
177
+ #### 删除前置处理
178
+ - 事件`beforeDelete`在文件选择前触发,参数如下:
179
+ - 第一个参数为正在删除的`index`
180
+ - 第二个参数是回调函数`suspend`,调用暂停删除
181
+ - 第三个参数是回调函数`next`,调用继续删除
182
+ - 第四个参数是回调函数`stop`,调用阻止删除
183
+ ```html
184
+ <ste-upload v-model="fileList6" @beforeDelete="beforeDelete" @delete="onSuccessDelete"></ste-upload>
185
+
186
+ <script>
187
+ export default{
188
+ watch:{
189
+ fileList6(v) {
190
+ setTimeout(() => {
191
+ v.forEach((item) => {
192
+ item.status = 'success';
193
+ });
194
+ }, 1000);
195
+ },
196
+ },
197
+ methods:{
198
+ beforeDelete(index, suspend, next, stop) {
199
+ suspend();
200
+ this.showToast({ title: 'suspend-delete', icon: 'none' });
201
+ setTimeout(() => {
202
+ next();
203
+ }, 2000);
204
+ },
205
+ onSuccessDelete(index, fileList) {
206
+ this.showToast({ title: 'success-delete', icon: 'none' });
207
+ },
208
+ }
209
+ }
210
+ </script>
211
+
212
+ ```
213
+
214
+
215
+ ---$
216
+ ### API
217
+ ### Props
218
+
219
+ | 参数 | 说明 | 类型 | 默认值 | 可选值 |
220
+ | -- | -- | -- | -- | -- |
221
+ | `v-model` | 已经上传的文件列表,`File`类型见下方说明 | `Array<File>` | `[]` | - |
222
+ | `accept` | 文件类型 | `String` | `'image'` | 见下方说明 |
223
+ | `capture` | 图片或者视频选取模式,当`accept`为`image`/`video`/`media`类型时生效 | `Array<"album"/"camera">` | `['album', 'camera']` | - |
224
+ | `camera` | 相机类型 当 `accept` 为 `image` / `video` / `media` 时生效 | `String` | `back` | `back`:后置<br/>`front`:前置 |
225
+ | `compressed` | 当 `accept` 为 `image` / `video` / `media` 时生效,是否压缩视频 | `String` | `true` | - |
226
+ | `maxDuration` | 当 `accept` 为 `video`/ `media` 时生效,拍摄视频最长拍摄时间,单位秒 | `Number` | `60` | - |
227
+ | `previewWidth` | 预览图和上传区域的宽度,单位为rpx | `String`/`Number` | `200` | - |
228
+ | `previewHeight` | 预览图和上传区域的高度,单位为rpx | `String`/`Number` | `200` | - |
229
+ | `previewImage` | 是否在选择完成后展示预览图 | `Boolean` | `true` | - |
230
+ | `previewFullImage`| 是否在点击预览图后展示全屏图片预览 | `Boolean` | `true` | - |
231
+ | `multiple` | 是否支持多选文件,部分安卓机型不支持 | `Boolean` | `false` | - |
232
+ | `disabled` | 是否禁用 | `Boolean` | `false` | - |
233
+ | `showUpload` | 是否展示文件上传按钮 | `Boolean` | `true` | - |
234
+ | `deletable` | 是否展示删除文件按钮 | `Boolean` | `true` | - |
235
+ | `maxSize` | 文件大小限制,单位为kb,0为不限制 | `Number` | `0` | - |
236
+ | `maxCount` | 最大上传文件数量 | `Number` | `9` | - |
237
+ | `uploadIcon` | 上传按钮图标,同`icon`组件`code` | `String` | `'&#xe69b;'` | - |
238
+ | `uploadText` | 上传按钮文字 | `String` | `'点击上传'` | - |
239
+ | `radius` | 圆角弧度,单位为rpx | `String`/`Number` | `9` | - |
240
+ | `flexWrap` | 超出内容是否换行 | `String` | `wrap` | 同css的`flex-wrap` |
241
+
242
+ #### File对象
243
+ | Key | 类型 | 说明 | 可选值 |
244
+ | -- | -- | -- | -- |
245
+ | `url` | `String`| 文件URL |- |
246
+ | `type` | `String`| 文件类型 |- |
247
+ | `name` | `String`| 文件名称 |- |
248
+ | `status` | `String`| 文件状态 |`'uploading'`/`'error'`/`'success'`|
249
+ | `path` | `String`| 文件本地路径(小程序选择时的本地路径),在没有URL时展示此字段 |- |
250
+ | `thumbPath` | `String`| 视频类型文件的首帧图片地址 |- |
251
+
252
+ #### accept 可选可选值值
253
+ | 可选值 | 说明 |
254
+ | -- | -- |
255
+ | `'image'` | 图片(默认) |
256
+ | `'video'` | 视频类型 |
257
+ | `'media'` | 媒体类型(可选择图片和视频) |
258
+ | `'file'` | 从聊天记录中选取图片视频之外的文件类型(仅微信小程序生效) |
259
+ | `'all'` | 选取全部类型文件(微信小程序从聊天记录中选取,支付宝不生效) |
260
+
261
+
262
+ ### Event
263
+
264
+ | 事件名 | 说明 | 事件参数 |
265
+ | -------- | ------------ | ------------- |
266
+ | `beforeRead` | 文件读取前触发 | 上方详细说明 |
267
+ | `read` | 文件读完成触发 | `fileList`:选择的文件列表 |
268
+ | `oversize` | 文件大小超出限制触发 | `file`:超出限制的第一个文件,`fileList`:选择的文件列表 |
269
+ | `beforeDelete` | 文件删除前触发 | 上方详细说明 |
270
+ | `delete` | 文件删除后触发 | `index`:删除的文件下标,`fileList`:剩余文件列表 |
271
+ | `open-preview` | 打开预览时触发 | - |
272
+ | `close-preview` | 关闭预览时触发 | - |
273
+
274
+
275
+ ---$
276
+ {{xuyajun}}
@@ -0,0 +1,229 @@
1
+ /**
2
+ * @type {{accept: "image" | "video";capture:("album" | "camera")[];camera:"back" | "front";compressed:boolean;maxDuration:number;multiple:boolean;count:number;}}
3
+ */
4
+ const _options = {
5
+ accept: 'image',
6
+ capture: ['album', 'camera'],
7
+ camera: 'back',
8
+ compressed: true,
9
+ maxDuration: 60,
10
+ multiple: false,
11
+ count: 9,
12
+ };
13
+
14
+ /**
15
+ * 读取本地媒体文件
16
+ * @param {{accept: "image" | "video" | "media";capture:("album" | "camera")[];camera:"back" | "front";compressed:boolean;maxDuration:number;multiple:boolean;count:number;}} options 参数
17
+ * @returns {Promise<{path:string;name:string;type:string;size:number;height?:number;width?:number;thumbPath?:string}[]>}
18
+ */
19
+ export function readMediaFile(options = {}) {
20
+ const { accept, capture, camera, compressed, maxDuration, multiple, count } = Object.assign(_options, options);
21
+ return new Promise((resolve, reject) => {
22
+ if (count < 1) {
23
+ reject('count不能小于1');
24
+ return;
25
+ }
26
+ // #ifdef MP-WEIXIN
27
+ wx.chooseMedia({
28
+ count,
29
+ mediaType: [accept],
30
+ sourceType: capture,
31
+ camera: camera,
32
+ sizeType: [compressed ? 'compressed' : 'original'],
33
+ maxDuration,
34
+ success(res) {
35
+ const tempFiles = res.tempFiles;
36
+ const result = tempFiles.map((item) => {
37
+ const m = {
38
+ name: null,
39
+ size: item.size,
40
+ path: item.tempFilePath,
41
+ type: res.type,
42
+ };
43
+ if (m.type === 'video') {
44
+ m.duration = item.duration;
45
+ m.height = item.height;
46
+ m.width = item.width;
47
+ m.thumbPath = item.thumbTempFilePath;
48
+ }
49
+ return m;
50
+ });
51
+ resolve(result);
52
+ },
53
+ fail: (err) => {
54
+ reject(err);
55
+ },
56
+ });
57
+ // #endif
58
+
59
+ // #ifdef MP-ALIPAY
60
+ if (accept === 'video') {
61
+ my.chooseVideo({
62
+ sourceType: capture,
63
+ camera,
64
+ compressed,
65
+ maxDuration,
66
+ success(e) {
67
+ resolve([
68
+ {
69
+ name: null,
70
+ size: e.size,
71
+ path: e.tempFilePath,
72
+ type: 'video',
73
+ duration: e.duration,
74
+ height: e.height,
75
+ width: e.width,
76
+ thumbPath: e.tempVideoThumbPath,
77
+ },
78
+ ]);
79
+ },
80
+ fail(err) {
81
+ reject(err);
82
+ },
83
+ });
84
+ } else {
85
+ aliReadImage({
86
+ count,
87
+ useFrontCamera: camera === 'front',
88
+ sizeType: [compressed ? 'compressed' : 'original'],
89
+ sourceType: capture,
90
+ })
91
+ .then((res) => resolve(res))
92
+ .catch((e) => reject(e));
93
+ }
94
+ // #endif
95
+
96
+ // #ifdef H5
97
+ h5ReadFile({
98
+ accept,
99
+ multiple,
100
+ })
101
+ .then((res) => resolve(res))
102
+ .catch((e) => reject(e));
103
+ // #endif
104
+ });
105
+ }
106
+
107
+ /**
108
+ * @param {"all" | "file"} accept
109
+ * @param {Number} count
110
+ */
111
+ export function readFile(accept = 'all', count = 9, multiple = false) {
112
+ return new Promise((resolve, reject) => {
113
+ if (count < 1) {
114
+ reject('count不能小于1');
115
+ return;
116
+ }
117
+ // #ifdef MP-WEIXIN
118
+ wx.chooseMessageFile({
119
+ type: accept,
120
+ count,
121
+ success: ({ tempFiles }) => {
122
+ resolve(tempFiles);
123
+ },
124
+ fail: (err) => {
125
+ reject(err);
126
+ },
127
+ });
128
+ // #endif
129
+ // #ifdef MP-ALIPAY
130
+ aliReadImage({
131
+ count,
132
+ })
133
+ .then((res) => resolve(res))
134
+ .catch((e) => reject(e));
135
+ // #endif
136
+ // #ifdef H5
137
+ h5ReadFile({
138
+ accept,
139
+ multiple,
140
+ })
141
+ .then((res) => resolve(res))
142
+ .catch((e) => reject(e));
143
+ // #endif
144
+ });
145
+ }
146
+
147
+ // #ifdef MP-ALIPAY
148
+ function aliReadImage({ count, useFrontCamera, sizeType, sourceType }) {
149
+ return new Promise((resolve, reject) => {
150
+ my.chooseImage({
151
+ count,
152
+ useFrontCamera,
153
+ sizeType,
154
+ sourceType,
155
+ success({ tempFiles }) {
156
+ const result = tempFiles.map((item) => {
157
+ return {
158
+ name: null,
159
+ path: item.path,
160
+ size: item.size,
161
+ type: 'image',
162
+ };
163
+ });
164
+ resolve(result);
165
+ },
166
+ fail(err) {
167
+ reject(err);
168
+ },
169
+ });
170
+ });
171
+ }
172
+ // #endif
173
+ // #ifdef H5
174
+ const h5FileType = {
175
+ all: '*',
176
+ file: '*',
177
+ image: '.PNG,.JPG,.WEBP,.SVG,.GIF',
178
+ video: '.mp4,.mov,.m4v,.3gp,.avi,.m3u8,.webm',
179
+ media: '.PNG,.JPG,.WEBP,.SVG,.GIF,.mp4,.mov,.m4v,.3gp,.avi,.m3u8,.webm',
180
+ };
181
+
182
+ function h5ReadFile({ accept = 'image', multiple = false }) {
183
+ return new Promise((resolve, reject) => {
184
+ let ipt = document.createElement('input');
185
+ ipt.style.display = 'none';
186
+ ipt.setAttribute('type', 'file');
187
+ if (multiple) {
188
+ ipt.setAttribute('multiple', multiple);
189
+ }
190
+ ipt.setAttribute('accept', h5FileType[accept]);
191
+ document.body.appendChild(ipt);
192
+ ipt.click();
193
+ });
194
+ }
195
+
196
+ /**
197
+ * 获取视频首帧
198
+ */
199
+ function getVideoFirstFrame(path) {
200
+ return new Promise((resolve, reject) => {
201
+ let video = document.createElement('video');
202
+ video.src = path;
203
+ video.onloadedmetadata = function () {
204
+ video.currentTime = 0.5;
205
+ video.addEventListener('canplay', function () {
206
+ video.pause();
207
+ const width = video.videoWidth,
208
+ height = video.videoHeight,
209
+ duration = video.duration;
210
+
211
+ setTimeout(() => {
212
+ let canvas = document.createElement('canvas');
213
+ canvas.width = width;
214
+ canvas.height = height;
215
+ canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
216
+ let thumbPath = canvas.toDataURL('image/png');
217
+ resolve({
218
+ thumbPath,
219
+ width,
220
+ height,
221
+ duration,
222
+ });
223
+ video = null;
224
+ }, 50);
225
+ });
226
+ };
227
+ });
228
+ }
229
+ // #endif