WxWallpaperController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\WxWallpaper;
  4. use App\Wen\Utils\Utils;
  5. use App\Models\User\WxUser;
  6. use App\Models\WxWallpapersSubject;
  7. use Dcat\Admin\Form;
  8. use Dcat\Admin\Grid;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. class WxWallpaperController extends AdminController
  12. {
  13. /**
  14. * Make a grid builder.
  15. *
  16. * @return Grid
  17. */
  18. protected function grid()
  19. {
  20. return Grid::make(new WxWallpaper(), function (Grid $grid) {
  21. $grid->quickSearch(['id', 'subject_id','user_id'])->placeholder('搜索图集ID,主题id,标题,作者id...')->width(50);
  22. $grid->column('id')->sortable();
  23. $grid->column('subject_id');
  24. $grid->column('imgs')->display(function ($v) {
  25. if(_empty_($v)){
  26. return '图集里没有图片';
  27. }
  28. $imgs = json_decode($v, true);
  29. $html = '<div style="max-width: 350px; overflow-x: scroll;">';
  30. foreach ($imgs as $img){
  31. $html .= '<img data-action="preview-img" style="max-width: 50px;margin-right: 10px;" src="'.Utils::imgWithStyle($img).'" / >';
  32. }
  33. return $html.'</div>';
  34. })->width('50px');
  35. $grid->column('title');
  36. $grid->column('user_id');
  37. // $grid->column('created_at');
  38. $grid->column('updated_at')->sortable();
  39. $grid->filter(function (Grid\Filter $filter) {
  40. $filter->equal('id');
  41. });
  42. });
  43. }
  44. /**
  45. * Make a show builder.
  46. *
  47. * @param mixed $id
  48. *
  49. * @return Show
  50. */
  51. protected function detail($id)
  52. {
  53. return Show::make($id, new WxWallpaper(), function (Show $show) {
  54. $show->field('id');
  55. $show->field('subject_id');
  56. $show->field('imgs');
  57. $show->field('title');
  58. $show->field('user_id');
  59. $show->field('created_at');
  60. $show->field('updated_at');
  61. });
  62. }
  63. /**
  64. * Make a form builder.
  65. *
  66. * @return Form
  67. */
  68. protected function form()
  69. {
  70. return Form::make(new WxWallpaper(), function (Form $form) {
  71. $form->display('id');
  72. $form->select('subject_id')->required()
  73. ->options(WxWallpapersSubject::pluck('name','id'));
  74. $form->multipleImage('imgs')->required()->url('files/uploads')->uniqueName()->autoUpload()->limit(100)->help('看你主要适配的机型,图片大致跟手机屏幕比例接近即可')->saveAsJson();
  75. $form->text('title')->required();
  76. // $form->select('user_id')->required()->options(WxUser::limit(10)->pluck('user_name','id'));
  77. $form->text('user_id')->required();
  78. $form->display('created_at');
  79. $form->display('updated_at');
  80. $form->deleting(function (Form $form){
  81. global $__MINI_GLOBAL_TENANT_ID__;
  82. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  83. return $form->response()->error('权限不足,不可以删除其他分站对象');
  84. }
  85. });
  86. });
  87. }
  88. }