Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

semour / semour_admin

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • semour_admin
  • vendor
  • dcat
  • laravel-admin
  • tests
  • Controllers
  • DropdownController.php
DropdownController.php 2.5 KB
mushishixian's avatar
安装laraveladmin
8ae169e3
 
mushishixian committed 2 years ago
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
<?php

namespace Tests\Controllers;

use Dcat\Admin\Admin;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Box;
use Dcat\Admin\Widgets\Dropdown;
use Illuminate\Routing\Controller;

class DropdownController extends Controller
{
    protected $tian = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'];
    protected $di = ['寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥', '子', '丑'];

    public function index(Content $content)
    {
        return $content->header('Dropdown Menu')
            ->row(function (Row $row) {
                $row->column(3, $this->example1());
                $row->column(3, $this->example2());
                $row->column(3, $this->example3());
            });
    }

    protected function example1()
    {
        $menu1 = Dropdown::make($this->tian)->button('天干');

        $menu2 = Dropdown::make()
            ->button('使用标题')
            ->buttonClass('btn btn-sm btn-inverse')
            ->options($this->tian, '天干')
            ->options($this->di, '地支');

        $menu3 = Dropdown::make([1, 2, 3, Dropdown::DIVIDER, 4, 5])->button('中间加分隔线');

        return Box::make(
            'Example1',
            $menu1->render().' &nbsp; '.$menu2->render().' &nbsp; '.$menu3->render()
        );
    }

    protected function example2()
    {
        $menu = Dropdown::make($this->tian);

        $menu->map(function ($v, $k) {
            if ($k === 7) {
                $this->divider();
            }
            $k++;

            return "{$k}. $v";
        });

        return Box::make('Example2', function () use ($menu) {
            return "<div class='dropdown'><a class='btn no-shadow text-muted' data-toggle='dropdown' href='javascript:void(0)'><i class='ti-email'></i> 自定义按钮 </a>{$menu->render()}</div>";
        });
    }

    protected function example3()
    {
        $menu1 = Dropdown::make()
            ->options($this->tian, '天干')
            ->options($this->di, '地支')
            ->click()
            ->buttonClass('btn btn-sm btn-light')
            ->map(function ($v, $k) {
                $k++;

                return "<a class='test_item' data-id='$k', data-value='{$v}' data-test='Hello world.' href='javascript:void(0)'>{$k}. $v</a>";
            });

        Admin::script(
            <<<'JS'
$('.test_item').click(function () {
    LA.info("Selected: " + JSON.stringify($(this).data()));
});
JS
        );

        return Box::make('Example3', $menu1);
    }
}