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

@@ -6,15 +6,3 @@ export function checkFileType(file: File, accepts: string[]) {
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);
}

View File

@@ -15,11 +15,16 @@ import { ref, toRefs, watch } from 'vue';
import { IconifyIcon } from '@vben/icons';
import { $t } from '@vben/locales';
import { isFunction, isObject, isString } from '@vben/utils';
import {
defaultImageAccepts,
isFunction,
isImage,
isObject,
isString,
} from '@vben/utils';
import { ElMessage, ElUpload } from 'element-plus';
import { checkImgType, defaultImageAccepts } from './helper';
import { UploadResultStatus } from './typing';
import { useUpload, useUploadType } from './use-upload';
@@ -173,7 +178,7 @@ const handleRemove = async (file: UploadFile) => {
const beforeUpload = async (file: File) => {
const { maxSize, accept } = props;
const isAct = checkImgType(file, accept);
const isAct = isImage(file.name, accept);
if (!isAct) {
ElMessage.error($t('ui.upload.acceptUpload', [accept]));
isActMsg.value = false;