| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Repositories\Config;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Support\JavaScript;
- use Dcat\Admin\Http\Controllers\AdminController;
- class ConfigController extends AdminController
- {
- // public $types=['文本框','数值','编辑器'];
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new Config(), function (Grid $grid) {
- // $grid->column('id')->sortable();
- $grid->column('name')->width("150px");
- $grid->column('key');
- $grid->column('val')->display(function() {
- return $this->type==1? $this->val1: $this->val;
- });
- $grid->column('beizhu');
- // $grid->column('created_at');
- $grid->column('updated_at')->sortable();
- $grid->model()->whereNotIn("key",['box_level_percent','box_level_paster','coupon_configs']);
- // $grid->filter(function (Grid\Filter $filter) {
- // $filter->equal('id');
- // });
- $grid->model()->orderBy("id","desc");
- // $grid->enableDialogCreate();
- // $grid->setDialogFormDimensions('70%', '60%');
- $grid->withBorder();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- // $actions->quickEdit(true);
- // $actions->disableEdit();
- $actions->disableView();
- });
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new Config(), function (Show $show) {
- $show->field('id');
- $show->field('key');
- $show->field('val');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new Config(), function (Form $form) {
- // $form->display('id');
- $form->text('name');
- if ($form->isCreating()) {
- $form->text('key')->required();
- } else {
- $form->text('key')->readonly();
- }
- $form->radio('type')
- ->when(0, function (Form $form) {
- $form->text('val','内容');
- })
- ->when(1, function (Form $form) {
- $form->editor('val1','内容')->options([
- 'toolbar' => [],
- 'setup' => JavaScript::make(
- <<<JS
- function (editor) {
- console.log('编辑器初始化成功', editor)
- }
- JS
- ),
- ]);
- })
- ->options([
- 0 => '显示文本框',
- 1 => '显示编辑器',
- ])->default(0);
- //
- $form->textarea('beizhu');
- // $form->display('created_at');
- // $form->display('updated_at');
- });
- }
- }
|