php查询数据,输出为base64格式的字符串作为url和文件名,前端直接js下载。
lrEle.postAndDone({
url: '/addons/device/download/exportQxtExcel/deviceId/'+ deviceId,
postData: datas,
successKey: 'code',
successVal: '1',
successFunc: function (res) {
lrBox.noLoading();
let xhr = new XMLHttpRequest();
xhr.open('GET', res.data.file, true);
xhr.setRequestHeader("Content-Type", 'application/json;charset=utf-8');
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
let blob = this.response;
let a = document.createElement('a');
let url = window.URL.createObjectURL(blob);
a.href = url;
a.download = res.data.filename;
a.click();
window.URL.revokeObjectURL(url);
}
};
xhr.send();
},
errFunc: function (res) {
lrBox.noLoading();
lrBox.msgTisf(res.msg);
}
});