7/17 添加公区收益
This commit is contained in:
@@ -57,23 +57,25 @@
|
||||
<el-col :span="12">
|
||||
<el-form-item label="附属材料">
|
||||
<el-upload
|
||||
:auto-upload="false"
|
||||
class="upload-demo"
|
||||
:file-list="fileList"
|
||||
:action="uploadUrl"
|
||||
:multiple="true"
|
||||
:auto-upload="false"
|
||||
ref="uploadRef"
|
||||
:show-file-list="true"
|
||||
name="files"
|
||||
:headers="headerToken()"
|
||||
:show-file-list="true"
|
||||
:on-remove="handleAvatarRemove"
|
||||
:on-change="handleProgress"
|
||||
:before-upload="beforeAvatarUpload"
|
||||
accept=".doc,.docx,.xls,.xlsx,.jpg,.jpeg,.png,.gif,.bmp,.webp"
|
||||
>
|
||||
<div class="uploadBtn flex flex-items-center">
|
||||
<el-icon><Upload /></el-icon>
|
||||
<span>上传文件</span>
|
||||
</div>
|
||||
<template #tip>仅支持doc/docx/xls/xlsx/jpg/png/gif等</template>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -144,14 +146,16 @@ const handleAvatarRemove: UploadProps['onRemove'] = (uploadFile: UploadUserFile,
|
||||
// 定义大小限制常量 (单位: MB)
|
||||
const MAX_SINGLE_FILE_SIZE = 10 * 1024 * 1024; // 10MB in bytes
|
||||
const MAX_TOTAL_FILE_SIZE = 20 * 1024 * 1024; // 20MB in bytes
|
||||
// 禁止的危险文件后缀
|
||||
const forbidSuffix = ['exe', 'msi', 'bat', 'cmd', 'sh', 'apk', 'dmg'];
|
||||
const uploadRef = ref();
|
||||
// 添加一个锁,防止 on-change 递归调用导致重复提示
|
||||
const isChecking = ref(false);
|
||||
const handleProgress: UploadProps['onChange'] = (uploadFile: UploadUserFile, uploadFiles: UploadFiles) => {
|
||||
// 如果正在校验中,直接返回,避免重复执行
|
||||
if (!beforeAvatarUpload(uploadFile)) {
|
||||
uploadRef.value.handleRemove(uploadFile);
|
||||
return;
|
||||
}
|
||||
if (isChecking.value) return;
|
||||
|
||||
// 加锁
|
||||
isChecking.value = true;
|
||||
// 创建一个新数组来存储校验通过的文件
|
||||
@@ -229,12 +233,41 @@ const handleProgress: UploadProps['onChange'] = (uploadFile: UploadUserFile, upl
|
||||
};
|
||||
|
||||
const blockedExts = ['.exe', '.bat', '.cmd', '.msi'];
|
||||
const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => {
|
||||
const allowExts = [
|
||||
// word
|
||||
'.doc',
|
||||
'.docx',
|
||||
'.dot',
|
||||
'.dotx',
|
||||
// excel
|
||||
'.xls',
|
||||
'.xlsx',
|
||||
'.xlsm',
|
||||
'.xlsb',
|
||||
// img
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.png',
|
||||
'.gif',
|
||||
'.bmp',
|
||||
'.webp',
|
||||
// 专业/矢量图
|
||||
'.psd',
|
||||
'.ai',
|
||||
'.svg',
|
||||
'.tif',
|
||||
'.tiff'
|
||||
];
|
||||
const beforeAvatarUpload = (rawFile: UploadUserFile) => {
|
||||
const ext = rawFile.name.toLowerCase().slice(rawFile.name.lastIndexOf('.'));
|
||||
if (blockedExts.includes(ext)) {
|
||||
ElMessage.warning(`禁止上传 ${ext} 文件`);
|
||||
return false;
|
||||
}
|
||||
if (!allowExts.includes(ext)) {
|
||||
ElMessage.warning('只能上传word,excel,图片等文件');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user