feat: 增加 file 文件上传 50%
This commit is contained in:
18
apps/web-antd/src/components/upload/helper.ts
Normal file
18
apps/web-antd/src/components/upload/helper.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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 reg.test(file.name);
|
||||
}
|
||||
|
||||
export function checkImgType(file: File) {
|
||||
return isImgTypeByName(file.name);
|
||||
}
|
||||
|
||||
export function isImgTypeByName(name: string) {
|
||||
return /\.(jpg|jpeg|png|gif|webp)$/i.test(name);
|
||||
}
|
||||
Reference in New Issue
Block a user