这一版本优化了很多

This commit is contained in:
王利强
2026-06-03 10:16:37 +08:00
parent 8046316216
commit 2af9f1fd59
954 changed files with 58194 additions and 1609 deletions

57
main.js
View File

@@ -1,5 +1,62 @@
import App from './App'
// 全局拦截选择图片,在文件进入上传列表前进行预过滤,从根本上解决“不合规图片在列表里转圈卡死”的问题
uni.addInterceptor('chooseImage', {
success(res) {
const allowedExtensions = ['bmp', 'gif', 'jpg', 'jpeg', 'png'];
const validTempFilePaths = [];
const validTempFiles = [];
let hasInvalid = false;
let invalidExt = '';
res.tempFiles.forEach((file, index) => {
const path = file.path || res.tempFilePaths[index];
const cleanPath = path.split('?')[0];
const ext = cleanPath.split('.').pop().toLowerCase();
if (allowedExtensions.includes(ext)) {
validTempFiles.push(file);
validTempFilePaths.push(res.tempFilePaths[index]);
} else {
hasInvalid = true;
invalidExt = ext;
}
});
if (hasInvalid) {
uni.showToast({
title: `已过滤不支持的 .${invalidExt} 格式图片,请上传 png/jpg/jpeg/gif/bmp`,
icon: 'none',
duration: 3500
});
}
res.tempFilePaths = validTempFilePaths;
res.tempFiles = validTempFiles;
}
});
// 全局拦截文件上传,校验文件后缀是否在后端白名单中,预防非法格式报错
uni.addInterceptor('uploadFile', {
invoke(args) {
const filePath = args.filePath;
if (filePath) {
const cleanPath = filePath.split('?')[0];
const ext = cleanPath.split('.').pop().toLowerCase();
const allowedExtensions = ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'html', 'htm', 'txt', 'rar', 'zip', 'gz', 'bz2', 'mp4', 'avi', 'rmvb', 'pdf'];
if (!allowedExtensions.includes(ext)) {
uni.showToast({
title: `不支持 .${ext} 格式,请上传合规的文件或图片`,
icon: 'none',
duration: 3000
});
return false; // 拦截请求
}
}
return args;
}
});
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'