链街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.

90 lines
2.6 KiB

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