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.
|
|
<?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;use App\Libs\SsdbClient;use App\Constants\v3\SsdbKeys;
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) { $menuName = $show->model()->menu_name; $show->field('id'); $show->field('menu_name'); $show->field('category_text'); $show->field('value')->width(6); if($menuName == 'initial_delivery_amount'){ $delivery = SsdbClient::client()->get(SsdbKeys::INTIAL_DELIVERY_AMOUNT); $show->field('value_text','已存ssdb的值:')->width(6)->value($delivery); } $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) { $menuName = $form->model()->menu_name; $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); $deliveryForm = $form->text('value')->required()->width(6)->maxLength(100);
if($menuName == 'initial_delivery_amount'){ $delivery = SsdbClient::client()->get(SsdbKeys::INTIAL_DELIVERY_AMOUNT); $deliveryForm->help('已存ssdb的值:'.$delivery); }
$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'); $menuName = $form->input('menu_name'); if($id && $menuName ){ $form->deleteInput('menu_name'); } if($id && $menuName == 'initial_delivery_amount'){ $delivery = $form->input('value'); SsdbClient::client()->set(SsdbKeys::INTIAL_DELIVERY_AMOUNT,$delivery); } }); $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(); }); }}
|