diff --git a/packages/uploader/README.md b/packages/uploader/README.md index e06cb60b..b60fc537 100644 --- a/packages/uploader/README.md +++ b/packages/uploader/README.md @@ -244,6 +244,7 @@ uploadFilePromise(fileName, chooseResult) { | compressed | 当 accept 为 `video` 时生效,是否压缩视频,默认为`true` | _boolean_ | - | | max-duration | 当 accept 为 `video` \| `media` 时生效,拍摄视频最长拍摄时间,单位秒 | _number_ | `60` | | 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` | #### accept 的合法值 diff --git a/packages/uploader/index.ts b/packages/uploader/index.ts index e5805cba..57019426 100644 --- a/packages/uploader/index.ts +++ b/packages/uploader/index.ts @@ -1,6 +1,11 @@ import { VantComponent } from '../common/component'; 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'; VantComponent({ @@ -63,6 +68,7 @@ VantComponent({ ...chooseImageProps, ...chooseVideoProps, ...chooseMediaProps, + ...chooseMessageFileProps, }, data: { diff --git a/packages/uploader/shared.ts b/packages/uploader/shared.ts index d6361fc9..23759f78 100644 --- a/packages/uploader/shared.ts +++ b/packages/uploader/shared.ts @@ -49,3 +49,8 @@ export const chooseMediaProps = { value: 'back', }, }; + +// props for choose file +export const chooseMessageFileProps = { + extension: null, +}; diff --git a/packages/uploader/utils.ts b/packages/uploader/utils.ts index eaedc718..c4a2678e 100644 --- a/packages/uploader/utils.ts +++ b/packages/uploader/utils.ts @@ -96,6 +96,7 @@ export function chooseFile({ camera, maxCount, mediaType, + extension, }) { return new Promise((resolve, reject) => { switch (accept) { @@ -134,6 +135,7 @@ export function chooseFile({ wx.chooseMessageFile({ count: multiple ? maxCount : 1, type: accept, + ...(extension ? { extension } : {}), success: (res) => resolve(formatFile(res)), fail: reject, });