[BO] 엑셀다운로드 로딩바 추가 - 로딩바가 필요한 엑셀 다운로드일 경우 excelDownload(url, data); 함수 사용하면 됩니다.
This commit is contained in:
@@ -192,6 +192,48 @@ var ajaxUtil = {
|
||||
},
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 엑셀 다운로드 (로딩바 포함)
|
||||
*/
|
||||
_excelDownload: function(url, data, errorCallback) {
|
||||
ajaxUtil._showWaiting();
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
data: data,
|
||||
xhrFields: {
|
||||
responseType: 'blob'
|
||||
},
|
||||
beforeSend: function(xhr) {
|
||||
if (ajaxUtil._csrfHeader != undefined) {
|
||||
xhr.setRequestHeader(ajaxUtil._csrfHeader, ajaxUtil._csrfToken);
|
||||
}
|
||||
},
|
||||
success: function(blob, status, xhr) {
|
||||
const disposition = xhr.getResponseHeader('Content-Disposition');
|
||||
const filenameMatch = disposition?.match(/filename\*?=UTF-8''(.+)/);
|
||||
const filename = filenameMatch ? decodeURIComponent(filenameMatch[1]) : 'download.xlsx';
|
||||
|
||||
const blobUrl = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = blobUrl;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
},
|
||||
error: function(rstData) {
|
||||
if (typeof errorCallback !== 'undefined') {
|
||||
errorCallback(rstData.status, rstData);
|
||||
} else {
|
||||
alert('엑셀 다운로드 실패');
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
ajaxUtil._hideWaiting();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
_jsonParse : function parse(jsonStr) {
|
||||
@@ -220,11 +262,17 @@ var ajaxUtil = {
|
||||
_hideWaiting:function(){
|
||||
if (ajaxUtil.loadingStatus) {
|
||||
ajaxUtil.loadingStatus = false;
|
||||
// TODO : 로딩바 숨김
|
||||
$('#loading').hide();
|
||||
}
|
||||
},
|
||||
_showWaiting:function(){
|
||||
ajaxUtil.loadingStatus = true;
|
||||
// TODO : 로딩바 활성화
|
||||
$('#loading').show();
|
||||
},
|
||||
};
|
||||
|
||||
const excelDownload = (url, data) => {
|
||||
ajaxUtil._excelDownload(url, data, (status, error) => {
|
||||
console.error('엑셀 다운로드 실패:', status, error);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user