mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 10:44:59 +00:00
[improvement] Uploader: support preview network image (#3899)
This commit is contained in:
@@ -26,6 +26,30 @@ export function isOversize(files: File | File[], maxSize: number): boolean {
|
||||
return toArray(files).some(file => file.size > maxSize);
|
||||
}
|
||||
|
||||
export function isImageDataUrl(dataUrl: string): boolean {
|
||||
return dataUrl.indexOf('data:image') === 0;
|
||||
export type FileListItem = {
|
||||
url?: string;
|
||||
file?: File;
|
||||
content?: string; // dataUrl
|
||||
};
|
||||
|
||||
const IMAGE_EXT = ['jpeg', 'jpg', 'gif', 'png', 'svg'];
|
||||
|
||||
export function isImageUrl(url: string): boolean {
|
||||
return IMAGE_EXT.some(ext => url.indexOf(`.${ext}`) !== -1);
|
||||
}
|
||||
|
||||
export function isImageFile(item: FileListItem): boolean {
|
||||
if (item.file && item.file.type) {
|
||||
return item.file.type.indexOf('image') === 0;
|
||||
}
|
||||
|
||||
if (item.url) {
|
||||
return isImageUrl(item.url);
|
||||
}
|
||||
|
||||
if (item.content) {
|
||||
return item.content.indexOf('data:image') === 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user