当前位置: 首页 > Web前端 > vue.js

vue-一些常用工具

时间:2023-03-31 21:25:02 vue.js

本文介绍一些常用工具1、验证码如下图所示。一般的后台管理系统在登录的时候都会设计一个验证码,这个验证码是前端生成的。单击画布以切换验证码。二维码的类型是数字还是字母,您可以根据需要设置。1、验证码的js如下图所示。首先,验证码的jsverifyCode代码介绍如下,可以根据需要修改长宽(_init方法中的宽高)。验证码的类型、颜色、干扰线等。functionGVerify(options){//创建图形验证码对象,接收options对象作为参数this.options={//默认options参数值id:'',//容器IdcanvasId:'verifyCanvas',//ofcanvasIDwidth:'100',//默认画布宽度height:'38',//默认画布高度type:'number',//默认图形验证码类型blend:数字和字母混合类型,number:purenumber,letter:Purelettercode:''}if(Object.prototype.toString.call(options)==='[objectObject]'){//判断传入参数的类型for(variinoptions){//根据传入参数,修改默认参数值this.options[i]=options[i]}}else{this.options.id=options}this.options.numArr='0,1,2,3,4,5,6,7,8,9'.split(',')this.options.letterArr=getAllLetter()this._init()this.refresh()}GVerify.prototype={/**版本号**/version:'1.0.0',/**初始化方法**/_init:function(){varcon=document.getElementById(this.options.id)varcanvas=document.createElement('canvas')//this.options.width=con.offsetWidth>0?con.offsetWidth:'30'//this.options.height=con.offsetHeight>0?con.offsetHeight:'30'this.options.width='100'this.options.height='38'canvas.id=this.options.canvasIdcanvas.width=this.options.widthcanvas.height=this.options.heightcanvas.style.cursor='pointer'canvas.innerHTML='您的浏览器版本不支持canvas'con.appendChild(canvas)varparent=thiscanvas.onclick=function(){parent.refresh()}},/**生成验证码**/refresh:function(){this.options.code='';varcanvas=document.getElementById(this.options.canvasId)if(canvas.getContext){varctx=canvas.getContext('2d')}ctx.textBaseline='middle'ctx.fillStyle=randomColor(180,240)ctx.fillRect(0,0,this.options.width,this.options.height)让txtArr='';if(this.options.type==='blend'){//判别验证码类型txtArr=this.options.numArr.concat(this.options.letterArr)}elseif(this.options.type==='number'){txtArr=this.options.numArr}else{txtArr=this.options.letterArr}for(vari=1;i<=4;i++){vartxt=txtArr[randomNum(0,txtArr.length)]this.options.code+=txtctx.font=randomNum(this.options.height/2,this.options.height)+'pxSimHei'//随机生成字体大小ctx.fillStyle=randomColor(50,160)//随机生成字体颜色ctx.shadowOffsetX=randomNum(-3,3)ctx.shadowOffsetY=randomNum(-3,3)ctx.shadowBlur=randomNum(-3,3)ctx.shadowColor='rgba(0,0,0,0.3)'varx=this.options.width/5*ivary=this.options.height/2vardeg=randomNum(-30,30)/**设置旋转角度和坐标原点**/ctx.translate(x,y)ctx.rotate(deg*Math.PI/180)ctx.fillText(txt,0,0)/**恢复旋转角度和坐标原点**/ctx.rotate(-deg*Math.PI/180)ctx.translate(-x,-y)}/**绘制干扰线**/for(leti=0;i<4;i++){ctx.strokeStyle=randomColor(40,180)ctx.beginPath()ctx.moveTo(randomNum(0,this.options.width),randomNum(0,this.options.height))ctx.lineTo(randomNum(0,this.options.width),randomNum(0,this.options.height))ctx.stroke()}/**绘制干扰点**/for(leti=0;i

{{codeMsg}}复制代码验证码验证规则constvalidateCode=(规则、值、回调)=>{让verifyFlag=this.verifyCode.validate(value);if(!verifyFlag){callback(newError('验证码输入错误'));}else{回调()}};验证码验证规则loginRules:{verifyCode:[{required:true,message:'verificationThecodecannotbeempty'},{validator:validateCode,trigger:'change'}]CopyCode2:返回中心点数组根据一组坐标[latitude,latitude]主要用于根据一组坐标点计算地图的中心点,打开地图时,点在地图的中间/**根据一组坐标[latitude,latitude]返回中心点数组[latitude,latitude]@parampoints@returns{number[]}*/exportfunctiongetPointsCenter(点){varpoint_num=点。长度;//坐标点个数varX=0,Y=0,Z=0;for(leti=0;i0){letmaxLng=points[0].longitude;让minLng=points[0].longitude;让maxLat=points[0].latitude;让minLat=points[0].latitude;让水库;for(leti=points.length-1;i>=0;i--){res=points[i];如果(res.longitude>maxLng)maxLng=res.longitude;如果(res.longitudemaxLat)maxLat=res.latitude;)minLat=res.latitude;}letzoom=["50","100","200","500","1000","2000","5000","10000","20000","25000","50000","100000","200000","500000","1000000","2000000"];//18级到3级。让pointA=newwindow.TMap.LatLng(maxLat,maxLng);//创建点坐标AletpointB=newwindow.TMap.LatLng(minLat,minLng);//创建点坐标Bletdistance=window.TMap.geometry.computeDistance([pointA,pointB]).toFixed(1);//获取两点之间的距离,保留两位小数for(leti=0,zoomLen=zoom.length;i0){return18-i+3;//之所以多了3个,是因为地图范围往往是比例尺距离的10倍以上。所以等级会增加3。}}}}复制代码以上就是最近用到的工具,希望对大家有所帮助,记录一下,温故知新!!!最后,如果您觉得这篇文章对您有点帮助,请点个赞。或者可以加入我的开发交流群:1025263163互相学习,我们会有专业的技术解答。如果您觉得这篇文章对您有用,请给我们的开源项目一个小星星:https://gitee。com/ZhongBangKe...非常感谢!