Merge pull request #5164 from landluck/feature/add_uploader_extension

feat(uploader): add extension property support
This commit is contained in:
landluck 2022-12-30 19:03:29 +08:00 committed by GitHub
commit 924d04b5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -244,6 +244,7 @@ uploadFilePromise(fileName, chooseResult) {
| compressed | 当 accept 为 `video` 时生效,是否压缩视频,默认为`true` | _boolean_ | - | | compressed | 当 accept 为 `video` 时生效,是否压缩视频,默认为`true` | _boolean_ | - |
| max-duration | 当 accept 为 `video` \| `media` 时生效,拍摄视频最长拍摄时间,单位秒 | _number_ | `60` | | max-duration | 当 accept 为 `video` \| `media` 时生效,拍摄视频最长拍摄时间,单位秒 | _number_ | `60` |
| media-type `v1.10.8` | 当 accept 为 `media` 时生效,选择的文件的文件类型,可选值为 `image` `video` | _string[]_ | `['image', 'video']` | | media-type `v1.10.8` | 当 accept 为 `media` 时生效,选择的文件的文件类型,可选值为 `image` `video` | _string[]_ | `['image', 'video']` |
| extension `v1.10.11` | 当 accept 为 `file` 时生效,根据文件拓展名过滤可选择文件。每一项都不能是空字符串。默认不过滤 | _string[] | undefined_ | - |
| upload-icon | 上传区域图标,可选值见 [Icon 组件](#/icon) | _string_ | `plus` | | upload-icon | 上传区域图标,可选值见 [Icon 组件](#/icon) | _string_ | `plus` |
#### accept 的合法值 #### accept 的合法值

View File

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

View File

@ -49,3 +49,8 @@ export const chooseMediaProps = {
value: 'back', value: 'back',
}, },
}; };
// props for choose file
export const chooseMessageFileProps = {
extension: null,
};

View File

@ -96,6 +96,7 @@ export function chooseFile({
camera, camera,
maxCount, maxCount,
mediaType, mediaType,
extension,
}) { }) {
return new Promise<File | File[]>((resolve, reject) => { return new Promise<File | File[]>((resolve, reject) => {
switch (accept) { switch (accept) {
@ -134,6 +135,7 @@ export function chooseFile({
wx.chooseMessageFile({ wx.chooseMessageFile({
count: multiple ? maxCount : 1, count: multiple ? maxCount : 1,
type: accept, type: accept,
...(extension ? { extension } : {}),
success: (res) => resolve(formatFile(res)), success: (res) => resolve(formatFile(res)),
fail: reject, fail: reject,
}); });