function mailValid(){ //alert(downloadmail) $("#downloadmailerrortip").html(""); var errortip = ""; //^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$ //^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$ var reg = new RegExp("^[a-z0-9A-Z]+([._\\-]*[a-z0-9A-Z])*@([a-zA-Z0-9]+[-a-z0-9A-Z]*[a-z0-9A-Z]+.){1,63}[a-z0-9A-Z]+$"); //正则表达式 var emailvalue = $("#downloadmail").val(); //alert(emailvalue) if(emailvalue){ if(!reg.test(emailvalue)){ //正则验证不通过,格式不对     errortip = "邮箱格式不正确!"; } }else{ errortip = "请输入您的邮箱!";   } if(errortip){ $("#downloadmailerrortip").html(errortip); return false; }else{ return true; //return false; } } function downLoadWinClose(){ //$("#downloadtomailwin").css("display","none"); $('#dialogBg5').fadeOut(300, function () { $('#dialog5').addClass('bounceOutUp').fadeOut(); }); } /** * */ function downLoadWinShow(thisp,fileUrl,fileName){ className = $(thisp).attr('class'); $('#dialogBg5').fadeIn(300); $('#dialog5').removeAttr('class').addClass('animated ' + className + '').fadeIn(); //$("#downloadtomailwin").css("display",""); $("#downloadfileurl").val(fileUrl); $("#downloadfilename").val(fileName); } function downLoadLinkToMail(){ var downloadfileurl = $("#downloadfileurl").val(); var fileName = $("#downloadfilename").val(); var mailCheck = mailValid(); if(mailCheck){ var emailvalue = $("#downloadmail").val(); submitLinkToMail(emailvalue,downloadfileurl,fileName); } } function submitLinkToMail(emailvalue,downloadfileurl,fileName){ $("#downLoadLinkToMailbtn").attr('disabled',true); $.ajax({ type: "post", url: "/sendFileToMail.jspx", data: { emailvalue : emailvalue, fileName : fileName, fileUrl : downloadfileurl }, dataType: "json", success: function(data){ //$("#downLoadLinkToMailbtn").attr('disabled',"false"); $('#downLoadLinkToMailbtn').removeAttr("disabled"); if(data.success=='1'){ alert("发送成功!"); downLoadWinClose(); }else{ alert("发送失败!"); } }, failure :function(){ //$("#downLoadLinkToMailbtn").attr('disabled',"false"); $('#downLoadLinkToMailbtn').removeAttr("disabled"); alert("发送失败,请联系管理员!"); } }); } function downLoadByName(attachName,attachPath,atype){ //attachPath = "/u/cms/www/111.pdf" $.ajax({ type: 'POST', url: "/updateDownLoadCount.jspx", data: { attachName : attachName, attachPath : attachPath, atype : atype }, success: function(resp){ } }); if(attachPath && attachPath.indexOf("http")<0){ attachName = encodeURIComponent(attachName.trim()); if(atype == 1){ if(attachPath.indexOf(".pdf")>=0 || attachPath.indexOf(".PDF")>=0 ){ window.open("/downloadByName.jspx?isPreview=Y&filePath="+attachPath+"&fileName="+attachName+"&t=" + new Date()); }else{ window.open(attachPath); } }else{ //下载 window.open("/downloadByName.jspx?filePath="+attachPath+"&fileName="+attachName+"&t=" + new Date()); } } else { console.log("执行接口"); if(atype == 1){ if(attachPath.indexOf(".pdf")>=0 || attachPath.indexOf(".PDF")>=0 ){ $.ajax({ type: 'POST', url: "/previewOrDownload.jspx", data: { filePath : attachPath, isPreview : "Y", }, success: function(resp){ const result = resp.replace(/&#40;/g, "(").replace(/&#41;/g, ")"); console.log("result",result); console.log("resp",resp); window.open(result); } }); }else{ downLoadUrl(attachName,attachPath); // window.open(attachPath); } }else{ //下载 downLoadUrl(attachName,attachPath); } } } function downLoadUrl(fileName, url) { fetch(url).then(response => response.blob()).then(blob => { downloadBlobFile(fileName, new Blob([blob], { type: 'application/octet-stream' })) }) } function downloadBlobFile(fileName, blob) { if (typeof window.navigator.msSaveBlob !== 'undefined') { // 兼容IE,window.navigator.msSaveBlob:以本地方式保存文件 window.navigator.msSaveBlob(blob, decodeURI(fileName)) } else { // 创建新的URL并指向File对象或者Blob对象的地址 const blobURL = window.URL.createObjectURL(blob) // 创建a标签,用于跳转至下载链接 const tempLink = document.createElement('a') tempLink.style.display = 'none' tempLink.href = blobURL tempLink.setAttribute('download', decodeURI(fileName)) // 兼容:某些浏览器不支持HTML5的download属性 if (typeof tempLink.download === 'undefined') { tempLink.setAttribute('target', '_blank') } // 挂载a标签 document.body.appendChild(tempLink) tempLink.click() document.body.removeChild(tempLink) // 释放blob URL地址 window.URL.revokeObjectURL(blobURL) } }