From dd1390d6f6fb36d2eb9b74cd3ee72938763c9070 Mon Sep 17 00:00:00 2001 From: ljlong_2630 Date: Thu, 14 Nov 2024 16:48:21 +0800 Subject: [PATCH] =?UTF-8?q?YT-844:=20=E5=8F=AF=E4=BB=A5=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6=E5=90=88=E6=A0=BC=E5=BC=8F=E8=A6=81=E6=B1=82?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ImportForm/src/ImportFormOnlyAdd.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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(),