var reason = ''; var shareImgUrl = ''; var currentdate= '' var jsons = {}; $().ready(function() { if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){ //微信 $(".long").css({ "display":"block", "position":"absolute", "top":"4.9rem", "left":"1.5rem" }) $(".leave_share").css("display","none") $("#curTpl").css("top","1.04rem") }else{ //app端 $(".leave_share").css("display","block") } shareFriend (); getNowFormatDate(); // 我要请假 $(".leaveInfo_submit").click(function(){ $(".container2").height($(".leaveImg").height()+100) var name = $("#name").val(); var department = $("#department").val(); var company = $("#company").val(); var sex= $('input:radio[name="sex"]:checked').val(); var time =$("#date1").text().split('至') var timeStart = time[0]; var timeEnd = time[1]; // console.log(name,department,company,time,sex) //判断填写内容 if(name.length == 0){ showMsg('姓名不能为空') return; }else if(name.length < 1 || name.length > 5){ showMsg('姓名请输入1到5个字') return; }else if(department == 0){ showMsg('部门不能为空') return; }else if (department.length < 2 || department.length >5){ showMsg('部门请输入2到5个字') return; }else if(company == 0){ showMsg('公司不能为空') return; }else if(company.length < 3 || company.length > 16){ showMsg('公司请输入3到16个字') return; } else if(sex == undefined || sex == null){ showMsg('请选择性别') return; } getReason(); $('.userName').html(name) $('.userDepartment').html(department) $('.timeStart').html(timeStart) $('.timeEnd').html(timeEnd) $('.container').css("display","none"); $('.container2').css("display","block"); $('.leaveImg').css("display","block"); if(company != ""){ $(".leave_reason_img img").attr("src",'/api/V2/createLeave?company=' + company); } // canvas绘制图像的原点是canvas画布的左上角 var canvasOne = document.getElementsByClassName("canvas")[0]; var canvasTwo = document.getElementsByClassName("canvas")[1]; getCanvas(canvasOne) getCanvas(canvasTwo) function getCanvas (canvas){ var context = canvas.getContext('2d'); drawText($("#company").val()); // 绘制圆形印章 function drawText(companyName="酷炫") { // 清除画布法一 context.globalAlpha=1; context.fillStyle="rgba(255,255,255,.0)"; context.fillRect(0,0,110,110); var text = "请假专用章"; var companyName = companyName; // 绘制印章边框 var width = canvas.width / 2; var height = canvas.height / 2; context.lineWidth = 2.5; context.strokeStyle = "#f00"; context.beginPath(); context.arc(width, height, 53, 0, Math.PI * 2);//宽、高、半径 context.stroke(); //画五角星 create5star(context,width,height,15,"#f00",0); // 绘制印章名称 context.font = '8px 宋体'; context.textBaseline = 'middle';//设置文本的垂直对齐方式 context.textAlign = 'center'; //设置文本的水平对对齐方式 context.lineWidth=1; context.fillStyle = '#f00'; context.save(); context.translate(width,height+35);// 平移到此位置, context.scale(1,2);//伸缩要先把远点平移到要写字的位置,然后在绘制文字 context.fillText(text,0,0);//原点已经移动 context.restore(); // 绘制印章单位 context.translate(width,height);// 平移到此位置, context.font = '10px 宋体' var count = companyName.length;// 字数 if(count>=8){ var angle = 4*Math.PI/(3*(count-1));// 字间角度 }else if(count==7){ context.rotate((2.25)*Math.PI);// 旋转90度,让字出现在中间 var angle = Math.PI/((count));// 字间角度 }else if(count<=3){ context.rotate(Math.PI/2);// 旋转90度,让字出现在中间 var angle = (1/6)*Math.PI;// 字间角度 }else{ context.rotate((2.3)*Math.PI);// 旋转90度,让字出现在中间 var angle = Math.PI/((count));// 字间角度 } // var angle = 4*Math.PI/(3*(count - 1));// 字间角度 var chars = companyName.split(""); var c; for (var i = 0; i < count; i++) { c = chars[i];// 需要绘制的字符          //绕canvas的画布圆心旋转 if (i == 0) { context.rotate(5 * Math.PI / 6); } else{ context.rotate(angle); } context.save(); context.translate(40, 0);// 平移到此位置,此时字和x轴垂直,公司名称和最外圈的距离 context.rotate(Math.PI / 2);// 旋转90度,让字平行于x轴 context.scale(1,2);//伸缩画布,实现文字的拉长 context.fillText(c, 0, 0);// 此点为字的中心点 context.restore(); } // 设置画布为最初的位置为原点,旋转回平衡的原位置,用于清除画布 context.rotate(-Math.PI/6); context.translate(0-canvas.width/2,0-canvas.height/2); //绘制五角星 function create5star(context, sx, sy, radius, color, rotato) { context.save(); context.fillStyle = color; context.translate(sx, sy);//移动坐标原点 context.rotate(Math.PI + rotato);//旋转 context.beginPath();//创建路径 var x = Math.sin(0); var y = Math.cos(0); var dig = Math.PI / 5 * 4; for (var i = 0; i < 5; i++) {//画五角星的五条边 var x = Math.sin(i * dig); var y = Math.cos(i * dig); context.lineTo(x * radius, y * radius); } context.closePath(); context.stroke(); context.fill(); context.restore(); } } } }) // 换个理由 $('.leave_change').click(function(){ var scrollTop = $(window).scrollTop(); $(".leaveImg").css("top",scrollTop); $('.leaveImg').css({ "display":"block" }); $("#curTpl").css("display","block") getReason(); }) }) //获取理由 function getReason(){ var scrollTop = $(window).scrollTop(); $(".leaveImg").css("top",scrollTop); $.ajax({ type:"get", url:"/api/V2/getReason", dataType:'json', success: function (res) { console.log(res) reason = res.res $('.reason').html(reason) //第一次生成图片 var dom=$(".leaveImg"); //你要转变的dom var width = dom.width(); var height = dom.height(); var type = "png"; var scaleBy = 3; //缩放比例 var canvas = document.createElement('canvas'); canvas.width = width * scaleBy; canvas.height = height * scaleBy; canvas.style.width = width * scaleBy + 'px'; canvas.style.height = height * scaleBy + 'px'; var context = canvas.getContext('2d'); context.scale(scaleBy, scaleBy); html2canvas(dom, { canvas:canvas, onrendered: function (canvas) { var url = canvas.toDataURL();//图片地址 $("#curTpl").attr('src',url) $("#curTpl").css("display","block") $(".leaveImg").css({ "display":"none", "z-index":"-11" }); shareImgUrl = url.split(',') jsons ={shareImageBase64Str:shareImgUrl[1] } // $("#generate_success").css("width",width+"px").css("height",height+"px");//在将放大的图片用css缩小,在手机上就非常清晰了 } }); // html2canvas($(".leaveImg"), {scale:2,logging:false,useCORS:true}).then(function(canvas){ // var url = canvas.toDataURL();//图片地址 // $("#curTpl").attr('src',url) // $("#curTpl").css("display","block") // $(".leaveImg").css({ // "display":"none", // "z-index":"-11" // }); // shareImgUrl = url.split(',') // jsons ={shareImageBase64Str:shareImgUrl[1] } // }) } }) } function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); // console.log(currentdate) return currentdate; } // 日历 var dateRange1 = new pickerDateRange('date1', { stopToday : false, isTodayValid : true, startDate: '2018-09-21', endDate: '2018-09-22', needCompare : false, defaultText : '至', autoSubmit : false, inputTrigger : 'input_trigger1', theme : 'ta' }); // 分享 var userId = 0; var flag = true; var str=location.href; //取得整个地址栏 var num=str.indexOf("?"); str=str.substr(num+1); //str得到?之后的字符串 var brr=str.split("&"); for(var i = 0 ; i { // 分享成功 $(".shareMask").css('display','none') },() => { showMsg("分享失败") flag = false; },() => { //微信审核为通过 flag = false; }) }else{ flag = false; } if(!flag){ //分享不成功 setTimeout(function () { $(".shareMask").css('display','none') },3000) } } }) }