From e421cf9188998ba5a1c07e6f306fc127b9c96f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Tue, 17 Jun 2025 11:01:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=E6=89=B9=E9=87=8F=E5=AF=BC=E5=87=BAzi?= =?UTF-8?q?p=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/measure/components/MeasureDetail.tsx | 54 +++++++++++++++++--------- src/utils/index.ts | 19 ++++----- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/pages/measure/components/MeasureDetail.tsx b/src/pages/measure/components/MeasureDetail.tsx index fe8f99f..501f3b8 100644 --- a/src/pages/measure/components/MeasureDetail.tsx +++ b/src/pages/measure/components/MeasureDetail.tsx @@ -144,19 +144,19 @@ export default function MeasureDetail() { setIsModaUploadlOpen(true) } - const onDownloadData = async () =>{ - setIdList([]) - let list = [...selectRows] - let Ids:number[] = [] - list.map(item => { - Ids.push(item.id) - }) - setIdList(Ids) - const response = await fetch(`/api/measurement-task/downloads/${Ids.join(',')}`); - const blob = await response.blob(); // 先获取 Blob - const arrayBuffer = await blob.arrayBuffer(); // 将 Blob 转换为 ArrayBuffer - exportFile(arrayBuffer, `坐标数据.xls`); // 传递 ArrayBuffer 给函数 - } + const onDownloadData = async () => { + // 1. 准备 id 列表 + const Ids = selectRows.map(r => r.id); + // 2. 发起请求 + const response = await fetch(`/api/measurement-data/downloads-zip/${Ids.join(',')}`); + // 3. 拿到 Blob + const blob = await response.blob(); + // 4. 解析后端文件名 + const contentDisp = response.headers.get('content-disposition'); + const filename = parseFilename(contentDisp) || 'download.zip'; + // 5. 触发下载 + exportFile(blob, filename); + }; const [percent, setPercent] = useState(0) @@ -233,14 +233,30 @@ export default function MeasureDetail() { getMeasurePoints(item) } - //导出 - const onDownloadRecord = async(item:DetailTable) => { - const response = await fetch(`/api/measurement-task/download/${item.id}`); - const blob = await response.blob(); // 先获取 Blob - const arrayBuffer = await blob.arrayBuffer(); // 将 Blob 转换为 ArrayBuffer - exportFile(arrayBuffer, `${item.name}.txt`); // 传递 ArrayBuffer 给函数 + function parseFilename(disposition: string | null): string | null { + if (!disposition) return null; + // 匹配 filename*=UTF-8''xxx 或 filename=xxx(带不带引号都能捕获) + const match = disposition.match(/filename\*?=(?:UTF-8'')?["']?([^"';]+)["']?/i); + return match ? decodeURIComponent(match[1]) : null; } + //导出 + const onDownloadRecord = async (item: DetailTable) => { + // 1. 发请求 + const response = await fetch(`/api/measurement-data/download/${item.id}`); + + // 2. 拿到 Blob + const blob = await response.blob(); + + // 3. 解析头里的文件名 + const contentDisp = response.headers.get('content-disposition'); + // fallback 到 item.name + .txt + const filename = parseFilename(contentDisp) || `${item.name}.txt`; + + // 4. 触发下载 + exportFile(blob, filename); + }; + const getMeasurePoints = (recordItem:DetailTable) => { getPointsById({id:recordItem.id}).then(res=>{ if (canvasRef.current) { diff --git a/src/utils/index.ts b/src/utils/index.ts index 3803b80..847fb09 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -87,18 +87,13 @@ export function findSymmetricPoint(px: number, py: number, ox = 0, oy = 0) { } -export function exportFile(response: ArrayBuffer, fileName: string){ - // 创建 Blob 对象 - const blob = new Blob([response], { type: 'application/octet-stream' }); - // 创建一个 URL 对象,将 Blob 对象转换为 URL - const url = window.URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = fileName; - // 模拟点击 元素来触发下载 - a.click(); - // 释放 URL 对象 - window.URL.revokeObjectURL(url); +export function exportFile(blob: Blob, fileName: string) { + const url = window.URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = fileName; + a.click(); + window.URL.revokeObjectURL(url); } export function padNumber(num: number, length: number) { From b848e8775ccbb49b8aeb5053efc4e538ba6e7add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Tue, 17 Jun 2025 11:33:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=E5=AF=BC=E5=87=BAtxt=E6=88=96?= =?UTF-8?q?=E8=80=85ban=E5=8F=AF=E4=BB=A5=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/system/Setting.tsx | 25 ++++++++++++++++++++++--- src/services/measure/type.ts | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/pages/system/Setting.tsx b/src/pages/system/Setting.tsx index a3b6d9a..ae4b0ab 100644 --- a/src/pages/system/Setting.tsx +++ b/src/pages/system/Setting.tsx @@ -326,9 +326,9 @@ export default function Setting(){ > { systemList.map((item, index) => { - return item.name ? + return item.name ? saveSet(item, e.target.value)}/>} : null - }) + }) } + + + + } @@ -367,6 +374,18 @@ export default function Setting(){ }) } + const onDownloadFileTypeChange = (value: string) => { + const params: StandbyMinutes = { + downloadFileType: value, + } + saveDeviceConfig(params).then(res=> { + message.success("保存成功"); + setSaveLoading(false) + }).catch(e => { + setSaveLoading(false) + }) + } + const onTodayNumberFlagChange = (value: boolean) => { const params: StandbyMinutes = { todayNumberFlag: value, diff --git a/src/services/measure/type.ts b/src/services/measure/type.ts index b9be0dc..20ac04b 100644 --- a/src/services/measure/type.ts +++ b/src/services/measure/type.ts @@ -132,4 +132,5 @@ export type trackItem = { export type StandbyMinutes = { standbyMinutes?: string | number todayNumberFlag?: boolean + downloadFileType?: string } \ No newline at end of file