思路
将整个body的内容替换为弹窗的内容,打印操作完成之后还原
echarts打印时未显示,通过将其转为img的方法进行打印
print() { var that = this; var oldstr = document.body.innerHTML; var div_print = document.getElementById("printTest"); var cv = document.getElementsByTagName("canvas")[0]; var resImg = document.getElementsByClassName("resImg")[0]; var context = cv.getContext("2d"); var img = new Image(); var strDataURI = cv.toDataURL("image/png"); img.src = strDataURI; img.onload = function() { console.log(img); setTimeout(function() { resImg.innerHTML = `<img src="${strDataURI}">`; var newstr = div_print.innerHTML; document.body.innerHTML = newstr; window.print(); window.location.reload(); document.body.innerHTML = oldstr; }, 1000); }; },
|