diff --git a/src/components/ImportForm/src/ImportFormOnlyAdd.vue b/src/components/ImportForm/src/ImportFormOnlyAdd.vue index a467067de..9f8c541e5 100644 --- a/src/components/ImportForm/src/ImportFormOnlyAdd.vue +++ b/src/components/ImportForm/src/ImportFormOnlyAdd.vue @@ -223,7 +223,19 @@ const submitForm = async () => { message.error('请上传文件') return } - file.value = fileList.value[0].name + // 校验文件类型 + const fileName = fileList.value[0].name + const fileExtension = fileName.substring(fileName.lastIndexOf('.')).toLowerCase() + const acceptedTypes = accept.value.split(',').map(type => type.toLowerCase()) + + // 检查文件扩展名是否在允许的类型列表中 + if (!acceptedTypes.some(type => type === fileExtension || type === `.*${fileExtension}`)) { + message.error(`只能上传 ${accept.value} 格式的文件`) + return + } + + file.value = fileName + // 提交请求 uploadHeaders.value = { Authorization: 'Bearer ' + getAccessToken(),