|
@@ -126,9 +126,70 @@ const fileList = ref([]);
|
|
|
|
|
|
// 处理文件变化
|
|
|
const handleFileChange = (file, files) => {
|
|
|
+ // 检查文件类型和大小
|
|
|
+ const isValidFile = validateFile(file);
|
|
|
+ if (!isValidFile) {
|
|
|
+ // 如果文件无效,从文件列表中移除
|
|
|
+ const index = files.indexOf(file);
|
|
|
+ if (index !== -1) {
|
|
|
+ files.splice(index, 1);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
fileList.value = files;
|
|
|
};
|
|
|
|
|
|
+// 验证文件类型和大小
|
|
|
+const validateFile = (file) => {
|
|
|
+ if (!file || !file.raw) return false;
|
|
|
+
|
|
|
+ const fileName = file.name || '';
|
|
|
+ const fileSize = file.size || 0;
|
|
|
+ const fileExt = fileName.split('.').pop().toLowerCase();
|
|
|
+
|
|
|
+ // 检查文件类型
|
|
|
+ if (selectedGroup.value == 1) {
|
|
|
+ // 模型库组只允许 obj、glb、zip 格式
|
|
|
+ if (!['obj', 'glb', 'zip'].includes(fileExt)) {
|
|
|
+ ElMessage.error(`不支持的文件类型`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查文件大小,不能超过 5MB
|
|
|
+ const maxSize = 5 * 1024 * 1024; // 5MB
|
|
|
+ if (fileSize > maxSize) {
|
|
|
+ ElMessage.error(`上传文件不能超过 5MB`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 其他组允许 jpg、png、jpeg、mp4、wav、mp3、shp、zip 格式
|
|
|
+ if (!['jpg', 'png', 'jpeg', 'mp4', 'wav', 'mp3', 'shp', 'zip'].includes(fileExt)) {
|
|
|
+ ElMessage.error(`不支持的文件格式`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查文件大小
|
|
|
+ if (fileExt === 'zip') {
|
|
|
+ // zip 文件不能超过 1GB
|
|
|
+ const maxSize = 1 * 1024 * 1024 * 1024; // 1GB
|
|
|
+ if (fileSize > maxSize) {
|
|
|
+ ElMessage.error(`上传文件不能超过 1GB`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 其他文件不能超过 2GB
|
|
|
+ const maxSize = 2 * 1024 * 1024 * 1024; // 2GB
|
|
|
+ if (fileSize > maxSize) {
|
|
|
+ ElMessage.error(`上传文件不能超过 2GB`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+};
|
|
|
+
|
|
|
// 处理文件删除
|
|
|
const handleFileRemove = (file, fileList) => {
|
|
|
handleFileChange({}, []);
|