From fceedd02cd5ce47ea7a1a10642bf12b4e3f28857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BB=98?= <925456043@qq.com> Date: Wed, 29 Jul 2026 00:57:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=A9=E5=B1=95=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=BA=93=E6=96=87=E6=A1=A3=E4=B8=8A=E4=BC=A0=E9=99=90=E5=88=B6?= =?UTF-8?q?=E8=87=B3=20100=20MB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 上传前校验单文件大小并给出本地化提示 - 同步支持格式与中英文说明 --- .../app/src/components/upload/DragFileUpload.vue | 15 ++++++++++++++- .../app/src/locales/langs/en-US/message.json | 3 ++- .../app/src/locales/langs/zh-CN/message.json | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/easyflow-ui-admin/app/src/components/upload/DragFileUpload.vue b/easyflow-ui-admin/app/src/components/upload/DragFileUpload.vue index 168cc3af..bffe3e85 100644 --- a/easyflow-ui-admin/app/src/components/upload/DragFileUpload.vue +++ b/easyflow-ui-admin/app/src/components/upload/DragFileUpload.vue @@ -4,6 +4,7 @@ import type { UploadProps } from 'element-plus'; import { ref } from 'vue'; import { useAppConfig } from '@easyflow/hooks'; +import { $t } from '@easyflow/locales'; import { useAccessStore } from '@easyflow/stores'; import { UploadFilled } from '@element-plus/icons-vue'; @@ -26,6 +27,8 @@ const props = defineProps({ }); const emit = defineEmits(['success', 'error', 'onChange']); +const MAX_FILE_SIZE_BYTES = 100 * 1024 * 1024; +const ACCEPTED_FILE_TYPES = '.txt,.pdf,.docx,.md,.pptx,.xlsx'; const accessStore = useAccessStore(); const headers = ref({ 'easyflow-token': accessStore.accessToken, @@ -51,6 +54,14 @@ const handleError: UploadProps['onError'] = (error) => { emit('error', normalizedError); }; +const beforeUpload: UploadProps['beforeUpload'] = (rawFile) => { + if (rawFile.size <= MAX_FILE_SIZE_BYTES) { + return true; + } + ElMessage.warning($t('message.upload.fileTooLarge')); + return false; +}; + // 文件状态变化回调 const handleChange: UploadProps['onChange'] = (file, fileList) => { emit('onChange', file, fileList); @@ -86,6 +97,8 @@ defineExpose({ drag :headers="headers" :action="`${apiURL}${props.action}`" + :accept="ACCEPTED_FILE_TYPES" + :before-upload="beforeUpload" :on-success="handleSuccess" :on-error="handleError" :on-change="handleChange" @@ -97,7 +110,7 @@ defineExpose({