feat: [approval] 결재 알림 드롭다운을 모달로 전환 + 로그인 시 자동 팝업

- 380px 드롭다운 → 560px 전체 화면 모달로 확장
- 로그인 시 미처리 결재 있으면 자동 팝업 (세션당 1회)
- ESC키/backdrop 클릭으로 모달 닫기 지원
- 모달 내 결재 카드: 긴급뱃지, 기안자, 양식, 날짜, 결재하기 링크
- 60초 뱃지 갱신 유지, per_page 10→20으로 확대
This commit is contained in:
김보곤
2026-02-28 15:33:05 +09:00
parent ba792a0fcc
commit 5f24d01780

View File

@@ -97,7 +97,7 @@ class="flex items-center gap-1.5 px-2.5 py-1.5 text-xs font-medium rounded-lg bo
<!-- 결재 알림 -->
<div class="relative" id="noti-bell-wrap">
<button type="button" onclick="toggleNotifications()"
<button type="button" onclick="openApprovalModal()"
class="p-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg relative">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" />
@@ -106,19 +106,6 @@ class="p-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg relati
style="display:none; position:absolute; top:2px; right:2px; min-width:18px; height:18px; padding:0 4px; font-size:10px; line-height:18px;"
class="flex items-center justify-center text-white bg-red-500 rounded-full font-bold"></span>
</button>
{{-- 드롭다운 --}}
<div id="noti-dropdown"
style="display:none; width:380px;"
class="absolute right-0 mt-2 bg-white rounded-xl shadow-2xl border border-gray-200 z-50">
<div class="px-4 py-3 border-b border-gray-200 flex items-center justify-between">
<span class="text-sm font-semibold text-gray-800">결재 대기</span>
<a href="/approval-mgmt/pending" class="text-xs text-blue-600 hover:underline">전체 보기 &rarr;</a>
</div>
<div id="noti-list" class="overflow-y-auto" style="max-height:380px;">
<div class="flex items-center justify-center py-10 text-gray-400 text-sm">로딩 ...</div>
</div>
</div>
</div>
<!-- User Menu Dropdown -->
@@ -166,6 +153,54 @@ class="flex items-center gap-1 lg:gap-2 p-1.5 lg:px-3 lg:py-2 text-sm font-mediu
</div>
</header>
<!-- 결재 알림 모달 -->
<div id="approval-modal" style="display:none;" class="fixed inset-0 z-50">
<div class="absolute inset-0 bg-black/50" onclick="closeApprovalModal()"></div>
<div class="relative flex items-center justify-center min-h-full p-4">
<div class="bg-white rounded-xl shadow-2xl w-full overflow-hidden relative" style="max-width:560px;">
<!-- 닫기 X -->
<button onclick="closeApprovalModal()"
class="absolute top-3 right-3 z-10 w-8 h-8 flex items-center justify-center text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-full transition-colors"
title="닫기">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
<!-- 헤더 -->
<div class="px-5 py-4 border-b border-gray-200 flex items-center gap-2">
<svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
<span class="text-base font-semibold text-gray-800">전자결재</span>
<span id="approval-modal-count"
style="display:none; min-width:20px; height:20px; padding:0 8px; font-size:11px; line-height:20px;"
class="ml-1 bg-red-500 text-white rounded-full text-xs font-bold items-center justify-center"></span>
</div>
<!-- 본문 (스크롤) -->
<div id="approval-modal-list" class="overflow-y-auto" style="max-height:60vh;">
<div class="flex items-center justify-center py-16 text-gray-400 text-sm">
<svg class="animate-spin w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
</svg>
불러오는 ...
</div>
</div>
<!-- 푸터 -->
<div class="px-5 py-3 border-t border-gray-200 flex justify-end gap-2">
<a href="/approval-mgmt/pending"
class="inline-flex items-center px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition-colors">
결재함으로 이동
</a>
<button onclick="closeApprovalModal()"
class="px-4 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-lg hover:bg-gray-200 transition-colors">
닫기
</button>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
// Close dropdowns when clicking outside
@@ -178,62 +213,69 @@ class="flex items-center gap-1 lg:gap-2 p-1.5 lg:px-3 lg:py-2 text-sm font-mediu
userMenu.classList.add('hidden');
}
}
// Notification dropdown
var notiWrap = document.getElementById('noti-bell-wrap');
var notiDropdown = document.getElementById('noti-dropdown');
if (notiWrap && notiDropdown && !notiWrap.contains(event.target)) {
notiDropdown.style.display = 'none';
}
});
// ─── 결재 알림 ───
var _notiLoaded = false;
function toggleNotifications() {
var dd = document.getElementById('noti-dropdown');
if (!dd) return;
var isOpen = dd.style.display !== 'none';
dd.style.display = isOpen ? 'none' : '';
if (!isOpen) loadNotifications();
// ─── 결재 알림 모달 ───
function openApprovalModal() {
document.getElementById('approval-modal').style.display = '';
document.body.style.overflow = 'hidden';
loadApprovalModal();
}
function loadNotifications() {
_notiLoaded = false;
var list = document.getElementById('noti-list');
list.innerHTML = '<div class="flex items-center justify-center py-10 text-gray-400 text-sm">' +
function closeApprovalModal() {
document.getElementById('approval-modal').style.display = 'none';
document.body.style.overflow = '';
}
function loadApprovalModal() {
var list = document.getElementById('approval-modal-list');
list.innerHTML = '<div class="flex items-center justify-center py-16 text-gray-400 text-sm">' +
'<svg class="animate-spin w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>' +
'<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/></svg>불러오는 중...</div>';
fetch('/api/admin/approvals/pending?per_page=10', {
fetch('/api/admin/approvals/pending?per_page=20', {
headers: { 'Accept': 'application/json' }
})
.then(function(r) { return r.json(); })
.then(function(res) {
var items = (res.data && res.data.data) || res.data || [];
if (!Array.isArray(items)) items = [];
renderNotifications(items, (res.data && res.data.total) || items.length);
renderApprovalModal(items, (res.data && res.data.total) || items.length);
})
.catch(function() {
list.innerHTML = '<div class="flex items-center justify-center py-10 text-gray-400 text-sm">조회에 실패했습니다.</div>';
list.innerHTML = '<div class="flex items-center justify-center py-16 text-gray-400 text-sm">조회에 실패했습니다.</div>';
});
}
function renderNotifications(items, total) {
var list = document.getElementById('noti-list');
function renderApprovalModal(items, total) {
var list = document.getElementById('approval-modal-list');
var countBadge = document.getElementById('approval-modal-count');
// 헤더 건수 뱃지
if (countBadge) {
if (total > 0) {
countBadge.textContent = total + '건 대기';
countBadge.style.cssText = 'display:inline-flex; align-items:center; justify-content:center; min-width:20px; height:20px; padding:0 8px; font-size:11px; line-height:20px;';
} else {
countBadge.style.display = 'none';
}
}
if (!items.length) {
list.innerHTML =
'<div class="flex flex-col items-center justify-center py-10 text-gray-400">' +
'<svg class="w-10 h-10 mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">' +
'<div class="flex flex-col items-center justify-center py-16 text-gray-400">' +
'<svg class="w-12 h-12 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">' +
'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>' +
'</svg>' +
'<span class="text-sm">처리할 결재가 없습니다</span></div>';
'<span class="text-sm font-medium text-gray-500">처리할 결재가 없습니다</span>' +
'<span class="text-xs text-gray-400 mt-1">모든 결재가 완료되었습니다</span></div>';
return;
}
var html = '';
var html = '<div class="divide-y divide-gray-100">';
items.forEach(function(item) {
var urgentBadge = item.is_urgent
? '<span style="font-size:10px; padding:1px 6px;" class="bg-red-100 text-red-600 rounded-full font-medium">긴급</span>'
? '<span class="shrink-0 bg-red-100 text-red-600 rounded-full font-medium" style="font-size:10px; padding:2px 8px;">긴급</span>'
: '';
var formName = (item.form && item.form.name) || '';
var drafterName = item.drafter_name || (item.drafter && item.drafter.name) || '';
@@ -243,26 +285,32 @@ function renderNotifications(items, total) {
dateStr = (d.getMonth()+1) + '/' + d.getDate() + ' ' + String(d.getHours()).padStart(2,'0') + ':' + String(d.getMinutes()).padStart(2,'0');
}
html += '<a href="/approval-mgmt/' + item.id + '" class="block px-4 py-3 hover:bg-blue-50 transition border-b border-gray-100">' +
'<div class="flex items-center justify-between gap-2 mb-1">' +
'<span class="text-sm font-medium text-gray-800 truncate flex-1">' + (item.title || '(제목 없음)') + '</span>' +
urgentBadge +
html += '<a href="/approval-mgmt/' + item.id + '" class="block px-5 py-4 hover:bg-blue-50/50 transition-colors group">' +
'<div class="flex items-start justify-between gap-3">' +
'<div class="flex-1 min-w-0">' +
'<div class="flex items-center gap-2 mb-1.5">' +
urgentBadge +
'<span class="text-sm font-medium text-gray-800 truncate">' + (item.title || '(제목 없음)') + '</span>' +
'</div>' +
'<div class="text-xs text-gray-500">' +
'기안자: ' + drafterName + (formName ? ' &middot; ' + formName : '') + (dateStr ? ' &middot; ' + dateStr : '') +
'</div>' +
'</div>' +
'<span class="shrink-0 text-xs text-blue-600 font-medium opacity-0 group-hover:opacity-100 transition-opacity mt-0.5">결재하기 &rarr;</span>' +
'</div>' +
'<div class="flex items-center justify-between text-xs text-gray-500">' +
'<span>' + drafterName + (formName ? ' · ' + formName : '') + '</span>' +
'<span>' + dateStr + '</span>' +
'</div></a>';
'</a>';
});
html += '</div>';
if (total > items.length) {
html += '<div class="px-4 py-2 text-center">' +
'<a href="/approval-mgmt/pending" class="text-xs text-blue-600 hover:underline">외 ' + (total - items.length) + '건 더보기</a></div>';
html += '<div class="px-5 py-3 text-center border-t border-gray-100">' +
'<a href="/approval-mgmt/pending" class="text-sm text-blue-600 hover:underline font-medium">외 ' + (total - items.length) + '건 더보기</a></div>';
}
list.innerHTML = html;
}
// 뱃지 건수 조회 (페이지 로드 + 60초마다 갱신)
// 뱃지 건수 조회 (페이지 로드 + 60초마다 갱신) + 자동 팝업
function refreshBadgeCount() {
fetch('/api/admin/approvals/badge-counts', {
headers: { 'Accept': 'application/json' }
@@ -272,17 +320,33 @@ function refreshBadgeCount() {
if (!res.success || !res.data) return;
var count = res.data.pending || 0;
var badge = document.getElementById('noti-badge');
if (!badge) return;
if (count > 0) {
badge.textContent = count > 99 ? '99+' : count;
badge.style.display = 'flex';
} else {
badge.style.display = 'none';
if (badge) {
if (count > 0) {
badge.textContent = count > 99 ? '99+' : count;
badge.style.display = 'flex';
} else {
badge.style.display = 'none';
}
}
// 자동 팝업: 미처리 결재 있고 세션에서 아직 표시 안 했으면
if (count > 0 && !sessionStorage.getItem('approval_modal_shown')) {
openApprovalModal();
sessionStorage.setItem('approval_modal_shown', '1');
}
})
.catch(function() {});
}
// ESC키로 모달 닫기
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
var modal = document.getElementById('approval-modal');
if (modal && modal.style.display !== 'none') {
closeApprovalModal();
}
}
});
document.addEventListener('DOMContentLoaded', function() {
refreshBadgeCount();
setInterval(refreshBadgeCount, 60000);