修复历史日志文件下载

pull/1719/head
648540858 2024-12-10 22:55:02 +08:00
parent 8495cd0f23
commit 79627201f5
1 changed files with 41 additions and 9 deletions

View File

@ -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}`
// }
//
// 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.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.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