var SPECIAL_CHARACTERS = [['"', '%22'], ['#', '%23'], ['%', '%25'], ['&', '%26'], ['(', '%28'], [')', '%29'], ['+', '%2B'], [',', '%2C'], [';', '%3B'], ['<', '%3C'], ['=', '%3D'], ['>', '%3E'], ['?', '%3F'], ['@', '%40'], ['\\', '%5C'], ['|', '%7C']]; 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]+$"); //姝e垯琛ㄨ揪寮 var emailvalue = $("#downloadmail").val(); //alert(emailvalue) if (emailvalue) { if (!reg.test(emailvalue)) { //姝e垯楠岃瘉涓嶉€氳繃锛屾牸寮忎笉瀵 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) { console.log("filepath",attachPath); const result = attachPath.replace(/&锛?0;/g, "(").replace(/&锛?1;/g, ")").replace(/&/g, "%26").replace(/\+/g, "%2B"); console.log("result", result); console.log("resp", resp); window.open(encodeURI("/pdfjs/web/viewer.html?file="+result)); } }); } else { if (attachName.includes("zip") || attachName.includes("rar") || attachName.includes("mp4")|| attachName.includes("stp")) { window.open(attachPath); } else { downLoadUrl(attachName, attachPath); } } } else { if (attachName.includes("zip") || attachName.includes("rar") || attachName.includes("mp4")|| attachName.includes("stp")) { window.open(attachPath); } else { downLoadUrl(attachName, attachPath); } } } } function downLoadUrl(fileName, url) { if(url) { for(var i = 0; i < SPECIAL_CHARACTERS.length; i++) { var characterArr = SPECIAL_CHARACTERS[i]; //鐗规畩瀛楃 var specialStr = characterArr[0]; if(url.indexOf(specialStr) > -1) { //闇€瑕佹浛鎹㈢殑瀛楃 var replaceStr = characterArr[1]; url = url.split(specialStr).join(replaceStr); } } fetch(url).then(response => response.blob()).then(blob => { downloadBlobFile(fileName, new Blob([blob], { type: 'application/octet-stream' })) }) } else { alert('娌℃湁闇€瑕佷笅杞界殑鏂囦欢!'); } } function downloadBlobFile(fileName, blob) { if (typeof window.navigator.msSaveBlob !== 'undefined') { // 鍏煎IE锛寃indow.navigator.msSaveBlob锛氫互鏈湴鏂瑰紡淇濆瓨鏂囦欢 window.navigator.msSaveBlob(blob, decodeURI(fileName)) } else { // 鍒涘缓鏂扮殑URL骞舵寚鍚慒ile瀵硅薄鎴栬€匓lob瀵硅薄鐨勫湴鍧€ const blobURL = window.URL.createObjectURL(blob) // 鍒涘缓a鏍囩锛岀敤浜庤烦杞嚦涓嬭浇閾炬帴 const tempLink = document.createElement('a') tempLink.style.display = 'none' tempLink.href = blobURL tempLink.setAttribute('download', decodeURI(fileName)) // 鍏煎锛氭煇浜涙祻瑙堝櫒涓嶆敮鎸丠TML5鐨刣ownload灞炴€ 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) } }