feat(uploader): add media media-type props support (#5113)

* feat(uploader): add media media-type props support

* docs(uploader): fix media-type props example error
This commit is contained in:
landluck 2022-11-28 20:36:44 +08:00 committed by GitHub
parent 09360b2df3
commit 56cc44f60e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 5 deletions

View File

@ -226,7 +226,7 @@ uploadFilePromise(fileName, chooseResult) {
| --- | --- | --- | --- |
| name | 标识符,可以在回调函数的第二项参数中获取 | _string \| number_ | - |
| accept | 接受的文件类型, 可选值为`all` `media` `image` `file` `video` | _string_ | `image` |
| sizeType | 所选的图片的尺寸, 当`accept``image`类型时设置所选图片的尺寸可选值为`original` `compressed` | _string[]_ | `['original','compressed']` |
| sizeType | 所选的图片的尺寸, 当`accept``image` \| `media` 类型时设置所选图片的尺寸可选值为`original` `compressed` | _string[]_ | `['original','compressed']` |
| preview-size | 预览图和上传区域的尺寸,默认单位为`px` | _string \| number_ | `80px` |
| preview-image | 是否在上传完成后展示预览图 | _boolean_ | `true` |
| preview-full-image | 是否在点击预览图后展示全屏图片预览 | _boolean_ | `true` |
@ -234,15 +234,16 @@ uploadFilePromise(fileName, chooseResult) {
| disabled | 是否禁用文件上传 | _boolean_ | `false` |
| show-upload | 是否展示文件上传按钮 | _boolean_ | `true` |
| deletable | 是否展示删除按钮 | _boolean_ | `true` |
| capture | 图片或者视频选取模式,当`accept``image`类型时设置`capture`可选值为`camera`可以直接调起摄像头 | _string \| string[]_ | `['album', 'camera']` |
| capture | 图片或者视频选取模式,当`accept``image` \| `media` 类型时设置`capture`可选值为`camera`可以直接调起摄像头 | _string[]_ | `['album', 'camera']` |
| max-size | 文件大小限制,单位为`byte` | _number_ | - |
| max-count | 文件上传数量限制 | _number_ | - |
| upload-text | 上传区域文字提示 | _string_ | - |
| image-fit | 预览图裁剪模式,可选值参考小程序`image`组件的`mode`属性 | _string_ | `scaleToFill` |
| use-before-read | 是否开启文件读取前事件 | _boolean_ | - |
| camera | 当 accept 为 `video` 时生效,可选值为 `back` `front` | _string_ | - |
| camera | 当 accept 为 `video` \| `media` 时生效,可选值为 `back` `front` | _string_ | - |
| compressed | 当 accept 为 `video` 时生效,是否压缩视频,默认为`true` | _boolean_ | - |
| max-duration | 当 accept 为 `video` 时生效,拍摄视频最长拍摄时间,单位秒 | _number_ | - |
| max-duration | 当 accept 为 `video` \| `media` 时生效,拍摄视频最长拍摄时间,单位秒 | _number_ | `60` |
| media-type `v1.10.8` | 当 accept 为 `media` 时生效,选择的文件的文件类型,可选值为 `image` `video` | _string[]_ | `['image', 'video']` |
| upload-icon | 上传区域图标,可选值见 [Icon 组件](#/icon) | _string_ | `plus` |
#### accept 的合法值

View File

@ -1,6 +1,6 @@
import { VantComponent } from '../common/component';
import { isImageFile, chooseFile, isVideoFile, File } from './utils';
import { chooseImageProps, chooseVideoProps } from './shared';
import { chooseImageProps, chooseVideoProps, chooseMediaProps } from './shared';
import { isBoolean, isPromise } from '../common/validator';
VantComponent({
@ -62,6 +62,7 @@ VantComponent({
},
...chooseImageProps,
...chooseVideoProps,
...chooseMediaProps,
},
data: {

View File

@ -29,3 +29,23 @@ export const chooseVideoProps = {
value: 'back',
},
};
// props for choose media
export const chooseMediaProps = {
capture: {
type: Array,
value: ['album', 'camera'],
},
mediaType: {
type: Array,
value: ['image', 'video'],
},
maxDuration: {
type: Number,
value: 60,
},
camera: {
type: String,
value: 'back',
},
};

View File

@ -95,6 +95,7 @@ export function chooseFile({
sizeType,
camera,
maxCount,
mediaType,
}) {
return new Promise<File | File[]>((resolve, reject) => {
switch (accept) {
@ -110,6 +111,7 @@ export function chooseFile({
case 'media':
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType,
sourceType: capture,
maxDuration,
sizeType,