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

<?php
namespace App\Admin\Controllers\v3;
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;
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) {
$src = $branch['cover_img_url'];
$logo = "<img src='$src' style='margin-left: 20px; max-width:35px;max-height:35px' class='img'/>";
$actions = '<a href="/admin/category/TieForm/'.$branch['id'].'" style="margin-left: 20px;">绑定</a>';
return "{$branch['id']} - {$branch['title']} $logo $actions";
});
$row->column(12, $tree);
});
}
public function form()
{
return Form::make(new Category(),function (Form $form){
// 只查一级
$parentList = Category::getCategoryArray([['parent_id','=',0]],[0=>'顶级']);
$form->select('parent_id')->default(0)->options($parentList);
$form->text('title');
$form->image('cover_img');
$form->number('sort');
$form->disableResetButton();
$form->disableViewCheck();
$form->disableEditingCheck();
$form->disableCreatingCheck();
});
}
/**
* 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');
});
}
}