//下载弹层 function bigHaibao() { var imgUrl = $('.swiper-wrapper .swiper-slide-active img').attr('src') + '?=v1'; var date =$("#publishDateTime").html(); var week = getWeekBig($("#NewsArticleTime").html()); //星期 console.log($("#publishDateTime").html()); var html = '
' + '
' + '
' + ' ' + '
' + date +'   ' + week +'
' + '
' + ' ' + ' ' + '
' + '
' + '' + '
' + ''; $('.synthPage').append(html); var url = window.location.href; var index = url.substring(0, url.lastIndexOf('/') + 1); console.log(index + '?' + getCaption()) $('body').find('#qrcode').qrcode({ render: 'canvas', width: 180, height: 180, // margin: '0 auto', text: index + '?' + getCaption() }); document.getElementById('qcImg').src = document.querySelector('canvas').toDataURL("image/webp"); synthesisImgLoadBig(); $('.tipsBtn').unbind("touchstart"); $('.tipsBtn').unbind("touchend"); $('.tipsBtn').bind("touchstart", function () { $(this).hide(); }); $('.tipsBtn').bind("touchend", function () { $(this).show(); }); } //判断图片是否加载完成 function synthesisImgLoadBig() { var img = $('.synthPage .synthPaper'); if (img && img.length != 0) { if (img[0].complete) { var synBoxH = $('#synthWrap').height(); var imgH = $('#synthWrap').height() - 100; $('#synthWrap>img.synthPaper').css('max-height', imgH + 'px'); $('#qrcode').hide() synthesisImgBig(); } else { setTimeout(function () { synthesisImgLoadBig() }, 300); } } else { setTimeout(function () { synthesisImgLoadBig() }, 300); } } //生成图片 function synthesisImgBig() { //clearInterval(synthesisImgLoadBig) var canvas = document.createElement('canvas'); // 创建一个canvas节点 var shareContent = document.getElementById('synthWrap'); // 需要截图的包裹的(原生的)DOM 对象 var width = shareContent.offsetWidth; // 获取dom 宽度 var height = shareContent.offsetHeight; // 获取dom 高度 var scale = 1.5; // 定义任意放大倍数 支持小数 canvas.getContext('2d').scale(scale, scale); // 获取context,设置scale var rect = shareContent.getBoundingClientRect(); // 获取元素相对于视口的 html2canvas(document.getElementById('synthWrap'), { x: rect.left, // 绘制的dom元素相对于视口的位置 y: rect.top, width: width, // dom 原始宽度 height: height, windowWidth: document.body.scrollWidth, windowHeight: document.body.scrollHeight, // x: 0, // y: 0, useCORS: true, // 开启跨域 dpi: window.devicePixelRatio * 2, scale: scale, // 添加的scale 参数 }).then((canvas) => { var context = canvas.getContext('2d') //关闭抗锯齿 context.mozImageSmoothingEnabled = false context.msImageSmoothingEnabled = false context.imageSmoothingEnabled = false $('#synthImg img').attr('src', canvas.toDataURL()); $('#synthWrap').hide(); $('#synthImg').show(); $('.synthPage .synthmask').hide(); $('.saveTipsBtn').show(); }) } //星期日期计算 function getWeekBig(timedat) { //timedat参数格式: "2018-09-11" let t = new Date(timedat); let week; if (t.getDay() === 0) week = "星期日"; if (t.getDay() === 1) week = "星期一"; if (t.getDay() === 2) week = "星期二"; if (t.getDay() === 3) week = "星期三"; if (t.getDay() === 4) week = "星期四"; if (t.getDay() === 5) week = "星期五"; if (t.getDay() === 6) week = "星期六"; return week; }; //判断当前时间和报纸刊期之间的时间差。 如在MaxshowData天内,返回true,否则返回false // type=1,忽略dtStartStr,日期根据浏览器地址获取;type=2,根据前一个参数,格式(YYYY/MM/DD) function DateMaxDiffBig(type, dtStartStr) { if (!ifMaxShowDate) { return true; } var maxinterval = MaxshowData;//允许看的天数 var re = /(\d{4})-(\d{2})\/(\d{2})/i; var sUrl = location.href; var r = sUrl.match(re); var dtEnd = new Date(); var dtStart; if (type == 1) { if (r) { dtStart = new Date(r[1] + "/" + r[2] + "/" + r[3]); } else { dtStart = new Date(); } } else if (type == 2) { dtStart = new Date(dtStartStr); if (isNaN(dtStart)) dtStart = new Date(); } var date3 = dtEnd.getTime() - dtStart.getTime(); //时间差的毫秒数 var days = Math.floor(date3 / (24 * 3600 * 1000));//计算出相差天数 if ((days) >= maxinterval) { return false; } else { return true; } }