star-cloud/resources/views/admin/basic-settings/machines/distribution.blade.php
sky121113 6b9b577978 [FEAT] 取貨碼功能強化與 UI 重構
1. 取貨碼模組新增 Slug 機制與公開憑證頁面,支援外部連結訪問。
2. 狀態篩選下拉選單重構為極簡奢華風組件 (x-searchable-select),並優化後端空值處理。
3. 機台分佈地圖新增「依型號分類」功能,提升管理便利性。
4. 新增 B660 取貨碼驗證 API 端點供機台通訊使用。
5. 更新多語言語系檔 (zh_TW.json) 確保介面一致性。
2026-04-29 10:39:35 +08:00

350 lines
18 KiB
PHP

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" class="h-full">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ __('Machine Distribution Map') }} | Star Cloud</title>
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=Outfit:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<style>
body { font-family: 'Inter', 'Outfit', sans-serif; }
#map { height: 100%; width: 100%; z-index: 1; }
.luxury-shadow { box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.15); }
.glass-panel {
background: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.3);
}
.dark .glass-panel {
background: rgba(15, 23, 42, 0.8);
border: 1px solid rgba(255, 255, 255, 0.05);
}
/* Custom Marker Style */
.custom-marker {
display: flex;
align-items: center;
justify-content: center;
}
.marker-dot {
width: 14px;
height: 14px;
border-radius: 50%;
border: 2px solid white;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
.marker-online { background-color: #10b981; }
.marker-offline { background-color: #64748b; }
.marker-error { background-color: #ef4444; }
</style>
</head>
<body class="h-full bg-slate-50 dark:bg-slate-950 overflow-hidden">
<div class="flex h-full relative">
<!-- Sidebar -->
<div class="hidden md:flex flex-col w-96 glass-panel border-r border-slate-200/50 dark:border-slate-800/50 z-20 overflow-hidden">
<div class="p-8 border-b border-slate-200/50 dark:border-slate-800/50">
<h1 class="text-2xl font-black text-slate-800 dark:text-white tracking-tight outfit-font">
Star Cloud
</h1>
<p class="text-[10px] font-black text-cyan-600 dark:text-cyan-400 uppercase tracking-[0.4em] mt-2">
{{ __('Machine Distribution') }}
</p>
</div>
<!-- Model Statistics -->
@php
$groupedByModel = $machines->groupBy(fn($m) => $m->machineModel?->name ?? __('Unknown Model'));
$modelColors = [
'U4' => '#EAB308', // Yellow
'U3' => '#15803D', // Green
'U1' => '#F97316', // Orange
'U4S' => '#0D9488', // Teal
'I1' => '#854D0E', // Olive
'U4SSS' => '#EF4444', // Red
'Y1' => '#F97316', // Orange
'U4SS' => '#3B82F6', // Blue
'U4S(短)' => '#1E3A8A', // Dark Blue
'U4XXXS' => '#64748B', // Slate
'易豐主機' => '#22C55E', // Bright Green
'I10' => '#A855F7', // Purple
'N1' => '#BEF264', // Lime
'Y2' => '#DC2626', // Red
'U4_Android9_test' => '#10b981', // Emerald
];
// Unify fallback color logic with JS
$getFallbackColor = function($name) {
$hash = 0;
$len = mb_strlen($name);
for ($i = 0; $i < $len; $i++) {
$char = mb_substr($name, $i, 1);
$code = mb_ord($char);
$hash = $code + (($hash << 5) - $hash);
$hash = $hash & 0xFFFFFFFF; // Keep it 32-bit
}
return sprintf('#%06X', $hash & 0xFFFFFF);
};
@endphp
<div class="p-4 border-b border-slate-200/50 dark:border-slate-800/50 bg-slate-50/50 dark:bg-slate-900/50 overflow-y-auto max-h-64 custom-scrollbar">
<div class="flex items-center justify-between mb-3">
<h3 class="text-[10px] font-black text-slate-400 uppercase tracking-widest">{{ __('Statistics: Model') }}</h3>
</div>
<div class="grid grid-cols-1 gap-2">
@foreach($groupedByModel as $modelName => $group)
@php $color = $modelColors[$modelName] ?? $getFallbackColor($modelName); @endphp
<div class="flex items-center justify-between group cursor-pointer" onclick="filterByModel('{{ $modelName }}')">
<div class="flex items-center gap-2">
<span class="w-2.5 h-2.5 rounded-full shadow-sm" style="background-color: {{ $color }}"></span>
<span class="text-xs font-bold text-slate-600 dark:text-slate-300 group-hover:text-cyan-500 transition-colors">{{ $modelName }}</span>
</div>
<span class="text-[10px] font-mono text-slate-400">({{ $group->count() }})</span>
</div>
@endforeach
</div>
</div>
<!-- Search Box -->
<div class="px-4 pb-4 border-b border-slate-200/50 dark:border-slate-800/50 bg-slate-50/30 dark:bg-slate-900/30 pt-4">
<div class="relative">
<span class="absolute inset-y-0 left-0 pl-3 flex items-center text-slate-400">
<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.5" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/></svg>
</span>
<input type="text" id="machine-search" onkeyup="updateSearchFilter(this.value)" placeholder="{{ __('Search name or serial...') }}"
class="w-full pl-10 pr-4 py-2.5 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-xl text-xs font-bold text-slate-700 dark:text-slate-200 placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-cyan-500/20 focus:border-cyan-500 transition-all shadow-sm">
</div>
</div>
<div class="flex-1 overflow-y-auto p-4 space-y-3 custom-scrollbar" id="machine-list">
@foreach($machines as $machine)
@php
$modelName = $machine->machineModel?->name ?? __('Unknown Model');
$color = $modelColors[$modelName] ?? $getFallbackColor($modelName);
@endphp
<div class="machine-item p-4 rounded-2xl bg-white/50 dark:bg-slate-900/50 border border-slate-100 dark:border-slate-800 hover:border-cyan-500/30 transition-all cursor-pointer group"
data-model="{{ $modelName }}"
data-id="{{ $machine->id }}"
onclick="focusMachine({{ $machine->latitude }}, {{ $machine->longitude }}, {{ $machine->id }})">
<div class="flex items-center justify-between mb-2">
<div class="flex items-center gap-2">
<span class="w-2 h-2 rounded-full" style="background-color: {{ $color }}"></span>
<span class="text-sm font-black text-slate-800 dark:text-white group-hover:text-cyan-500 transition-colors">
{{ $machine->name }}
</span>
</div>
<div class="flex items-center gap-1.5">
<span class="w-1.5 h-1.5 rounded-full {{ $machine->status === 'online' ? 'bg-emerald-500' : ($machine->status === 'offline' ? 'bg-slate-400' : 'bg-rose-500') }}"></span>
<span class="text-[9px] font-bold text-slate-400 uppercase tracking-widest">{{ __($machine->status) }}</span>
</div>
</div>
<p class="text-xs font-medium text-slate-500 dark:text-slate-400 leading-relaxed truncate">
{{ $machine->address ?: $machine->location ?: __('No address information') }}
</p>
<div class="mt-3 flex items-center justify-between">
<span class="text-[10px] font-mono text-slate-400 bg-slate-100 dark:bg-slate-800 px-2 py-0.5 rounded shadow-sm">
{{ $machine->serial_no }}
</span>
<span class="text-[9px] font-black text-slate-300 dark:text-slate-600 uppercase">{{ $modelName }}</span>
</div>
</div>
@endforeach
</div>
<div class="p-6 border-t border-slate-200/50 dark:border-slate-800/50 bg-slate-50/50 dark:bg-slate-900/50">
<div class="flex items-center justify-between text-[10px] font-black text-slate-400 uppercase tracking-widest">
<span>{{ __('Total Machines') }}</span>
<span class="text-slate-800 dark:text-white">{{ $machines->count() }}</span>
</div>
<button onclick="resetFilter()" class="mt-4 w-full py-2 rounded-xl border border-slate-200 dark:border-slate-800 text-[10px] font-black text-slate-400 hover:text-cyan-500 hover:border-cyan-500/30 transition-all uppercase tracking-widest">
{{ __('Show All') }}
</button>
</div>
</div>
<!-- Map Container -->
<div class="flex-1 relative h-full">
<div id="map"></div>
<!-- Floating Top Header (Mobile) -->
<div class="md:hidden absolute top-4 left-4 right-4 z-[1000]">
<div class="glass-panel p-4 rounded-2xl luxury-shadow border border-slate-200/50 dark:border-slate-800/50 flex items-center justify-between">
<div>
<h1 class="text-lg font-black text-slate-800 dark:text-white tracking-tight outfit-font line-clamp-1">
{{ __('Machine Distribution Map') }}
</h1>
</div>
<div class="w-10 h-10 rounded-xl bg-cyan-500/10 flex items-center justify-center text-cyan-500 border border-cyan-500/20">
<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.5" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
</div>
</div>
</div>
</div>
</div>
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script>
const machines = @json($machines);
const modelColors = @json($modelColors);
function getFallbackColor(name) {
let hash = 0;
for (let i = 0; i < name.length; i++) {
hash = name.charCodeAt(i) + ((hash << 5) - hash);
}
const color = '#' + (hash & 0x00FFFFFF).toString(16).toUpperCase().padStart(6, '0');
return color;
}
const map = L.map('map', {
zoomControl: false
}).setView([23.973875, 120.982024], 8); // Center of Taiwan
L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>',
subdomains: 'abcd',
maxZoom: 20
}).addTo(map);
L.control.zoom({
position: 'bottomright'
}).addTo(map);
const markers = {};
const markerGroups = {};
machines.forEach(machine => {
if (machine.latitude && machine.longitude) {
const modelName = machine.machine_model?.name || '{{ __("Unknown Model") }}';
const color = modelColors[modelName] || getFallbackColor(modelName);
const icon = L.divIcon({
className: 'custom-marker',
html: `<div class="marker-dot" style="background-color: ${color}; border-color: white;"></div>`,
iconSize: [20, 20],
iconAnchor: [10, 10]
});
const marker = L.marker([machine.latitude, machine.longitude], { icon: icon }).addTo(map);
const popupContent = `
<div class="p-2 min-w-[200px]">
<div class="flex items-center justify-between mb-2">
<div class="flex items-center gap-2">
<div class="w-3 h-3 rounded-full" style="background-color: ${color}"></div>
<span class="text-sm font-black text-slate-800">${machine.name}</span>
</div>
<span class="text-[9px] font-bold text-slate-400 uppercase tracking-widest">${modelName}</span>
</div>
<p class="text-[11px] font-medium text-slate-500 mb-2">${machine.address || machine.location || ''}</p>
<div class="flex items-center justify-between border-t border-slate-100 pt-2 mt-2">
<span class="text-[9px] font-black text-slate-400 uppercase tracking-widest">${machine.serial_no}</span>
<div class="flex items-center gap-1">
<div class="w-1.5 h-1.5 rounded-full ${machine.status === 'online' ? 'bg-emerald-500' : (machine.status === 'offline' ? 'bg-slate-400' : 'bg-rose-500')}"></div>
<span class="text-[9px] font-bold text-cyan-600 uppercase tracking-widest">${machine.status.toUpperCase()}</span>
</div>
</div>
</div>
`;
marker.bindPopup(popupContent, {
maxWidth: 300,
className: 'luxury-popup'
});
markers[machine.id] = marker;
if (!markerGroups[modelName]) markerGroups[modelName] = [];
markerGroups[modelName].push(marker);
}
});
function focusMachine(lat, lng, id) {
map.flyTo([lat, lng], 15, {
duration: 1.5
});
setTimeout(() => {
if (markers[id]) {
markers[id].openPopup();
}
}, 1600);
}
let currentModelFilter = null;
let currentSearchQuery = '';
function applyFilters() {
const visibleMarkers = [];
machines.forEach(machine => {
const modelName = machine.machine_model?.name || '{{ __("Unknown Model") }}';
const matchesModel = !currentModelFilter || modelName === currentModelFilter;
const matchesSearch = !currentSearchQuery ||
machine.name.toLowerCase().includes(currentSearchQuery) ||
machine.serial_no.toLowerCase().includes(currentSearchQuery);
const isVisible = matchesModel && matchesSearch;
if (markers[machine.id]) {
if (isVisible) {
markers[machine.id].addTo(map);
visibleMarkers.push(markers[machine.id]);
} else {
markers[machine.id].remove();
}
}
const item = document.querySelector(`.machine-item[data-id="${machine.id}"]`);
if (item) {
if (isVisible) item.classList.remove('hidden');
else item.classList.add('hidden');
}
});
// If we have visible markers and a model filter is active, adjust bounds
if (currentModelFilter && visibleMarkers.length > 0) {
const group = new L.featureGroup(visibleMarkers);
map.fitBounds(group.getBounds().pad(0.1));
}
}
function filterByModel(modelName) {
currentModelFilter = modelName;
applyFilters();
}
function updateSearchFilter(query) {
currentSearchQuery = query.toLowerCase().trim();
applyFilters();
}
function resetFilter() {
currentModelFilter = null;
currentSearchQuery = '';
document.getElementById('machine-search').value = '';
applyFilters();
map.setView([23.973875, 120.982024], 8);
}
// Adjust map on window resize
window.addEventListener('resize', () => {
map.invalidateSize();
});
</script>
</body>
</html>