$http({ url: url, method: "POST", data: postData, headers: { 'Content-type': 'application/json' }, dataType: "json", responseType: 'arraybuffer' }).success(function (data) {
var blobJudge = new Blob([data]);
//将Blob 对象转换成字符串
var reader = new FileReader();
reader.readAsText(blobJudge, 'utf-8');
reader.onload = function (e) {
var json = eval('(' + reader.result + ')');
console.info(reader.result);
if(json.result=='3016'||json.result=='3015'){
var dataReturn={};
dataReturn.msg = "导出的数据为空";
dataReturn.result = 4000;
returnLoginConfirm(dataReturn, url);
def.resolve(dataReturn);
}else{
//导出excel
var blob = new Blob([data], {type: "application/vnd.ms-excel"});
var objectUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display:none');
a.setAttribute('href', objectUrl);
a.setAttribute('download', fileName);
a.click();
URL.revokeObjectURL(objectUrl);
}
}
}).error(function (err) {
var data = {};
if (err && err.msg && err.result) {
data.msg = err.msg;
data.result = err.result;
} else {
data.msg = "导出的数据为空";
data.result = 4000;
}
returnLoginConfirm(data, url);
def.resolve(data);
});
转载至链接:https://my.oschina.net/u/1052192/blog/1838982