// 查看
const handleCheck = async (id) => {
const res = await downloadDetection({
id,
});
// 关键代码 res:流文件
const blobData = [res];
const blob = new Blob(blobData, { type: "application/pdf" });
const blobURL = window.URL.createObjectURL(blob);
window.open(blobURL);
};
// 下载
const handleDownLoad = async (row) => {
const res = await downloadDetection({
id: row.id,
});
const blob = new Blob([res], {
type: "application/pdf;chartset=UTF-8",
});
const a = document.createElement("a");
a.style.display = "none";
const URL = window.URL || window.webkitURL;
const herf = URL.createObjectURL(blob);
a.target = "_blank";
a.href = herf;
a.download = row.templateName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
如果没有查看或下载成功,可在接口请求设置以下代码:
// 下载检测报告
export function downloadDetection(data) {
return request({
url: `/obsReport/downloadDetection`,
method: 'post',
data,
responseType: 'arraybuffer' // 关键代码
})
}