mirror of
https://gitee.com/yudaocode/yudao-ui-admin-vben.git
synced 2025-12-30 10:32:25 +00:00
21 lines
500 B
TypeScript
21 lines
500 B
TypeScript
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);
|
|
}
|