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

93 lines
2.8 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\v3\CategoryTieForm;
  13. use App\Libs\SsdbClient;
  14. class CategoryController extends AdminController
  15. {
  16. public function index(Content $content)
  17. {
  18. return $content->header('分类')
  19. ->body(function (Row $row) {
  20. $tree = new Tree(new Category);
  21. $tree->branch(function ($branch) {
  22. // 查询分类ssdb
  23. $ssdb = new SsdbClient();
  24. $category = $ssdb->client()->hgetall('applet_index_category');
  25. $select = array_keys($category);
  26. $src = $branch['cover_img_url'];
  27. $logo = "<img src='$src' style='margin-left: 20px; max-width:35px;max-height:35px' class='img'/>";
  28. $actions = '';
  29. $actions = (in_array($branch['id'],$select)) ?'<span style="margin-left: 20px;color: #dda451;">在首页显示'.'【'.$branch['sort'].'】</span>' :$actions;
  30. return "{$branch['id']} - {$branch['title']} $logo $actions ";
  31. });
  32. $tree->tools(function (Tree\Tools $tools) {
  33. $tools->add(new CategoryTie());
  34. });
  35. $row->column(12, $tree);
  36. });
  37. }
  38. public function form()
  39. {
  40. return Form::make(new Category(),function (Form $form){
  41. // 只查一级
  42. $parentList = Category::getArray([['parent_id','=',0]],['顶级'=>0]);
  43. $form->select('parent_id')->default(0)->options($parentList);
  44. $form->text('title')->required();
  45. $form->image('cover_img')->autoUpload()->required()->uniqueName();
  46. $form->number('sort');
  47. $form->radio('status')->options([0 => '禁用', 1 => '正常']);
  48. $form->disableResetButton();
  49. $form->disableViewCheck();
  50. $form->disableEditingCheck();
  51. $form->disableCreatingCheck();
  52. });
  53. }
  54. public function categoryTieForms(Content $content)
  55. {
  56. return $content
  57. ->title('绑定分类到首页')
  58. ->body(new Card(new CategoryTieForm()));
  59. }
  60. /**
  61. * Make a show builder.
  62. *
  63. * @param mixed $id
  64. *
  65. * @return Show
  66. */
  67. protected function detail($id)
  68. {
  69. return Show::make($id, new Category(), function (Show $show) {
  70. $show->field('parent_id');
  71. $show->field('title');
  72. $show->field('cover_img')->image();
  73. $show->field('sort');
  74. $show->field('status');
  75. });
  76. }
  77. }