From 79627201f591c982dd283a10db082783eec7b87a Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 10 Dec 2024 22:55:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=86=E5=8F=B2=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/operationsForHistoryLog.vue | 50 +++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/web_src/src/components/operationsForHistoryLog.vue b/web_src/src/components/operationsForHistoryLog.vue index 870f1509..196cf49d 100755 --- a/web_src/src/components/operationsForHistoryLog.vue +++ b/web_src/src/components/operationsForHistoryLog.vue @@ -82,6 +82,7 @@ import uiHeader from '../layout/UiHeader.vue' import MediaServer from './service/MediaServer' import operationsFoShowLog from './dialog/operationsFoShowLog.vue' import moment from 'moment' +import userService from "./service/UserService"; export default { name: 'app', @@ -154,16 +155,47 @@ export default { }, downloadFile(file) { - const link = document.createElement('a'); - link.target = "_blank"; - link.download = file.fileName; - if (process.env.NODE_ENV === 'development') { - link.href = `/debug/api/log/file/${file.fileName}` - }else { - link.href = `/api/log/file/${file.fileName}` - } + // const link = document.createElement('a'); + // link.target = "_blank"; + // link.download = file.fileName; + // if (process.env.NODE_ENV === 'development') { + // link.href = `/debug/api/log/file/${file.fileName}` + // }else { + // link.href = `/api/log/file/${file.fileName}` + // } + // + // link.click(); - link.click(); + + // 文件下载地址 + const fileUrl = ((process.env.NODE_ENV === 'development') ? process.env.BASE_API : baseUrl) + `/api/log/file/${file.fileName}`; + + // 设置请求头 + const headers = new Headers(); + headers.append('access-token', userService.getToken()); // 设置授权头,替换YourAccessToken为实际的访问令牌 + // 发起 请求 + fetch(fileUrl, { + method: 'GET', + headers: headers, + }) + .then(response => response.blob()) + .then(blob => { + console.log(blob) + // 创建一个虚拟的链接元素,模拟点击下载 + const link = document.createElement('a'); + link.target = "_blank"; + link.href = window.URL.createObjectURL(blob); + link.download = file.fileName; // 设置下载文件名,替换filename.ext为实际的文件名和扩展名 + document.body.appendChild(link); + + // 模拟点击 + link.click(); + + // 移除虚拟链接元素 + document.body.removeChild(link); + this.$message.success("已申请截图",{closed: true}) + }) + .catch(error => console.error('下载失败:', error)); }, loadEnd() { this.playerTitle = this.file.fileName