From 4c74d5a410a49e1599cac02d873a549303408564 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Thu, 15 Jan 2026 19:22:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E9=A3=9F=E5=A0=82=E8=8F=9C=E5=93=81?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E7=BB=9F=E8=AE=A1(=E6=8C=89=E5=A4=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/other.ts | 68 +++++++++++++++++-- .../hard/canteen-product-total/index.vue | 6 ++ 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/utils/other.ts b/src/utils/other.ts index 2b9b1f9..908cccb 100644 --- a/src/utils/other.ts +++ b/src/utils/other.ts @@ -265,8 +265,26 @@ export function downBlobFile(url: any, query: any, fileName: string) { .then((response) => { handleBlobFile(response, fileName) }) - .catch((error) => { - useMessage().error(error.msg || "下载失败") + .catch(async (error) => { + let msg = "下载失败" + try { + if (error instanceof Blob) { + const text = typeof (error as any).text === "function" ? await (error as any).text() : "" + if (text) { + try { + const json = JSON.parse(text) + msg = json.msg || json.message || msg + } catch { + msg = text || msg + } + } + } else if (typeof error === "object") { + msg = (error as any).msg || (error as any).message || msg + } + } catch { + msg = "下载失败" + } + useMessage().error(msg) }) } @@ -286,8 +304,26 @@ export function postDownBlobFile(url: any, data: any, fileName: string) { .then((response) => { handleBlobFile(response, fileName) }) - .catch((error) => { - useMessage().error(error.msg || "下载失败") + .catch(async (error) => { + let msg = "下载失败" + try { + if (error instanceof Blob) { + const text = typeof (error as any).text === "function" ? await (error as any).text() : "" + if (text) { + try { + const json = JSON.parse(text) + msg = json.msg || json.message || msg + } catch { + msg = text || msg + } + } + } else if (typeof error === "object") { + msg = (error as any).msg || (error as any).message || msg + } + } catch { + msg = "下载失败" + } + useMessage().error(msg) }) } @@ -334,7 +370,6 @@ export function handleBlobFile(response: any, fileName: string) { } else if (response.data && response.data instanceof Blob) { blob = response.data } else { - // 尝试构造安全的blob const safeData = Array.isArray(response) ? response : [response] blob = new Blob(safeData, { type: "application/octet-stream" }) } @@ -344,6 +379,29 @@ export function handleBlobFile(response: any, fileName: string) { return } + if (blob.type === "application/json" || blob.type === "text/plain") { + try { + const handleText = (t: string) => { + try { + const json = JSON.parse(t) + useMessage().error(json.msg || json.message || "下载失败") + } catch { + useMessage().error(t || "下载失败") + } + } + if (typeof (blob as any).text === "function") { + ;(blob as any).text().then((t: string) => handleText(t)) + } else { + const reader = new FileReader() + reader.onload = () => handleText(String(reader.result || "")) + reader.readAsText(blob) + } + } catch { + useMessage().error("下载失败") + } + return + } + // 3. 验证文件大小 (防止过大文件) const MAX_FILE_SIZE = 100 * 1024 * 1024 // 100MB限制 if (blob.size > MAX_FILE_SIZE) { diff --git a/src/views/hard/canteen-product-total/index.vue b/src/views/hard/canteen-product-total/index.vue index bfc1888..2f78bbe 100644 --- a/src/views/hard/canteen-product-total/index.vue +++ b/src/views/hard/canteen-product-total/index.vue @@ -105,6 +105,12 @@ watch(() => [activeTab.value, productTotalTableByDayRef.value, productTotalTable } }) +onMounted(() => { + nextTick(() => { + search() + }) +}) + // 清空搜索条件 const resetQuery = () => { // 清空搜索条件