5 changed files with 131 additions and 0 deletions
-
82app/Admin/Controllers/CategoryController.php
-
16app/Admin/Repositories/Category.php
-
1app/Admin/routes.php
-
17app/Models/Category.php
-
15resources/lang/zh_CN/category.php
@ -0,0 +1,82 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers; |
|||
|
|||
use App\Common\UserStatus; |
|||
use App\Models\Category; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Layout\Content; |
|||
use Dcat\Admin\Layout\Row; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Http\Controllers\AdminController; |
|||
use Dcat\Admin\Tree; |
|||
|
|||
class CategoryController extends AdminController |
|||
{ |
|||
public function index(Content $content) |
|||
{ |
|||
return $content->header('产品分类') |
|||
->body(function (Row $row) { |
|||
$tree = new Tree(new Category); |
|||
$tree->expand(); |
|||
$tree->query(function ($model) { |
|||
//agent_id为0是系统分类,其它是代理商分类
|
|||
return $model->where('agent_id', 0); |
|||
}); |
|||
$row->column(12, $tree); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make(new Category(), function (Grid $grid) { |
|||
$grid->column('id')->sortable(); |
|||
$grid->column('pid'); |
|||
$grid->column('name'); |
|||
$grid->column('sort'); |
|||
|
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->equal('id'); |
|||
|
|||
}); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a show builder. |
|||
* |
|||
* @param mixed $id |
|||
* |
|||
* @return Show |
|||
*/ |
|||
protected function detail($id) |
|||
{ |
|||
return Show::make($id, new Category(), function (Show $show) { |
|||
$show->field('id'); |
|||
$show->field('pid'); |
|||
$show->field('name'); |
|||
$show->field('sort'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
return Form::make(new Category(), function (Form $form) { |
|||
$form->display('id'); |
|||
$form->select('pid')->options(Category::selectOptions()); |
|||
$form->text('name'); |
|||
$form->text('sort')->default(255); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Repositories; |
|||
|
|||
use App\Models\Category as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class Category extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'Category' => '产品分类', |
|||
'category' => '产品分类', |
|||
], |
|||
'fields' => [ |
|||
'agent_id' => '代理商ID', |
|||
'pid' => '上级ID', |
|||
'name' => '类目名称', |
|||
'sort' => '排序', |
|||
], |
|||
'options' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue