feat: add upload comp

This commit is contained in:
xingyu4j
2025-05-09 16:17:20 +08:00
parent 684d564ea1
commit 477e387ce9
6 changed files with 693 additions and 0 deletions

View File

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