filesbox/web/dist/design/designstatic/common/js/commonShare/commonPicShare.js

2 lines
21 KiB
JavaScript
Raw Permalink Normal View History

2024-07-26 06:10:54 +00:00
function getImage(t,i){var o=new XMLHttpRequest;o.open("get",t,!0),o.responseType="blob",o.onload=function(){this.status==200&&i&&i(URL.createObjectURL(this.response))},o.send(null)}CanvasRenderingContext2D.prototype.roundRect=function(t,i,o,d,c,n,r,h){c&&!n&&!r&&!h&&(n=c,r=c,h=c);var l=Math.min(o,d);return c>l/2&&(c=l/2),n>l/2&&(n=l/2),r>l/2&&(r=l/2),h>l/2&&(h=l/2),this.beginPath(),this.moveTo(t+c,i),this.arcTo(t+o,i,t+o,i+d,c),this.arcTo(t+o,i+d,t,i+d,n),this.arcTo(t,i+d,t,i,r),this.arcTo(t,i,t+o,i,h),this},CanvasRenderingContext2D.prototype.wrapText=function(t,i,o,d,c,n){if(!(typeof t!="string"||typeof i!="number"||typeof o!="number")){var r=this,h=r.canvas;typeof d=="undefined"&&(d=h&&h.width||300),typeof n=="undefined"&&(n=h&&parseInt(window.getComputedStyle(h).lineHeight)||parseInt(window.getComputedStyle(document.body).lineHeight));for(var l=t.split(""),e="",g=0;g<l.length;g++){var s=e+l[g],x=r.measureText(s),a=x.width;a>d&&g>0?(r.fillText(e,i,o),e=l[g],o+=n):e=s}r.fillText(e,i,o)}};function shareMsg(t){var i='<div class="share-msg" style="z-index: 10001"></div>';$("body").append(i),$(".share-msg").html(t),$(".share-msg").show(),setTimeout(function(){$(".share-msg").hide(),$(".share-msg").remove()},2e3)}var drawImg=function(t,i){var o=t.find(function(e){return e.code==="qrCode"});if(o){if(o.text||(o.text=window.location.href),!document.getElementById("code"))return;var d=new QRCode(document.getElementById("code"),{text:o.text,width:104,height:104,correctLevel:QRCode.CorrectLevel.L});d.makeCode(o.text)}var c=document.getElementById("canvas"),n=c.getContext("2d");n.textBaseline="top",n.save();function r(e,g,s,x,a,f,v){if(e){v&&v.type==="circle"&&(n.save(),n.beginPath());var u=new Image;u.setAttribute("crossOrigin","Anonymous"),u.src=e,u.onload=function(){if(v&&v.type==="circle"){var w=v.r,b=2*w,y=g+w,p=s+w;n.arc(y,p,w,0,2*Math.PI),n.clip(),n.drawImage(u,g,s,x,a),n.restore()}else n.drawImage(u,g,s,x,a);f&&f()},u.onerror=function(){shareMsg("\u56FE\u7247\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u5C1D\u8BD5\uFF01"),f&&f()}}else f&&f()}var h=0;function l(e){if(h++,h<=t.length)if(e.code=="course")try{var g=new Image;g.setAttribute("crossOrigin","Anonymous"),g.src=e.text,g.width=e.width,g.height=e.height,g.onload=function(){e.rotate?(n.save(),n.beginPath(),n.rotate(-e.rotate*Math.PI/180),r(e.text,e.x,e.y,e.width,e.height,function(){n.restore(),l(t[h])})):(typeof e.radius!="object"&&(e.radius={}),n.roundRect(e.x,e.y,e.width,e.height,e.radius.right||0,e.radius.bottom||0,e.radius.left||0,e.radius.top||0),n.clip(),r(e.text,e.x,e.y,e.width,e.height,function(){n.restore(),l(t[h])}))}}catch(a){l(t[h]),console.log(a)}else if(e.code==="avatar")try{e.radius?(n.save(),n.beginPath(),typeof e.radius=="number"&&e.radius!==NaN?e.radius={top:e.radius,right:e.radius,bottom:e.radius,left:e.radius}:(typeof e.radius!="object"||e.radius===null||e.radius instanceof Array)&&(e.radius={}),n.roundRect(e.x,e.y,e.width,e.height,e.radius.right||0,e.radius.bottom||0,e.radius.left||0,e.radius.top||0),n.clip(),r(e.text,e.x,e.y,e.width,e.height,function(){n.restore(),l(t[h])})):r(e.text,e.x,e.y,e.width,e.height,function(){l(t[h])},{type:"circle",r:e.width/2})}catch(a){l(t[h]),console.log(a)}else if(e.code==="qrCode"){var s="";if($("#code img").attr("src"))s=$("#code img").attr("src");else{var x=document.querySelector("#code canvas");s=x&&x.toDataURL("image/png")}try{r(s,e.x,e.y,e.width,e.height,function(){l(t[h])})}catch(a){l(t[h]),console.log(a)}}else if(e.code==="block")n.rect(e.x,e.y,e.width,e.height),n.fillStyle="#"+e.color,n.fillRect(e.x,e.y,e.width,e.height),l(t[h]);else if(e.font)n.font=e.size+"px "+e.font,e.bold&&(n.font=n.font+" bold"),n.fillStyle="#"+e.color,e["text-align"]==="left"?n.textAlign="left":e["text-align"]==="center"?n.textAlign="center":e["text-align"]==="right"?n.textAlign="right":e["text-align"]==="start"?n.textAlign="start":e["text-align"]==="end"?n.textAlign="end":n.textAlign="start",e.rotate?(n.save(),n.beginPath(),n.rotate(-e.rotate*Math.PI/180),e.lineHeight?(n.wrapText(e.text,e.x,e.y,e.width,e.height,e.lineHeight),n.