DistAppearanceController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Distributor\Controllers;
  3. use App\Distributor\Repositories\DistAppearance;
  4. use App\Distributor\Actions\AppearanceEnable;
  5. use App\Distributor\Repositories\DistAdminDistributor;
  6. use App\Libraries\CommonHelper;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. use Dcat\Admin\Layout\Content;
  10. class DistAppearanceController extends AdminDistController
  11. {
  12. /**
  13. * page index
  14. */
  15. public function index(Content $content)
  16. {
  17. return $content
  18. ->header(admin_trans( 'admin.site_appearance'))
  19. ->description('')
  20. ->breadcrumb(['text'=>'list','url'=>''])
  21. ->body($this->grid());
  22. }
  23. /**
  24. * Make a grid builder.
  25. *
  26. * @return Grid
  27. */
  28. protected function grid()
  29. {
  30. $distInfo = DistAdminDistributor::getInfo();
  31. return Grid::make(new DistAppearance(), function (Grid $grid) use ($distInfo) {
  32. //指定视图,去掉删除按钮
  33. $grid->view('admin.grid.table');
  34. $grid->column('id')->display(function () {
  35. return $this->_index+1;
  36. });
  37. // 标题
  38. $grid->column('title');
  39. // 封面图
  40. $grid->column('cover_image')->display(function ($image) {
  41. $dataImages = [$image];
  42. return CommonHelper::displayImage($dataImages,100);
  43. })->width('20%');
  44. $grid->column('describe')->width('40%');
  45. $grid->column('isEnabled')->display(function () use ($distInfo) {
  46. if ($this->id == $distInfo->appearance_id) {
  47. return '<span class="label" style="background:#21b978;">'.admin_trans_label('Yes').'</span>';
  48. } else {
  49. return '<span class="label" style="background:#d2d6de;">'.admin_trans_label('No').'</span>';
  50. }
  51. });
  52. //按钮
  53. $grid->disableCreateButton();
  54. $grid->disableDeleteButton();
  55. $grid->disableBatchDelete();
  56. $grid->tools('<a href="'.getDistributorDomain().'" target="_blank"><button class="btn btn-primary grid-refresh btn-mini" style="margin-right:3px"><i class="feather icon-chrome"></i><span class="d-none d-sm-inline">&nbsp; '.admin_trans_label('browse').'</span></button></a>');
  57. // 操作
  58. $grid->actions(function (Grid\Displayers\Actions $actions) {
  59. $actions->disableDelete();
  60. $actions->disableEdit();
  61. $actions->disableView();
  62. $actions->append(new AppearanceEnable());
  63. });
  64. //排序
  65. $grid->model()->where('enabled',1)->orderBy('order','desc')->orderBy('id','desc');
  66. });
  67. }
  68. }