fix: 文件类型校验

Signed-off-by: NicholasLD <nicholasld505@gmail.com>
This commit is contained in:
NicholasLD 2025-06-10 05:35:35 +00:00 committed by Gitee
parent e8240021cb
commit 19940201f5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -28,7 +28,7 @@ const props = withDefaults(defineProps<Props>(), {
defaultUpload: true, defaultUpload: true,
showTip: true, showTip: true,
max: 5, max: 5,
accept: '.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.pdf', accept: '',
fileSize: 5, fileSize: 5,
uploadType: 'file', uploadType: 'file',
modelValue: '' modelValue: ''
@ -121,6 +121,12 @@ function beforeUpload(options: { file: UploadFileInfo; fileList: UploadFileInfo[
return false; return false;
} }
} }
if (accept.value && !file.name.match(new RegExp(accept.value.replace(/\./g, '\\.').replace(/,/g, '|')))) {
window.$message?.error(`文件格式不正确, 请上传 ${accept.value} 格式文件!`);
return false;
}
// //
if (file.name.includes(',')) { if (file.name.includes(',')) {
window.$message?.error('文件名不正确,不能包含英文逗号!'); window.$message?.error('文件名不正确,不能包含英文逗号!');
@ -203,8 +209,13 @@ async function handleRemove(file: UploadFileInfo) {
if (file.status !== 'finished') { if (file.status !== 'finished') {
return; return;
} }
fileList.value = fileList.value.filter(item => item.id !== file.id);
const fileIds = listToString(fileList.value);
emit('update:modelValue', fileIds);
needRelaodData.value = true;
const { error } = await fetchBatchDeleteOss([file.id]); const { error } = await fetchBatchDeleteOss([file.id]);
if (error) return; if (error) return;
window.$message?.success('删除成功'); window.$message?.success('删除成功');
} }
</script> </script>