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
93 lines
2.8 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers\v3;
|
|
|
|
use App\Admin\Actions\Tree\CategoryTie;
|
|
use App\Models\v3\Category;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Layout\Row;
|
|
use Dcat\Admin\Layout\Content;
|
|
use Dcat\Admin\Tree;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Widgets\Card;
|
|
use App\Admin\Forms\v3\CategoryTieForm;
|
|
use App\Libs\SsdbClient;
|
|
|
|
class CategoryController extends AdminController
|
|
{
|
|
public function index(Content $content)
|
|
{
|
|
return $content->header('分类')
|
|
->body(function (Row $row) {
|
|
$tree = new Tree(new Category);
|
|
|
|
$tree->branch(function ($branch) {
|
|
// 查询分类ssdb
|
|
$ssdb = new SsdbClient();
|
|
$category = $ssdb->client()->hgetall('applet_index_category');
|
|
$select = array_keys($category);
|
|
|
|
$src = $branch['cover_img_url'];
|
|
$logo = "<img src='$src' style='margin-left: 20px; max-width:35px;max-height:35px' class='img'/>";
|
|
|
|
$actions = '';
|
|
$actions = (in_array($branch['id'],$select)) ?'<span style="margin-left: 20px;color: #dda451;">在首页显示'.'【'.$branch['sort'].'】</span>' :$actions;
|
|
|
|
return "{$branch['id']} - {$branch['title']} $logo $actions ";
|
|
});
|
|
$tree->tools(function (Tree\Tools $tools) {
|
|
$tools->add(new CategoryTie());
|
|
});
|
|
|
|
$row->column(12, $tree);
|
|
});
|
|
}
|
|
|
|
public function form()
|
|
{
|
|
return Form::make(new Category(),function (Form $form){
|
|
|
|
// 只查一级
|
|
$parentList = Category::getArray([['parent_id','=',0]],['顶级'=>0]);
|
|
|
|
$form->select('parent_id')->default(0)->options($parentList);
|
|
$form->text('title')->required();
|
|
$form->image('cover_img')->autoUpload()->required()->uniqueName();
|
|
|
|
$form->number('sort');
|
|
$form->radio('status')->options([0 => '禁用', 1 => '正常']);
|
|
|
|
$form->disableResetButton();
|
|
$form->disableViewCheck();
|
|
$form->disableEditingCheck();
|
|
$form->disableCreatingCheck();
|
|
});
|
|
}
|
|
|
|
public function categoryTieForms(Content $content)
|
|
{
|
|
return $content
|
|
->title('绑定分类到首页')
|
|
->body(new Card(new CategoryTieForm()));
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Category(), function (Show $show) {
|
|
|
|
$show->field('parent_id');
|
|
$show->field('title');
|
|
$show->field('cover_img')->image();
|
|
$show->field('sort');
|
|
$show->field('status');
|
|
});
|
|
}
|
|
}
|