提交代码
This commit is contained in:
85
app/Admin/Controllers/AreaController.php
Normal file
85
app/Admin/Controllers/AreaController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\AreaSetManage;
|
||||
use App\Admin\Exporters\ProvinceExporter;
|
||||
use App\Models\User;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use RuLong\Area\Models\Area;
|
||||
|
||||
class AreaController extends AdminController
|
||||
{
|
||||
protected $title = '省市管理';
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new Area);
|
||||
$grid->disableCreateButton();
|
||||
// $grid->disableActions();
|
||||
$grid->exporter(new ProvinceExporter());
|
||||
$grid->model()->where('depth', '<', 3);
|
||||
|
||||
$grid->actions(function ($actions) {
|
||||
if ($this->row->type == '地级') {
|
||||
$actions->add(new AreaSetManage);
|
||||
}
|
||||
$actions->disableView();
|
||||
$actions->disableEdit();
|
||||
$actions->disableDelete();
|
||||
});
|
||||
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 3, function ($filter) {
|
||||
$filter->like('name', '省市全称');
|
||||
$filter->equal('hot', '是否热门')->select([
|
||||
' ' => '全部',
|
||||
'1' => '是',
|
||||
'0' => '否',
|
||||
]);
|
||||
});
|
||||
|
||||
$filter->column(1 / 3, function ($filter) {
|
||||
$filter->equal('type', '等级')->select([
|
||||
' ' => '全部',
|
||||
'省级' => '省级',
|
||||
'地级' => '地级',
|
||||
]);
|
||||
});
|
||||
});
|
||||
$grid->column('sn', '排序')->sortable();
|
||||
$states = [
|
||||
'on' => ['value' => 1, 'text' => '是', 'color' => 'primary'],
|
||||
'off' => ['value' => 0, 'text' => '否', 'color' => 'default'],
|
||||
];
|
||||
$grid->column('name', '省市全称');
|
||||
$grid->column('type', '等级');
|
||||
$grid->column('管理人')->display(function ($title, $column) use ($grid) {
|
||||
if ($this->user) {
|
||||
return $this->user->info->nickname;
|
||||
} else {
|
||||
return '---';
|
||||
}
|
||||
});
|
||||
$grid->column('shortname', '简称');
|
||||
// $grid->column('cnname', '拼音');
|
||||
// $grid->column('enname', '英文');
|
||||
$grid->column('hot', '是否热门')->switch($states);
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new Area);
|
||||
$form->switch('hot', '是否热门')->default(1);
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user