Skip to content

Commit

Permalink
feat(uploader): add extension property support
Browse files Browse the repository at this point in the history
  • Loading branch information
landluck committed Dec 29, 2022
1 parent bcafa2b commit a80767e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/uploader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 的合法值
Expand Down
8 changes: 7 additions & 1 deletion packages/uploader/index.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -63,6 +68,7 @@ VantComponent({
...chooseImageProps,
...chooseVideoProps,
...chooseMediaProps,
...chooseMessageFileProps,
},

data: {
Expand Down
5 changes: 5 additions & 0 deletions packages/uploader/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ export const chooseMediaProps = {
value: 'back',
},
};

// props for choose file
export const chooseMessageFileProps = {
extension: null,
};
2 changes: 2 additions & 0 deletions packages/uploader/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function chooseFile({
camera,
maxCount,
mediaType,
extension,
}) {
return new Promise<File | File[]>((resolve, reject) => {
switch (accept) {
Expand Down Expand Up @@ -134,6 +135,7 @@ export function chooseFile({
wx.chooseMessageFile({
count: multiple ? maxCount : 1,
type: accept,
...(extension ? { extension } : {}),
success: (res) => resolve(formatFile(res)),
fail: reject,
});
Expand Down

0 comments on commit a80767e

Please sign in to comment.