- 사이드바: 결재 대기/기안함/참조함 메뉴에 빨간 뱃지 표시 - 헤더: 알림 벨 클릭 시 결재 대기 목록 드롭다운 표시 - 드롭다운: 제목/기안자/양식/긴급 여부/일시 표시, 클릭 시 상세 이동 - 뱃지 건수 60초 자동 갱신 (API: /api/admin/approvals/badge-counts)
310 lines
15 KiB
PHP
310 lines
15 KiB
PHP
<!-- Header -->
|
|
<header class="bg-white shadow-sm h-16 flex items-center justify-between px-4 lg:px-6 border-b border-gray-200">
|
|
<!-- 좌측: 모바일 햄버거 + 테넌트 셀렉터 -->
|
|
<div class="flex items-center gap-2 lg:gap-4">
|
|
<!-- 모바일 햄버거 버튼 (lg 미만에서만 표시) -->
|
|
<button
|
|
type="button"
|
|
onclick="openMobileSidebar()"
|
|
class="p-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors lg:hidden"
|
|
title="메뉴 열기"
|
|
>
|
|
<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="M4 6h16M4 12h16M4 18h16" />
|
|
</svg>
|
|
</button>
|
|
|
|
<!-- 모바일 로고 + 테넌트 뱃지 (lg 미만에서만 표시) -->
|
|
<div class="flex items-center gap-2 lg:hidden">
|
|
<span class="text-lg font-bold text-gray-900">{{ config('app.name') }}</span>
|
|
@unless(request()->routeIs('sales.*') || request()->routeIs('finance.settlement*'))
|
|
@php
|
|
$mobileTenant = $globalTenants->firstWhere('id', session('selected_tenant_id'));
|
|
@endphp
|
|
@if($mobileTenant)
|
|
<button
|
|
type="button"
|
|
onclick="openMobileSidebar()"
|
|
class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-primary/10 text-primary"
|
|
title="테넌트 변경"
|
|
>
|
|
{{ Str::limit($mobileTenant->company_name, 8) }}
|
|
</button>
|
|
@endif
|
|
@endunless
|
|
</div>
|
|
|
|
@unless(request()->routeIs('sales.*') || request()->routeIs('finance.settlement*'))
|
|
<!-- 테넌트 셀렉터 (데스크톱: 전체 표시, 모바일: 축소) -->
|
|
<div class="hidden lg:flex items-center gap-2">
|
|
<svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
|
|
</svg>
|
|
<label for="tenant-select" class="text-sm font-medium text-gray-700">테넌트 선택:</label>
|
|
</div>
|
|
|
|
<form action="{{ route('tenant.switch') }}" method="POST" id="tenant-switch-form" class="hidden lg:block">
|
|
@csrf
|
|
<select
|
|
name="tenant_id"
|
|
id="tenant-select"
|
|
onchange="document.getElementById('tenant-switch-form').submit()"
|
|
class="border-gray-300 rounded-lg text-sm focus:ring-primary focus:border-primary min-w-[200px]"
|
|
>
|
|
@foreach($globalTenants as $tenant)
|
|
<option value="{{ $tenant->id }}" {{ session('selected_tenant_id') == $tenant->id ? 'selected' : '' }}>
|
|
{{ $tenant->company_name }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</form>
|
|
|
|
<!-- 현재 테넌트 정보 (데스크톱에서만 표시) -->
|
|
@php
|
|
$currentTenant = $globalTenants->firstWhere('id', session('selected_tenant_id'));
|
|
@endphp
|
|
@if($currentTenant)
|
|
<span class="hidden lg:inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-primary/10 text-primary cursor-pointer hover:bg-primary/20"
|
|
data-context-menu="tenant"
|
|
data-entity-id="{{ $currentTenant->id }}"
|
|
data-entity-name="{{ $currentTenant->company_name }}"
|
|
title="클릭하여 메뉴 열기">
|
|
<svg class="w-4 h-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
</svg>
|
|
{{ $currentTenant->company_name }}
|
|
</span>
|
|
@endif
|
|
@endunless
|
|
</div>
|
|
|
|
<!-- Right Side Actions -->
|
|
<div class="flex items-center gap-4">
|
|
<!-- API 인증 상태 (전역) -->
|
|
<button
|
|
type="button"
|
|
onclick="DevToolsAuth.openModal()"
|
|
class="flex items-center gap-1.5 px-2.5 py-1.5 text-xs font-medium rounded-lg border transition-colors hover:bg-gray-50"
|
|
id="header-api-auth-btn"
|
|
title="API 인증 설정"
|
|
>
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
|
|
</svg>
|
|
<span class="hidden lg:inline dev-tools-auth-status text-gray-500">API 인증</span>
|
|
<span class="dev-tools-auth-dot w-2 h-2 rounded-full bg-gray-300"></span>
|
|
</button>
|
|
|
|
<!-- 결재 알림 벨 -->
|
|
<div class="relative" id="noti-bell-wrap">
|
|
<button type="button" onclick="toggleNotifications()"
|
|
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" />
|
|
</svg>
|
|
<span id="noti-badge"
|
|
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">전체 보기 →</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 -->
|
|
<div class="relative">
|
|
<button
|
|
type="button"
|
|
onclick="document.getElementById('headerUserMenu').classList.toggle('hidden')"
|
|
class="flex items-center gap-1 lg:gap-2 p-1.5 lg:px-3 lg:py-2 text-sm font-medium text-gray-700 hover:bg-gray-100 rounded-lg focus:outline-none"
|
|
>
|
|
<div class="w-8 h-8 rounded-full bg-primary text-white flex items-center justify-center text-sm font-bold">
|
|
{{ mb_strtoupper(mb_substr(auth()->user()->name ?? 'U', 0, 1)) }}
|
|
</div>
|
|
<!-- 이름: 데스크톱에서만 표시 -->
|
|
<span class="hidden lg:inline text-gray-700">{{ auth()->user()->name ?? 'User' }}</span>
|
|
<!-- chevron: 데스크톱에서만 표시 -->
|
|
<svg class="hidden lg:block w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
|
</svg>
|
|
</button>
|
|
|
|
<!-- Dropdown Menu -->
|
|
<div id="headerUserMenu" class="hidden absolute right-0 mt-2 w-56 bg-white rounded-lg shadow-lg border border-gray-200 py-1 z-50">
|
|
<!-- User Info -->
|
|
<div class="px-4 py-3 border-b border-gray-200">
|
|
<p class="text-sm font-medium text-gray-900">{{ auth()->user()->name ?? 'User' }}</p>
|
|
<p class="text-xs text-gray-500 truncate">{{ auth()->user()->email }}</p>
|
|
</div>
|
|
|
|
<!-- Menu Items -->
|
|
<a href="{{ route('profile.index') }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
|
프로필 설정
|
|
</a>
|
|
|
|
<div class="border-t border-gray-200 my-1"></div>
|
|
|
|
<!-- Logout -->
|
|
<form method="POST" action="{{ route('logout') }}" id="logout-form">
|
|
@csrf
|
|
<button type="button" onclick="handleLogout()" class="block w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-gray-100">
|
|
로그아웃
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
@push('scripts')
|
|
<script>
|
|
// Close dropdowns when clicking outside
|
|
document.addEventListener('click', function(event) {
|
|
// User menu
|
|
const userMenu = document.getElementById('headerUserMenu');
|
|
if (userMenu) {
|
|
const button = event.target.closest('button[onclick*="headerUserMenu"]');
|
|
if (!button && !userMenu.contains(event.target)) {
|
|
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 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">' +
|
|
'<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', {
|
|
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);
|
|
})
|
|
.catch(function() {
|
|
list.innerHTML = '<div class="flex items-center justify-center py-10 text-gray-400 text-sm">조회에 실패했습니다.</div>';
|
|
});
|
|
}
|
|
|
|
function renderNotifications(items, total) {
|
|
var list = document.getElementById('noti-list');
|
|
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">' +
|
|
'<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>';
|
|
return;
|
|
}
|
|
|
|
var html = '';
|
|
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>'
|
|
: '';
|
|
var formName = (item.form && item.form.name) || '';
|
|
var drafterName = item.drafter_name || (item.drafter && item.drafter.name) || '';
|
|
var dateStr = '';
|
|
if (item.drafted_at) {
|
|
var d = new Date(item.drafted_at);
|
|
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 +
|
|
'</div>' +
|
|
'<div class="flex items-center justify-between text-xs text-gray-500">' +
|
|
'<span>' + drafterName + (formName ? ' · ' + formName : '') + '</span>' +
|
|
'<span>' + dateStr + '</span>' +
|
|
'</div></a>';
|
|
});
|
|
|
|
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>';
|
|
}
|
|
|
|
list.innerHTML = html;
|
|
}
|
|
|
|
// 뱃지 건수 조회 (페이지 로드 + 60초마다 갱신)
|
|
function refreshBadgeCount() {
|
|
fetch('/api/admin/approvals/badge-counts', {
|
|
headers: { 'Accept': 'application/json' }
|
|
})
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
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';
|
|
}
|
|
})
|
|
.catch(function() {});
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
refreshBadgeCount();
|
|
setInterval(refreshBadgeCount, 60000);
|
|
});
|
|
|
|
/**
|
|
* 로그아웃 처리 (FCM 토큰 해제 후 로그아웃)
|
|
*/
|
|
async function handleLogout() {
|
|
// FCM 토큰 해제 시도 (window.FCM이 있는 경우에만)
|
|
if (window.FCM && typeof window.FCM.unregisterToken === 'function') {
|
|
try {
|
|
await window.FCM.unregisterToken();
|
|
console.log('[Logout] FCM token unregistered');
|
|
} catch (error) {
|
|
console.warn('[Logout] FCM unregister failed:', error);
|
|
}
|
|
}
|
|
|
|
// 로그아웃 폼 제출
|
|
document.getElementById('logout-form').submit();
|
|
}
|
|
</script>
|
|
@endpush
|