map = {
searchType: searchType,
searchName: searchName,
createTime: createTime,
category: category,
customerStatus: where.customerStatus
}
url = layui.setter.base_server + "api/cybank/customer/exportList"; //请求的URl
xhr = new XMLHttpRequest(); //定义http请求对象
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json;charset=utf-8");
xhr.setRequestHeader("authorization", layui.user.getAccessToken());
xhr.setRequestHeader("client-key", layui.user.initClientKey());
xhr.send(JSON.stringify(map));
xhr.responseType = "blob"; // 返回类型blob
xhr.onload = function () { // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
if (this.status === 200) {
var blob = this.response;
var reader = new FileReader();
reader.readAsDataURL(blob); // 转换为base64,可以直接放入a表情href
reader.onload = function (e) {
// console.log(e); //查看有没有接收到数据流
// 转换完成,创建一个a标签用于下载
var a = document.createElement('a');
a.download = "客户信息导出" + Date.parse(new Date()) + ".xlsx"; //自定义下载文件名称
a.href = e.target.result;
$("body").append(a); // 修复firefox中无法触发click
a.click();
$(a).remove();
utils.successMsg("导出成功,请稍等一会");
}
} else {
alert("出现了未知的错误!");
}
}