mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 03:11:15 +00:00
[improvement] Uploader: optimize code
This commit is contained in:
27
packages/uploader/utils.js
Normal file
27
packages/uploader/utils.js
Normal file
@@ -0,0 +1,27 @@
|
||||
export function toArray(item) {
|
||||
if (Array.isArray(item)) {
|
||||
return item;
|
||||
}
|
||||
|
||||
return [item];
|
||||
}
|
||||
|
||||
export function readFile(file, resultType) {
|
||||
return new Promise(resolve => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = event => {
|
||||
resolve(event.target.result);
|
||||
};
|
||||
|
||||
if (resultType === 'dataUrl') {
|
||||
reader.readAsDataURL(file);
|
||||
} else if (resultType === 'text') {
|
||||
reader.readAsText(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function isOversize(files, maxSize) {
|
||||
return toArray(files).some(file => file.size > maxSize);
|
||||
}
|
Reference in New Issue
Block a user