import JSZip from 'jszip';
import FileSaver from 'file-saver';
import JSZipUtils from 'jszip-utils'
downLoadPics = async (record) => {
let pics = record.pics
let len = pics.length
if (len <= 0) {
message.info("该报告暂无图片")
return;
}
let links = []
for (let i = 0; i < len; i++) {
let imageUrl = pics[i].imageUrl
if (typeof (imageUrl) !== 'undefined' && imageUrl !== null && imageUrl.length > 0)
links.push(imageUrl)
}
let zip = new JSZip()
let count = 0
let zipFilename = record.reportId + "诊断报告"
links.forEach(function (url, i) {
var filename = '诊断' + record.reportId + '图片' + (i + 1) + ".png";
JSZipUtils.getBinaryContent(url, function (err, data) {
if (err) {
throw err;
}
zip.file(filename, data, { binary: true });
count++;
if (count == links.length) {
zip.generateAsync({ type: 'blob' }).then(function (content) {
FileSaver.saveAs(content, zipFilename);
});
}
});
});
}