feat: 增加 image 文件上传 80%

This commit is contained in:
YunaiV
2025-04-18 13:08:20 +08:00
parent f6e2dc55ff
commit 1bacb6759f
4 changed files with 282 additions and 11 deletions

View File

@@ -1,18 +1,17 @@
export function checkFileType(file: File, accepts: string[]) {
let reg;
if (!accepts || accepts.length === 0) {
reg = /.(jpg|jpeg|png|gif|webp)$/i;
} else {
const newTypes = accepts.join('|');
reg = new RegExp('\\.(' + newTypes + ')$', 'i');
return true;
}
const newTypes = accepts.join('|');
const reg = new RegExp('\\.(' + newTypes + ')$', 'i');
return reg.test(file.name);
}
export function checkImgType(file: File) {
return isImgTypeByName(file.name);
}
/**
* 默认图片类型
*/
export const defaultImageAccepts = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
export function isImgTypeByName(name: string) {
return /\.(jpg|jpeg|png|gif|webp)$/i.test(name);
}
export function checkImgType(file: File, accepts: string[] = defaultImageAccepts) {
return checkFileType(file, accepts);
}