forked from nsjcy/frontEnd/nsjcy

1
liuwh
2020-03-05 c79f4fea5045445c40cd417c3bdcf78c843f87ae
1
"use strict";var randomNum=function(t,e){return Math.floor(Math.random()*(e-t)+t)},randomColor=function(t,e){var a=randomNum(t,e),r=randomNum(t,e),o=randomNum(t,e);return"rgb(".concat(a,", ").concat(r,", ").concat(o,")")},render=function(t,e){var a=1<arguments.length&&void 0!==e?e:{},r=a.str,o=a.num,n=a.width,i=a.height,l=a.bgColor,u=a.fontColor,m=a.hasPoint,d=a.hasLine,h="";"function"==typeof t.setTextBaseline&&t.setTextBaseline("bottom"),t.setFillStyle(l||randomColor(180,240)),t.fillRect(0,0,n,i);for(var s=0;s<o;s++){var c=(n-10)/o*s+10,v=randomNum(i/2,i),f=randomNum(-45,45),g=r[randomNum(0,r.length)],N=randomNum(16,40),p=parseInt(i/2);h+=g,t.setFillStyle(u||randomColor(10,100)),t.setFontSize(p<N?p:N),t.translate(c,v),t.rotate(f*Math.PI/180),t.fillText(g,0,0),t.rotate(-f*Math.PI/180),t.translate(-c,-v)}if(d)for(var y=0;y<o;y++)t.setStrokeStyle(randomColor(90,180)),t.beginPath(),t.moveTo(randomNum(0,n),randomNum(0,i)),t.lineTo(randomNum(0,n),randomNum(0,i)),t.stroke();if(m)for(var x=0;x<10*o;x++)t.setFillStyle(randomColor(0,255)),t.beginPath(),t.arc(randomNum(0,n),randomNum(0,i),1,0,2*Math.PI),t.fill();return h};Component({properties:{str:{type:String,value:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},num:{type:Number,value:6},width:{type:Number,value:120},height:{type:Number,value:40},bgColor:{type:String,value:""},fontColor:{type:String,value:""},hasPoint:{type:Boolean,value:!0},hasLine:{type:Boolean,value:!0},canvasId:{type:String,value:"wux-vcode"}},methods:{draw:function(){var t=this,e=this.data,a=e.width,r=e.height,o=e.canvasId;this.ctx=this.ctx||wx.createCanvasContext(o,this),this.ctx.clearRect(0,0,a,r);var n=render(this.ctx,this.data);this.ctx.draw(!1,function(){return t.triggerEvent("change",{value:n})})}},attached:function(){this.draw()},detached:function(){this.ctx=null}});