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