函数
const fileInput = document.createElement('input');
fileInput.type = 'file';
function ImageUpload({ accept, fileType, call, error }){
fileInput.accept = accept;
fileInput.value = '';
fileInput.onchange = () => {
if(fileInput.files.length > 0){
let status = 0;
let keys = '';
if(fileType === 'audio'){
const reg = /.\.(mp3|MP3)$/;
keys = 'mp3';
if(reg.test(fileInput.files[0].name)){
status = 1;
}
} else if(fileType === 'video'){
const reg = /.\.(mp4|MP4)$/;
keys = 'mp4';
if(reg.test(fileInput.files[0].name)){
status = 1;
}
} else if(fileType === 'image'){
const reg = /.\.(jpeg|jpg|png|gif|GIF|PNG|JPG|JPEG|JPG)$/;
keys = 'jpeg、jpg、png、gif';
if(reg.test(fileInput.files[0].name)){
status = 1;
}
} else if(fileType === 'statsImg'){
const reg = /.\.(jpeg|jpg|png|PNG|JPG|JPEG|JPG)$/;
keys = 'jpeg、jpg、png';
if(reg.test(fileInput.files[0].name)){
status = 1;
}
}
if(status){
call(fileInput.files[0]);
} else{
error && error();
alart("上传文件有误")
}
}
};
fileInput.click();
}