From e8985c6e8c58b5d66ea2c6cc7d8d9fd13cefc0b6 Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Thu, 5 Mar 2026 16:43:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A0=94=E5=88=A4=E5=88=86=E6=9E=90=E6=8A=A5?= =?UTF-8?q?=E5=91=8A--step1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/request.ts | 42 ++++++++++++++++++++- src/api/work/negative.ts | 9 +++++ src/views/work/Query.vue | 79 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 124 insertions(+), 6 deletions(-) diff --git a/src/api/request.ts b/src/api/request.ts index 257be51..38decfd 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -35,6 +35,11 @@ function del(options: Options) { return ajax(options.url, options) } +function postWord(options: Options) { + options.method = 'POST'; + return ajaxWord(options.url, options); +} + let isRelogin = false; function ajax(url: string, options: Options) { const headers: Record = { @@ -103,11 +108,46 @@ function ajax(url: string, options: Options) { }) } + +function ajaxWord(url: string, options: Options) { + const headers: Record = { + "Authorization": getToken() + }; + + let body: string | FormData; + + if (options?.body) { + headers["Content-Type"] = "application/json"; + body = JSON.stringify(options.body); + } + + return fetch(`${BASE_PATH}${url}`, { + method: options.method, + headers: { ...headers, ...options.headers }, + body: body + }).then(async response => { + + if (!response.ok) { + throw new Error("下载失败"); + } + + const blob = await response.blob(); // ⭐ 关键:读取二进制 + + const disposition = response.headers.get("content-disposition"); + + return { + blob, + disposition + }; + }); +} + const request = { get, post, put, - del + del, + postWord } export default request; \ No newline at end of file diff --git a/src/api/work/negative.ts b/src/api/work/negative.ts index 7e15da2..b846567 100644 --- a/src/api/work/negative.ts +++ b/src/api/work/negative.ts @@ -102,3 +102,12 @@ export function getIdByOriginId(originId) { url: `/negative/getIdByOriginId/${originId}` }); } + +// 生成报告 +export function generateReport(data) { + return request.postWord({ + url: "/negative/generateReport", + body: data + }) +} + diff --git a/src/views/work/Query.vue b/src/views/work/Query.vue index d8c7a0f..22d2588 100644 --- a/src/views/work/Query.vue +++ b/src/views/work/Query.vue @@ -186,6 +186,21 @@ /> + + + + +
@@ -456,6 +471,9 @@ 数据导出 + 报告生成
{ + // await feedback.confirm("请确定生成当前页面数据的报告"); + debugger + const reportDateRange = query.value.reportDateRange; + if (!reportDateRange){ + feedback.msgError("请选择对应报告时间") + return + } + const loading = ElLoading.service({ + lock: true, + text: "报告生成中...", + background: "rgba(0, 0, 0, 0.5)", + }); + try { + // 发送请求到后端生成报告 + const body = { + beginTime: query.value.reportDateRange[0], + endTime: query.value.reportDateRange[1], + } + const res = await generateReport(body); + + const blob = res.blob; + + let fileName = "研判分析报告.docx"; + + if (res.disposition) { + const match = res.disposition.match(/filename\*?=.*''(.+)/); + if (match) { + fileName = decodeURIComponent(match[1]); + } + } + + const url = window.URL.createObjectURL(blob); + const link = document.createElement("a"); + + link.href = url; + link.download = fileName; + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + window.URL.revokeObjectURL(url); + loading.close(); + } catch (error) { + console.log(error) + loading.close(); + } +} + + async function handleDel(row) { await feedback.confirm(`确定删除该数据?`); await delNegative(row.id);