mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-05 19:41:45 +08:00
Merge pull request #5164 from landluck/feature/add_uploader_extension
feat(uploader): add extension property support
This commit is contained in:
commit
924d04b5a3
@ -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 的合法值
|
||||
|
@ -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: {
|
||||
|
@ -49,3 +49,8 @@ export const chooseMediaProps = {
|
||||
value: 'back',
|
||||
},
|
||||
};
|
||||
|
||||
// props for choose file
|
||||
export const chooseMessageFileProps = {
|
||||
extension: null,
|
||||
};
|
||||
|
@ -96,6 +96,7 @@ export function chooseFile({
|
||||
camera,
|
||||
maxCount,
|
||||
mediaType,
|
||||
extension,
|
||||
}) {
|
||||
return new Promise<File | File[]>((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,
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user