37 lines
1.5 KiB
PHP
37 lines
1.5 KiB
PHP
@props(['aMenus', 'cPathKeys', 'iCurrentLevel' => 1])
|
|
|
|
@foreach(collect($aMenus)->groupBy('sGroup') as $sGroup => $aGroupMenus)
|
|
@if (!empty($sGroup) && $iCurrentLevel === 1)
|
|
{{-- 仅在第一层渲染分组大标题 --}}
|
|
<div class="mac-meta-title">{{ __('menu.'.$sGroup) }}</div>
|
|
@endif
|
|
|
|
@foreach($aGroupMenus as $aMenu)
|
|
@php
|
|
// 从激活链路数组里拿到当前层级的激活 ID
|
|
$iActiveIdForLevel = $cPathKeys->get($iCurrentLevel - 1);
|
|
$bIsActive = ($aMenu['iId'] == $iActiveIdForLevel);
|
|
$bHasChildren = !empty($aMenu['children_recursive']);
|
|
@endphp
|
|
|
|
<div class="mac-menu-item-wrapper level-{{ $iCurrentLevel }}">
|
|
<a href="{{ $aMenu['sUrl'] }}">
|
|
<div class="mac-item {{ $bIsActive ? 'active' : '' }}">
|
|
{{-- 如果有子节点,可以加一个展开/折叠的小图标 --}}
|
|
@if($bHasChildren) <span class="arrow">▾</span> @endif
|
|
{{ $aMenu["sName"] }}
|
|
</div>
|
|
</a>
|
|
|
|
{{-- 🎯 核心:如果还有子集,并且当前链路处于激活路径上,则递归调用自己 --}}
|
|
@if($bHasChildren && $bIsActive)
|
|
<x-menu-node
|
|
:aMenus="$aMenu['children_recursive']"
|
|
:cPathKeys="$cPathKeys"
|
|
:iCurrentLevel="$iCurrentLevel + 1"
|
|
/>
|
|
@endif
|
|
</div>
|
|
@endforeach
|
|
@endforeach
|