feat: use vben/utils upload

This commit is contained in:
xingyu4j
2025-11-18 17:33:39 +08:00
parent ec23e8acf6
commit 60854e59f1
8 changed files with 26 additions and 38 deletions

View File

@@ -107,6 +107,7 @@ export const defaultImageAccepts = [
* 判断文件是否为图片
*
* @param filename 文件名
* @param accepts 支持的文件类型
* @returns 是否为图片
*/
export function isImage(
@@ -120,6 +121,22 @@ export function isImage(
return accepts.includes(ext);
}
/**
* 判断文件是否为指定类型
*
* @param file 文件
* @param accepts 支持的文件类型
* @returns 是否为指定类型
*/
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);
}
/**
* 格式化文件大小
*