修改下载 调用接口

This commit is contained in:
wangchengming 2025-12-11 22:03:32 +08:00
parent e7802101fc
commit d3e218e597
2 changed files with 79 additions and 4 deletions

View File

@ -175,7 +175,45 @@ export default {
// const url = this.outPath + '\\' + this.queryParams.case_no + '_' + item + '_ROC.json' // const url = this.outPath + '\\' + this.queryParams.case_no + '_' + item + '_ROC.json'
// const path = url.replace(/\\/g, '/') // const path = url.replace(/\\/g, '/')
// this.$axios.get(window.CONFIG.baseUrl + '/download', { params: { path: path }}) // this.$axios.get(window.CONFIG.baseUrl + '/download', { params: { path: path }})
this.downloadFile(this.output_path, this.queryParams.case_no + '_' + item + '_ROC.json') // this.downloadFile(this.output_path, this.queryParams.case_no + '_' + item + '_ROC.json')
this.$axios.get(window.CONFIG.baseUrl + '/download', { params: { path: this.output_path }, responseType: 'blob', }).then(res => {
// 1.
if (!res.data) {
this.$message.error('下载失败:无文件数据');
return;
}
// 2.
let fileName = '下载文件'; //
const contentDisposition = res.headers['content-disposition'];
if (contentDisposition) {
// Content-Disposition
const fileNameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
if (fileNameMatch && fileNameMatch[1]) {
fileName = decodeURIComponent(fileNameMatch[1].replace(/['"]/g, ''));
}
}
// 3.
const blob = new Blob([res.data]);
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement('a');
// 4.
link.href = downloadUrl;
link.download = fileName; //
link.style.display = 'none';
// 5.
document.body.appendChild(link);
link.click();
// 6.
setTimeout(() => {
document.body.removeChild(link);
window.URL.revokeObjectURL(downloadUrl); // URL
}, 100);
})
}) })
}, },
chart() { chart() {

View File

@ -174,9 +174,46 @@ export default {
arr.forEach(item => { arr.forEach(item => {
// const url = this.outPath + '\\' + this.queryParams.case_no + '_' + item + '_ROC.json' // const url = this.outPath + '\\' + this.queryParams.case_no + '_' + item + '_ROC.json'
// const path = url.replace(/\\/g, '/') // const path = url.replace(/\\/g, '/')
const path = this.output_path
// this.$axios.get(window.CONFIG.baseUrl + '/download', { params: { path: path }}) // this.$axios.get(window.CONFIG.baseUrl + '/download', { params: { path: path }})
this.downloadFile(path, this.queryParams.case_no + '_' + item + '_ROC.json') // this.downloadFile(path, this.queryParams.case_no + '_' + item + '_ROC.json')
this.$axios.get(window.CONFIG.baseUrl + '/download', { params: { path: this.output_path }, responseType: 'blob', }).then(res => {
// 1.
if (!res.data) {
this.$message.error('下载失败:无文件数据');
return;
}
// 2.
let fileName = '下载文件'; //
const contentDisposition = res.headers['content-disposition'];
if (contentDisposition) {
// Content-Disposition
const fileNameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
if (fileNameMatch && fileNameMatch[1]) {
fileName = decodeURIComponent(fileNameMatch[1].replace(/['"]/g, ''));
}
}
// 3.
const blob = new Blob([res.data]);
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement('a');
// 4.
link.href = downloadUrl;
link.download = fileName; //
link.style.display = 'none';
// 5.
document.body.appendChild(link);
link.click();
// 6.
setTimeout(() => {
document.body.removeChild(link);
window.URL.revokeObjectURL(downloadUrl); // URL
}, 100);
})
}) })
}, },
chart() { chart() {