初始提交
This commit is contained in:
44
rg-09112127/js/exportCertificate.js
Normal file
44
rg-09112127/js/exportCertificate.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
导出证书
|
||||
*/
|
||||
|
||||
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";
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user