angularjs 服务端下载execl
2021-01-14 19:11
标签:href download out action disable int move har child html js angularjs 服务端下载execl 标签:href download out action disable int move har child 原文地址:https://www.cnblogs.com/yiyangl/p/13406164.htmlbutton class="btn btn-sm btn-primary pull-right" ng-click="exportData($event)">i class="fa fa-spinner fa-pulse hidden">i>导出表格button>
//导出数据
$scope.exportData = function(e) {
var arr = e.target.children[0].className.split(‘ ‘);
var index = arr.indexOf(‘hidden‘);
arr.splice(index, 1);
e.target.children[0].className = arr.join(‘ ‘);
e.target.disabled = true;
function resetBtn(e) {
e.target.children[0].className = e.target.children[0].className + ‘ hidden‘;
e.target.disabled = false;
}
$http({
method: ‘get‘,
url: $scope.baseUrl + ‘sampleCenter/reception?part=seek&action=exportExcel‘,
responseType: ‘arraybuffer‘
}).then(function(response) {
if (response.headers()[‘content-type‘] == ‘text/html; charset=utf-8‘) {
var encode = new TextDecoder(‘utf-8‘);
var data = JSON.parse(encode.decode(new Uint8Array(response.data)));
if (data.error) {
toaster.pop({
type: ‘error‘,
body: data.error,
timeout: 0
});
resetBtn(e);
}
} else {
var blob = new Blob([response.data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
var objectUrl = URL.createObjectURL(blob);
var a = document.createElement(‘a‘);
a.href = objectUrl;
a.target = ‘_blank‘;
a.download = ‘表格‘;
document.body.append(a);
a.click();
a.remove();
resetBtn(e);
}
}, function() {
toaster.pop({
type: ‘error‘,
body: ‘下载失败请与管理员联系!‘,
timeout: 0
});
resetBtn(e);
})
}
上一篇:js比较两个时间的大小
文章标题:angularjs 服务端下载execl
文章链接:http://soscw.com/index.php/essay/41904.html