为dcat admin的无限菜单添加背景颜色

介绍

为dcat admin的菜单添加背景颜色

代码修改

@php
    $depth = $item['depth'] ?? 0;

    $horizontal = config('admin.layout.horizontal_menu');

    $defaultIcon = config('admin.menu.default_icon', 'feather icon-circle');

    // 定义每一级的背景色数组
    $backgroundColors = ['#129560', '#78C3A5', '#cbe7dd']; // 你可以根据需要修改颜色
    $backgroundColor = $backgroundColors[$depth % count($backgroundColors)];

    // 定义圆角大小(百分比)
    $borderRadiusPercentage = '4px'; // 你可以根据需要修改圆角大小
@endphp

@if($builder->visible($item))
    @if(empty($item['children']))
        <li class="nav-item">
            <a data-id="{{ $item['id'] ?? '' }}" @if(mb_strpos($item['uri'], '://') !== false) target="_blank" @endif
            href="{{ $builder->getUrl($item['uri']) }}"
               class="nav-link {!! $builder->isActive($item) ? 'active' : '' !!}"
               style="background-color: {{ $backgroundColor }}; border-radius: {{ $borderRadiusPercentage }};"> <!-- 添加背景色和圆角 -->
                {!! str_repeat('&nbsp;', $depth) !!}<i class="fa fa-fw {{ $item['icon'] ?: $defaultIcon }}"></i>
                <p>
                    {!! $builder->translate($item['title']) !!}
                </p>
            </a>
        </li>
    @else

        <li class="{{ $horizontal ? 'dropdown' : 'has-treeview' }} {{ $depth > 0 ? 'dropdown-submenu' : '' }} nav-item {{ $builder->isActive($item) ? 'menu-open' : '' }}">
            <a href="#"  data-id="{{ $item['id'] ?? '' }}"
               class="nav-link {{ $builder->isActive($item) ? ($horizontal ? 'active' : '') : '' }}
               {{ $horizontal ? 'dropdown-toggle' : '' }}"
               style="background-color: {{ $backgroundColor }}; border-radius: {{ $borderRadiusPercentage }};"> <!-- 添加背景色和圆角 -->
                {!! str_repeat('&nbsp;', $depth) !!}<i class="fa fa-fw {{ $item['icon'] ?: $defaultIcon }}"></i>
                <p>
                    {!! $builder->translate($item['title']) !!}

                    @if(! $horizontal)
                        <i class="right fa fa-angle-left"></i>
                    @endif
                </p>
            </a>
            <ul class="nav {{ $horizontal ? 'dropdown-menu' : 'nav-treeview' }}">
                @foreach($item['children'] as $item)
                    @php
                        $item['depth'] = $depth + 1;
                    @endphp

                    @include('admin::partials.menu', ['item' => $item])
                @endforeach
            </ul>
        </li>
    @endif
@endif
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

能不能给个效果图,能直观的看看是什么效果

3个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!