Files
RGKT/rg-09112127/js/exportCertificate.js
2025-10-10 19:44:14 +08:00

44 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
导出证书
*/
function showCertificate() {
// 获取dom
let certificateDom = document.querySelector('.box-certificate');
certificateDom.style.display = certificateDom.style.display == "block" ? "none" : "block";
let certificateNameDom = document.querySelector('.box-certificate-name>span');
let classInfo = getClassInfo();
certificateNameDom.innerText = classInfo.thank.name;
let mainVideoDom = document.getElementById("mainVideo");
mainVideoDom.pause();
// 控制按钮展示
const buttonDom = document.getElementsByClassName('box-btn')[0];
buttonDom.style.display = 'none';
}
function exportCertificate() {
// 获取dom
let certificateDom = document.querySelector('.box-certificate');
// 创建dom
let canvas = document.createElement('canvas');
let ctx = canvas.getContext('2d');
// 设置dom尺寸
canvas.width = certificateDom.offsetWidth;
canvas.height = certificateDom.offsetHeight;
// 调用 html2canvas 方法创建一个下载链接将dom转成base64下载
html2canvas(certificateDom).then(function (canvas) {
let imgData = canvas.toDataURL('image/png');
let link = document.createElement('a');
link.download = '鸣谢证书.png';
link.href = imgData;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
certificateDom.style.display = "none";
});
}