详情PDF附件点击后不下载在浏览器中进行预览

dianlixunjian
Zhufu 2024-08-21 10:59:41 +08:00
parent 5f956ca149
commit d67d7affc3
1 changed files with 22 additions and 1 deletions

View File

@ -347,6 +347,7 @@
import { getGeom } from '@/api/sys/layerManagement';
import {getLoadCaseImgList} from '@/api/tiankongdi'
import { useMessage } from '@/hooks/web/useMessage';
import axios from 'axios';
const { createMessage } = useMessage();
import Icon from '@/components/Icon/Icon.vue';
import { getAppEnvConfig } from '@/utils/env';
@ -654,7 +655,27 @@
}
}
const downLoadFile = (url) => {
window.open(`${VITE_GLOB_INFO_IMAGE_URL}/${url}`, 'mozillaTab');
if(url.indexOf('.pdf') !== -1){
axios({
method: 'get',
url: `${VITE_GLOB_INFO_IMAGE_URL}/${url}`,
responseType: 'blob',
headers: {
'Content-Disposition': 'inline',
}
})
.then(response => {
let blob = new Blob([response.data], {type: 'application/pdf'});
let url = window.URL.createObjectURL(blob)
window.open(url);
})
.catch(error => {
console.error(error);
});
}else{
window.open(`${VITE_GLOB_INFO_IMAGE_URL}/${url}`, '_blank');
}
};
const getContainer = () => {
return document.getElementById('info-container');