From c171cfc3c7f6f68864eadb04b3a3cf90f9c419ee Mon Sep 17 00:00:00 2001 From: kangsunlee Date: Mon, 7 Jul 2025 10:52:52 +0900 Subject: [PATCH] =?UTF-8?q?[BO]=20=EC=97=91=EC=85=80=EB=8B=A4=EC=9A=B4?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EB=A1=9C=EB=94=A9=EB=B0=94=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20=EB=A1=9C=EB=94=A9=EB=B0=94=EA=B0=80=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=97=91=EC=85=80=20=EB=8B=A4?= =?UTF-8?q?=EC=9A=B4=EB=A1=9C=EB=93=9C=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20exc?= =?UTF-8?q?elDownload(url,=20data);=20=ED=95=A8=EC=88=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=A9=B4=20=EB=90=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/images/common/ico_loading.svg | 8 +++ .../resources/static/scripts/ajaxUtils.js | 52 ++++++++++++++++++- .../templates/households/households.html | 7 +-- .../modal/modal-excel-household.html | 5 ++ .../resources/templates/layout/layout.html | 2 + 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 admin/src/main/resources/static/assets/images/common/ico_loading.svg diff --git a/admin/src/main/resources/static/assets/images/common/ico_loading.svg b/admin/src/main/resources/static/assets/images/common/ico_loading.svg new file mode 100644 index 00000000..fcd23ed8 --- /dev/null +++ b/admin/src/main/resources/static/assets/images/common/ico_loading.svg @@ -0,0 +1,8 @@ + + + + +
+ + +
diff --git a/admin/src/main/resources/static/scripts/ajaxUtils.js b/admin/src/main/resources/static/scripts/ajaxUtils.js index d37cfd02..eeb269e6 100644 --- a/admin/src/main/resources/static/scripts/ajaxUtils.js +++ b/admin/src/main/resources/static/scripts/ajaxUtils.js @@ -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); + }); }; \ No newline at end of file diff --git a/admin/src/main/resources/templates/households/households.html b/admin/src/main/resources/templates/households/households.html index 0c1a3ceb..28fa56c1 100644 --- a/admin/src/main/resources/templates/households/households.html +++ b/admin/src/main/resources/templates/households/households.html @@ -491,13 +491,10 @@ const f = document.reqForm; const data = $(f).serializeObject(); - // size 를 제거하면 전체 목록을 가져온다. - delete data.size; - if (url !== '') { - location.href = url + '?' + new URLSearchParams(data).toString(); + excelDownload(url, data); } else { - console.warn('엑셀 다운르도 경로 없음.') + console.warn('엑셀 다운르도 경로 없음.'); } } diff --git a/admin/src/main/resources/templates/households/modal/modal-excel-household.html b/admin/src/main/resources/templates/households/modal/modal-excel-household.html index 99117318..cf487ebd 100644 --- a/admin/src/main/resources/templates/households/modal/modal-excel-household.html +++ b/admin/src/main/resources/templates/households/modal/modal-excel-household.html @@ -52,6 +52,9 @@ return; } + // 로딩바 show + ajaxUtil._showWaiting(); + let formData = new FormData(); formData.append('file', fileInput.files[0]); @@ -68,6 +71,8 @@ $("meta[name='_csrf']").attr("content")); }, success(res) { + ajaxUtil._hideWaiting(); // 로딩바 hide + alert("총 "+res.total+"건 중에 "+res.success+"건 등록되었습니다."); }, statusCode: { diff --git a/admin/src/main/resources/templates/layout/layout.html b/admin/src/main/resources/templates/layout/layout.html index db11e28d..533f4846 100644 --- a/admin/src/main/resources/templates/layout/layout.html +++ b/admin/src/main/resources/templates/layout/layout.html @@ -9,6 +9,8 @@
+
+