SiteAlbumFolderController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\SiteAlbumFolder;
  4. use App\Libraries\CommonHelper;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. use Dcat\Admin\Layout\Content;
  10. use Dcat\Admin\Admin;
  11. class SiteAlbumFolderController extends AdminController
  12. {
  13. /**
  14. * page index
  15. */
  16. public function index(Content $content)
  17. {
  18. return $content
  19. ->header(admin_trans( 'admin.folder'))
  20. ->body($this->grid());
  21. }
  22. /**
  23. * Make a grid builder.
  24. *
  25. * @return Grid
  26. */
  27. protected function grid()
  28. {
  29. return Grid::make(new SiteAlbumFolder(), function (Grid $grid) {
  30. $grid->view('admin.grid-custom.table');
  31. $grid->column('id')->sortable();
  32. $grid->column('title')->display(function ($title) {
  33. $level = $this->level; // 获取当前行的 level 字段值
  34. $has_children = $this->has_children; // 获取当前行的 has_children 字段值
  35. if ($has_children) {
  36. $prefix = str_repeat('&nbsp; ', $level * 2). ' <i class="fa fa-angle-right"></i>&nbsp; '; // 生成 level * 3 个加号
  37. } else {
  38. $prefix = str_repeat('&nbsp; ', $level * 2). ' &nbsp; '; // 生成 level * 3 个加号
  39. }
  40. return $prefix . ' ' . html_entity_decode($title); // 拼接加号和名称
  41. });
  42. $grid->column('cover') ->display(function ($images) {
  43. return CommonHelper::displayImage([$images],80);
  44. });
  45. //$grid->column('folder_type')->using(admin_trans_array(config('dictionary.folder_type')))->label([0 => 'primary', 1 => 'success',]);
  46. $grid->column('parent_id');
  47. $grid->column('order')->sortable();
  48. $grid->column('enabled')->switch();
  49. $grid->column('created_at')->sortable();
  50. $grid->disableViewButton();
  51. $grid->showQuickEditButton();
  52. $grid->enableDialogCreate();
  53. $grid->disableEditButton();
  54. $grid->disablePerPages();
  55. });
  56. }
  57. /**
  58. * Make a form builder.
  59. *
  60. * @return Form
  61. */
  62. protected function form()
  63. {
  64. return Form::make(new SiteAlbumFolder(), function (Form $form) {
  65. $form->select('parent_id', admin_trans_field('parent'))
  66. ->options(SiteAlbumFolder::selectMainOptions())
  67. ->saving(function ($v) {
  68. return (int) $v;
  69. })->default(0);
  70. $form->text('title')->required();
  71. $form->image('cover')
  72. ->retainable()//禁止删OSS图
  73. ->autoUpload()
  74. ->uniqueName()
  75. ->accept(config('admin.upload.oss_image.accept'))
  76. ->maxSize(config('admin.upload.oss_image.max_size'))
  77. ->dir(config("admin.upload.directory.image").'/uploads/'.date("Ymd"))
  78. ->required();
  79. // $form->radio('folder_type')
  80. // ->options(admin_trans_array(config('dictionary.folder_type')))
  81. // ->default(0)->required();
  82. $form->listbox('show_tabs')->options(admin_trans_array([
  83. '0' => 'cover',
  84. '1' => 'en_detail',
  85. '2' => 'cn_detail',
  86. '3' => 'video',
  87. '4' => 'poster',
  88. '5' => 'cert',
  89. '6' => 'pdf',
  90. ]))->default([0, 1, 2, 3, 4, 5, 6])->saving(function ($v) { return json_encode($v); });
  91. $form->number('order')
  92. ->default(0)
  93. ->rules('numeric');
  94. $form->switch('enabled')->default(1);
  95. });
  96. }
  97. }