feat: import form vben/utils

This commit is contained in:
xingyu4j
2025-11-18 17:29:52 +08:00
parent b3a1848243
commit ec23e8acf6
9 changed files with 52 additions and 63 deletions

View File

@@ -90,18 +90,34 @@ export function getFileNameFromUrl(url: null | string | undefined): string {
}
}
/**
* 默认图片类型
*/
export const defaultImageAccepts = [
'bmp',
'gif',
'jpeg',
'jpg',
'png',
'svg',
'webp',
];
/**
* 判断文件是否为图片
*
* @param filename 文件名
* @returns 是否为图片
*/
export function isImage(filename: null | string | undefined): boolean {
if (!filename) {
export function isImage(
filename: null | string | undefined,
accepts: string[] = defaultImageAccepts,
): boolean {
if (!filename || accepts.length === 0) {
return false;
}
const ext = filename.split('.').pop()?.toLowerCase() || '';
return ['bmp', 'gif', 'jpeg', 'jpg', 'png', 'svg', 'webp'].includes(ext);
return accepts.includes(ext);
}
/**