mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(uploader): add extension property support
This commit is contained in:
parent
bcafa2b894
commit
a80767e9c1
@ -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 的合法值
|
||||||
|
@ -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: {
|
||||||
|
@ -49,3 +49,8 @@ export const chooseMediaProps = {
|
|||||||
value: 'back',
|
value: 'back',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// props for choose file
|
||||||
|
export const chooseMessageFileProps = {
|
||||||
|
extension: null,
|
||||||
|
};
|
||||||
|
@ -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,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user