feat: vite文件大小限制

This commit is contained in:
wizardchen
2025-12-30 19:19:00 +08:00
committed by lyingbug
parent da1dcb0cda
commit 6a123f4620
3 changed files with 17 additions and 5 deletions
+9 -4
View File
@@ -1,4 +1,9 @@
import { MessagePlugin } from "tdesign-vue-next";
// 从环境变量获取最大文件大小(MB),默认30MB
const MAX_FILE_SIZE_MB = Number(import.meta.env.VITE_MAX_FILE_SIZE_MB) || 50;
const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
export function generateRandomString(length: number) {
let result = "";
const characters =
@@ -33,16 +38,16 @@ export function kbFileTypeVerification(file: any, silent = false) {
}
if (
(type == "pdf" || type == "docx" || type == "doc") &&
file.size > 31457280
file.size > MAX_FILE_SIZE_BYTES
) {
if (!silent) {
MessagePlugin.error("pdf/doc文件不能超过30M!");
MessagePlugin.error(`pdf/doc文件不能超过${MAX_FILE_SIZE_MB}M!`);
}
return true;
}
if ((type == "txt" || type == "md") && file.size > 31457280) {
if ((type == "txt" || type == "md") && file.size > MAX_FILE_SIZE_BYTES) {
if (!silent) {
MessagePlugin.error("txt/md文件不能超过30M!");
MessagePlugin.error(`txt/md文件不能超过${MAX_FILE_SIZE_MB}M!`);
}
return true;
}