链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.0 KiB

  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Category;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Layout\Row;
  6. use Dcat\Admin\Layout\Content;
  7. use Dcat\Admin\Tree;
  8. use Dcat\Admin\Controllers\AdminController;
  9. use Dcat\Admin\Show;
  10. class CategoryController extends AdminController
  11. {
  12. public function index(Content $content)
  13. {
  14. return $content->header('分类')
  15. ->body(function (Row $row) {
  16. $tree = new Tree(new Category);
  17. $tree->branch(function ($branch) {
  18. $src = $branch['cover_img_url'];
  19. $logo = "<img src='$src' style='margin-left: 20px; max-width:35px;max-height:35px' class='img'/>";
  20. $actions = '<a href="/admin/category/TieForm/'.$branch['id'].'" style="margin-left: 20px;">绑定</a>';
  21. return "{$branch['id']} - {$branch['title']} $logo $actions";
  22. });
  23. $row->column(12, $tree);
  24. });
  25. }
  26. public function form()
  27. {
  28. return Form::make(new Category(),function (Form $form){
  29. // 只查一级
  30. $parentList = Category::getCategoryArray([['parent_id','=',0]],[0=>'顶级']);
  31. $form->select('parent_id')->default(0)->options($parentList);
  32. $form->text('title');
  33. $form->image('cover_img');
  34. $form->number('sort');
  35. $form->disableResetButton();
  36. $form->disableViewCheck();
  37. $form->disableEditingCheck();
  38. $form->disableCreatingCheck();
  39. });
  40. }
  41. /**
  42. * Make a show builder.
  43. *
  44. * @param mixed $id
  45. *
  46. * @return Show
  47. */
  48. protected function detail($id)
  49. {
  50. return Show::make($id, new Category(), function (Show $show) {
  51. $show->field('parent_id');
  52. $show->field('title');
  53. $show->field('cover_img')->image();
  54. $show->field('sort');
  55. $show->field('status');
  56. });
  57. }
  58. }