var saleTime = row.saleTime; var date = new Date(saleTime); console.log(saleTime); var fileName = this.dateFormat(date, "yyyyMMddhhssmm") + ".jpg"; var url = Kit.remote + "/admin/v1/pf/prescription/downImage?id=" + row.id; var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.responseType = "blob"; xhr.setRequestHeader("Authorization", Kit.getToken()); xhr.onload = function () { if (this.status === 200) { var blob = null; try { blob = this.response; var href = window.URL.createObjectURL(blob); var a = document.createElement('a'); a.download = fileName; a.href = href; document.body.appendChild(a); a.click(); //点击下载 document.body.removeChild(a); } catch (e) { } if (blob != null) { Kit.Notice.success({ title: "下载成功" }); } else { Kit.Notice.error({ title: "下载失败" }); } } else { Kit.Notice.error({ title: "下载失败" }); } }; xhr.send();
ajax 下载文件
最新推荐文章于 2024-03-28 17:49:22 发布