SiteAlbumFolderController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\SiteAlbumFolder;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use Dcat\Admin\Layout\Content;
  9. use Dcat\Admin\Admin;
  10. class SiteAlbumFolderController extends AdminController
  11. {
  12. /**
  13. * page index
  14. */
  15. public function index(Content $content)
  16. {
  17. return $content
  18. ->header(admin_trans( 'admin.folder'))
  19. ->body($this->grid());
  20. }
  21. /**
  22. * Make a grid builder.
  23. *
  24. * @return Grid
  25. */
  26. protected function grid()
  27. {
  28. return Grid::make(new SiteAlbumFolder(), function (Grid $grid) {
  29. $grid->column('id')->sortable();
  30. $grid->column('title')->display(function ($title) {
  31. $level = $this->level; // 获取当前行的 level 字段值
  32. $prefix = str_repeat('&nbsp; ', $level * 2). ' <i class="fa fa-angle-right"></i>&nbsp; '; // 生成 level * 3 个加号
  33. return $prefix . ' ' . html_entity_decode($title); // 拼接加号和名称
  34. });;
  35. $grid->column('parent_id');
  36. $grid->column('order')->sortable();
  37. $grid->column('enabled')->switch();
  38. $grid->column('created_at')->sortable();
  39. $grid->disableViewButton();
  40. $grid->showQuickEditButton();
  41. $grid->enableDialogCreate();
  42. $grid->disableEditButton();
  43. $grid->disablePerPages();
  44. });
  45. }
  46. /**
  47. * Make a form builder.
  48. *
  49. * @return Form
  50. */
  51. protected function form()
  52. {
  53. return Form::make(new SiteAlbumFolder(), function (Form $form) {
  54. $form->select('parent_id', admin_trans_field('parent'))
  55. ->options(SiteAlbumFolder::selectMainOptions())
  56. ->saving(function ($v) {
  57. return (int) $v;
  58. });
  59. $form->text('title')->required();
  60. $form->radio('folder_type')
  61. ->options(admin_trans_array(config('dictionary.folder_type')))
  62. ->default(0)->required();
  63. $form->listbox('show_tabs')->options(admin_trans_array([
  64. '0' => 'cover',
  65. '1' => 'en_detail',
  66. '2' => 'cn_detail',
  67. '3' => 'video',
  68. '4' => 'poster',
  69. '5' => 'cert',
  70. '6' => 'pdf',
  71. ]))->default([0, 1, 2, 3, 4, 5, 6])->saving(function ($v) { return json_encode($v); });
  72. $form->number('order')
  73. ->default(0)
  74. ->rules('numeric');
  75. $form->switch('enabled')->default(1);
  76. });
  77. }
  78. }