Files
star-cloud/resources/views/components/breadcrumbs.blade.php
2026-03-13 10:08:30 +08:00

177 lines
8.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@props(['links' => null])
@php
if (is_null($links)) {
$routeName = Route::currentRouteName();
$links = [];
// 預設首頁 (Dashboard)
$links[] = [
'label' => __('Dashboard'),
'url' => route('admin.dashboard'),
'active' => $routeName === 'admin.dashboard'
];
if ($routeName && $routeName !== 'admin.dashboard') {
// 定義大模組映射表 (路由前綴 => 大模組名稱)
$moduleMap = [
'profile' => __('Profile Settings'),
'admin.members' => __('Member Management'),
'admin.membership-tiers' => __('Member Management'),
'admin.deposit-bonus-rules' => __('Member Management'),
'admin.point-rules' => __('Member Management'),
'admin.gift-definitions' => __('Member Management'),
'admin.machines' => __('Machine Management'),
'admin.app' => __('APP Management'),
'admin.warehouses' => __('Warehouse Management'),
'admin.sales' => __('Sales Management'),
'admin.analysis' => __('Analysis Management'),
'admin.audit' => __('Audit Management'),
'admin.data-config' => __('Data Configuration'),
'admin.remote' => __('Remote Management'),
'admin.line' => __('Line Management'),
'admin.reservation' => __('Reservation System'),
'admin.special-permission' => __('Special Permission'),
'admin.permission' => __('Permission Settings'),
];
// 1. 找出所屬大模組
$foundModule = null;
foreach ($moduleMap as $prefix => $label) {
if (str_starts_with($routeName, $prefix)) {
$foundModule = [
'label' => $label,
'url' => '#',
'active' => false
];
break;
}
}
if ($foundModule) {
$links[] = $foundModule;
}
// 2. 處理具體頁面
$segments = explode('.', $routeName);
$lastSegment = end($segments);
// 嘗試翻譯最後一個片段作為頁面名稱
$pageLabel = match($lastSegment) {
'edit' => __('Profile'), // 專門處理 profile.edit
'index' => null, // 通常 index 代表列表,如果在大模組下則不重複顯示
'logs' => __('Machine Logs'),
'permissions' => __('Machine Permissions'),
'utilization' => __('Utilization Rate'),
'expiry' => __('Expiry Management'),
'maintenance' => __('Maintenance Records'),
'ui-elements' => __('UI Elements'),
'helper' => __('Helper'),
'questionnaire' => __('Questionnaire'),
'games' => __('Games'),
'timer' => __('Timer'),
'personal' => __('Warehouse List (Individual)'),
'stock-management' => __('Stock Management'),
'transfers' => __('Transfers'),
'purchases' => __('Purchases'),
'replenishments' => __('Replenishments'),
'replenishment-records' => __('Replenishment Records'),
'machine-stock' => __('Machine Stock'),
'staff-stock' => __('Staff Stock'),
'returns' => __('Returns'),
'pickup-codes' => __('Pickup Codes'),
'orders' => __('Orders'),
'promotions' => __('Promotions'),
'pass-codes' => __('Pass Codes'),
'store-gifts' => __('Store Gifts'),
'change-stock' => __('Change Stock'),
'machine-reports' => __('Machine Reports'),
'product-reports' => __('Product Reports'),
'survey-analysis' => __('Survey Analysis'),
'products' => __('Product Management'),
'advertisements' => __('Advertisement Management'),
'admin-products' => __('Admin Sellable Products'),
'accounts' => __('Account Management'),
'sub-accounts' => __('Sub Accounts'),
'sub-account-roles' => __('Sub Account Roles'),
'points' => __('Point Settings'),
'badges' => __('Badge Settings'),
'restart' => __('Machine Restart'),
'restart-card-reader' => __('Card Reader Restart'),
'checkout' => __('Remote Checkout'),
'lock' => __('Remote Lock'),
'change' => __('Remote Change'),
'dispense' => __('Remote Dispense'),
'official-account' => __('Line Official Account'),
'coupons' => __('Line Coupons'),
'stores' => __('Store Management'),
'time-slots' => __('Time Slots'),
'venues' => __('Venue Management'),
'reservations' => __('Reservations'),
'clear-stock' => __('Clear Stock'),
'apk-versions' => __('APK Versions'),
'discord-notifications' => __('Discord Notifications'),
'app-features' => __('APP Features'),
'roles' => __('Roles'),
'others' => __('Others'),
'ai-prediction' => __('AI Prediction'),
'create' => __('Create'),
'show' => __('Show'),
'members' => __('Member List'), // 處理 admin.members.index 這種情況
default => null,
};
// 如果匹配不到,嘗試處理一些特殊的 index 標籤
if (!$pageLabel && $lastSegment === 'index') {
$pageLabel = match($segments[count($segments)-2] ?? '') {
'members' => __('Member List'),
'machines' => __('Machine List'),
'warehouses' => __('Warehouse List'),
'sales' => __('Sales Records'),
default => null,
};
}
if ($pageLabel) {
$links[] = [
'label' => $pageLabel,
'url' => route($routeName),
'active' => true
];
}
// 確保最後一個 link 是 active 的
if (!empty($links)) {
$links[count($links) - 1]['active'] = true;
// 如果倒數第二個也是同個頁面(例如 Dashboard > Dashboard則移除重複
if (count($links) > 1 && $links[count($links)-1]['label'] === $links[count($links)-2]['label']) {
array_pop($links);
$links[count($links)-1]['active'] = true;
}
}
}
}
@endphp
<nav {{ $attributes->merge(['class' => 'flex', 'aria-label' => 'Breadcrumb']) }}>
<ol class="flex items-center whitespace-nowrap min-w-0 w-full">
@foreach($links as $link)
<li class="flex items-center text-sm {{ $link['active'] ? 'font-semibold text-slate-800 dark:text-slate-200' : 'text-slate-500 dark:text-slate-400' }} {{ !$loop->last ? 'shrink-0' : 'truncate' }}">
@if(!$link['active'] && $link['url'] !== '#')
<a class="hover:text-cyan-600 transition-colors" href="{{ $link['url'] }}">
{{ $link['label'] }}
</a>
@else
{{ $link['label'] }}
@endif
@if(!$loop->last)
<svg class="flex-shrink-0 mx-3 overflow-visible h-2.5 w-2.5 text-slate-400 dark:text-slate-600" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 1L10.6869 7.16086C10.8637 7.35239 10.8637 7.64761 10.6869 7.83914L5 14" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
@endif
</li>
@endforeach
</ol>
</nav>