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.
100 lines
3.0 KiB
100 lines
3.0 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers\v3;
|
|
|
|
use App\Admin\Repositories\v3\SystemConfig;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use App\Models\v3\SystemConfig as SystemConfigModel;
|
|
|
|
class SystemConfigController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new SystemConfig(), function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('menu_name');
|
|
$grid->column('info');
|
|
$grid->column('value');
|
|
$grid->column('category_text');
|
|
$grid->column('sort');
|
|
$grid->column('status')->switch();
|
|
|
|
$grid->model()->orderby('id','desc');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
$filter->like('menu_name');
|
|
$filter->equal('category')->select(SystemConfigModel::$_CATEGORY);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new SystemConfig(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('menu_name');
|
|
$show->field('category_text');
|
|
$show->field('value');
|
|
$show->field('info');
|
|
$show->field('desc');
|
|
$show->field('sort');
|
|
$show->field('status_text');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new SystemConfig(), function (Form $form) {
|
|
$form->hidden('id');
|
|
|
|
$form->text('menu_name')->width(4)->required()->rules('regex:/^[0-9a-z_]{1,}$/',['regex'=>'只能输入数字、小写字母和下划线'])->help('本字段在添加成功后不能编辑!');
|
|
$form->select('category')->width(4)->options(SystemConfigModel::$_CATEGORY);
|
|
$form->text('value')->required()->width(6)->maxLength(100);
|
|
$form->text('info')->maxLength(255);
|
|
$form->text('desc')->maxLength(500);
|
|
$form->number('sort')->width(2)->default(0);
|
|
|
|
$form->saving(function(Form $form){
|
|
$id = $form->input('id');
|
|
if($id && $form->input('menu_name') ){
|
|
$form->deleteInput('menu_name');
|
|
}
|
|
});
|
|
$form->switch('status')
|
|
->customFormat(function ($v) {
|
|
return $v == 1 ? 1 : 0;
|
|
})
|
|
->saving(function ($v) {
|
|
return $v == 1 ? 1 : 0;
|
|
});
|
|
|
|
$form->disableResetButton();
|
|
$form->disableViewCheck();
|
|
$form->disableEditingCheck();
|
|
$form->disableCreatingCheck();
|
|
});
|
|
}
|
|
}
|