From 282925b6ef127ce67ca5e72b76856a4d80dac5c0 Mon Sep 17 00:00:00 2001 From: LanZinYtt <3414700632@qq.com> Date: Sat, 23 May 2026 21:47:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=9B=B4=E6=94=B9=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E7=9A=84=E6=96=B9=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?=E6=B5=81=E5=BC=8F=E4=B8=8A=E4=BC=A0=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E4=B8=8A=E4=BC=A0=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/modeling_router.py | 14 +++-- frontend/src/apis/submitModelingApi.ts | 8 ++- frontend/src/components/UserStepper.vue | 73 +++++++++++++++++++------ 3 files changed, 70 insertions(+), 25 deletions(-) diff --git a/backend/app/routers/modeling_router.py b/backend/app/routers/modeling_router.py index fdedd51..7c32617 100644 --- a/backend/app/routers/modeling_router.py +++ b/backend/app/routers/modeling_router.py @@ -244,13 +244,15 @@ async def modeling( logger.warning("跳过空文件名") continue - content = await file.read() - if not content: - logger.warning(f"文件 {file.filename} 内容为空") - continue - + # 流式写入,避免一次性读取大文件 with open(data_file_path, "wb") as f: - f.write(content) + chunk_size = 1024 * 1024 + while True: + chunk = await file.read(chunk_size) + if not chunk: + break + f.write(chunk) + await file.close() logger.info(f"成功保存文件: {data_file_path}") except Exception as e: diff --git a/frontend/src/apis/submitModelingApi.ts b/frontend/src/apis/submitModelingApi.ts index 613b17c..27b28cd 100644 --- a/frontend/src/apis/submitModelingApi.ts +++ b/frontend/src/apis/submitModelingApi.ts @@ -1,4 +1,5 @@ import request from "@/utils/request"; +import type { AxiosProgressEvent } from "axios"; /** * 提交数学建模任务 @@ -12,6 +13,7 @@ export function submitModelingTask( format_output?: string; }, files?: File[], + onUploadProgress?: (progressEvent: AxiosProgressEvent) => void, ) { const formData = new FormData(); // 添加问题数据 @@ -36,7 +38,11 @@ export function submitModelingTask( headers: { "Content-Type": "multipart/form-data", }, - timeout: 30000, // 添加超时设置 + onUploadProgress: (event) => { + if (!onUploadProgress) return; + onUploadProgress(event); + }, + timeout: 300000, }); } } diff --git a/frontend/src/components/UserStepper.vue b/frontend/src/components/UserStepper.vue index dc7d573..fabed9a 100644 --- a/frontend/src/components/UserStepper.vue +++ b/frontend/src/components/UserStepper.vue @@ -3,6 +3,7 @@ import { saveApiConfig } from "@/apis/apiKeyApi"; import { submitModelingTask } from "@/apis/submitModelingApi"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; +import type { AxiosProgressEvent } from "axios"; import { Select, SelectContent, @@ -77,6 +78,13 @@ const taskId = ref(null); /** 文件输入元素引用 */ const fileInput = ref(null); +/** 是否正在提交 */ +const isSubmitting = ref(false); + +/** 上传进度百分比 */ +const uploadProgress = ref(0); + + // ---- Methods ---- const nextStep = () => { @@ -102,6 +110,16 @@ const handleFileUpload = (event: Event) => { const router = useRouter(); +const handleUploadProgress = (progressEvent: AxiosProgressEvent) => { + const loaded = progressEvent.loaded ?? 0; + const total = progressEvent.total ?? 0; + + if (total > 0) { + const nextProgress = Math.min(100, Math.round((loaded / total) * 100)); + uploadProgress.value = Math.max(uploadProgress.value, nextProgress); + } +}; + /** 提交建模任务 */ const handleSubmit = async () => { try { @@ -140,6 +158,8 @@ const handleSubmit = async () => { console.log(selectedOptions.value); console.log(question.value); console.log(uploadedFiles.value); + isSubmitting.value = true; + uploadProgress.value = 0; const response = await submitModelingTask( { ques_all: question.value, @@ -147,7 +167,9 @@ const handleSubmit = async () => { format_output: selectedOptions.value.format, }, uploadedFiles.value, + handleUploadProgress, ); + uploadProgress.value = 100; taskId.value = response?.data?.task_id ?? null; taskStore.addUserMessage(question.value); @@ -168,6 +190,8 @@ const handleSubmit = async () => { description: "请检查 API Key 是否正确", variant: "destructive", }); + } finally { + isSubmitting.value = false; } }; @@ -199,7 +223,7 @@ const handleSubmit = async () => { -
+
{
-
-

拖拽数据集到此处或点击上传

-

- 支持 .txt, .csv, .xlsx 等格式文件(可多选) -

-
- 已上传文件: -
    -
  • - {{ file.name }} -
  • -
-
-
-
+
+

拖拽数据集到此处或点击上传

+

+ 支持 .txt, .csv, .xlsx 等格式文件(可多选) +

+
+ 已上传文件: +
    +
  • + {{ file.name }} +
  • +
+
+
+