DropdownController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Tests\Controllers;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Layout\Content;
  5. use Dcat\Admin\Layout\Row;
  6. use Dcat\Admin\Widgets\Box;
  7. use Dcat\Admin\Widgets\Code;
  8. use Dcat\Admin\Widgets\Dropdown;
  9. use Illuminate\Routing\Controller;
  10. class DropdownController extends Controller
  11. {
  12. protected $tian = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'];
  13. protected $di = ['寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥', '子', '丑'];
  14. public function index(Content $content)
  15. {
  16. return $content->header('Dropdown Menu')
  17. ->row(function (Row $row) {
  18. $row->column(3, $this->example1());
  19. $row->column(3, $this->example2());
  20. $row->column(3, $this->example3());
  21. });
  22. }
  23. protected function example1()
  24. {
  25. $menu1 = Dropdown::make($this->tian)->button('天干');
  26. $menu2 = Dropdown::make()
  27. ->button('使用标题')
  28. ->buttonClass('btn btn-sm btn-inverse')
  29. ->options($this->tian, '天干')
  30. ->options($this->di, '地支');
  31. $menu3 = Dropdown::make([1, 2, 3, Dropdown::DIVIDER, 4, 5])->button('中间加分隔线');
  32. return Box::make(
  33. 'Example1',
  34. $menu1->render().' &nbsp; '.$menu2->render().' &nbsp; '.$menu3->render()
  35. );
  36. }
  37. protected function example2()
  38. {
  39. $menu = Dropdown::make($this->tian);
  40. $menu->map(function ($v, $k) {
  41. if ($k === 7) {
  42. $this->divider();
  43. }
  44. $k++;
  45. return "{$k}. $v";
  46. });
  47. return Box::make('Example2', function () use ($menu) {
  48. 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>";
  49. });
  50. }
  51. protected function example3()
  52. {
  53. $menu1 = Dropdown::make()
  54. ->options($this->tian, '天干')
  55. ->options($this->di, '地支')
  56. ->click()
  57. ->buttonClass('btn btn-sm btn-light')
  58. ->map(function ($v, $k) {
  59. $k++;
  60. return "<a class='test_item' data-id='$k', data-value='{$v}' data-test='Hello world.' href='javascript:void(0)'>{$k}. $v</a>";
  61. });
  62. Admin::script(
  63. <<<JS
  64. $('.test_item').click(function () {
  65. LA.info("Selected: " + JSON.stringify($(this).data()));
  66. });
  67. JS
  68. );
  69. return Box::make('Example3', $menu1);
  70. }
  71. }