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

92 lines
2.7 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')->required()->uniqueName();
  46. $form->number('sort');
  47. $form->disableResetButton();
  48. $form->disableViewCheck();
  49. $form->disableEditingCheck();
  50. $form->disableCreatingCheck();
  51. });
  52. }
  53. public function categoryTieForms(Content $content)
  54. {
  55. return $content
  56. ->title('绑定分类到首页')
  57. ->body(new Card(new CategoryTieForm()));
  58. }
  59. /**
  60. * Make a show builder.
  61. *
  62. * @param mixed $id
  63. *
  64. * @return Show
  65. */
  66. protected function detail($id)
  67. {
  68. return Show::make($id, new Category(), function (Show $show) {
  69. $show->field('parent_id');
  70. $show->field('title');
  71. $show->field('cover_img')->image();
  72. $show->field('sort');
  73. $show->field('status');
  74. });
  75. }
  76. }