mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] Uploader: support isImage flag (#4072)
This commit is contained in:
parent
b004ae11c0
commit
c012b29a20
@ -42,7 +42,10 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
fileList: [
|
||||
{ url: 'https://img.yzcdn.cn/vant/cat.jpeg' }
|
||||
{ url: 'https://img.yzcdn.cn/vant/cat.jpeg' },
|
||||
// Uploader 根据文件后缀来判断是否为图片文件
|
||||
// 如果图片 URL 中不包含类型信息,可以添加 isImage 标记来声明
|
||||
{ url: 'https://cloud-image', isImage: true }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ test('isImageFile', () => {
|
||||
expect(isImageFile({ file: { type: 'application/pdf' } })).toBeFalsy();
|
||||
expect(isImageFile({ content: 'data:image/xxx' })).toBeTruthy();
|
||||
expect(isImageFile({ content: 'data:application/xxx' })).toBeFalsy();
|
||||
expect(isImageFile({ isImage: true })).toBeTruthy();
|
||||
expect(isImageFile({})).toBeFalsy();
|
||||
});
|
||||
|
@ -30,6 +30,7 @@ export type FileListItem = {
|
||||
url?: string;
|
||||
file?: File;
|
||||
content?: string; // dataUrl
|
||||
isImage?: boolean;
|
||||
};
|
||||
|
||||
const IMAGE_EXT = ['jpeg', 'jpg', 'gif', 'png', 'svg'];
|
||||
@ -39,6 +40,12 @@ export function isImageUrl(url: string): boolean {
|
||||
}
|
||||
|
||||
export function isImageFile(item: FileListItem): boolean {
|
||||
// some special urls cannot be recognized
|
||||
// user can add `isImage` flag to mark it as an image url
|
||||
if (item.isImage) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.file && item.file.type) {
|
||||
return item.file.type.indexOf('image') === 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user