123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Actions\Grid\AppearanceImport;
- use App\Admin\Repositories\DistAppearance;
- use App\Libraries\CommonHelper;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Admin;
- class DistAppearanceController extends AdminController
- {
- /**
- * page index
- */
- public function index(Content $content)
- {
- return $content
- ->header(admin_trans( 'admin.appearance'))
- ->description('')
- ->breadcrumb(['text'=>'list','url'=>''])
- ->body($this->grid());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new DistAppearance(), function (Grid $grid) {
- $grid->column('id')->sortable();
- // 标题
- $grid->column('title');
- // 文件夹
- $grid->column('folder')->help('Folder names under the directory:/resources/appearance');
- // 封面图
- $grid->column('cover_image')->display(function ($image) {
- $dataImages = [$image];
- return CommonHelper::displayImage($dataImages,100);
- });
- // 排序
- $grid->column('order')->orderable();
- //是否导入
- $grid->column('imported')->using(config('dictionary.whether'))->label([
- 0 => 'default',
- 1 => 'success',
- ]);
- //是否启用
- $grid->column('enabled')->switch();
- // 时间
- $grid->column('created_at');
- $grid->column('updated_at')->sortable();
- // 过滤器
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->expand();
- $filter->equal('title')->width(2);
- $filter->equal('enabled', )->select(admin_trans_array(config('dictionary.enabled')))->width(2);
- });
- // 操作
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableDelete();
- $actions->append(new AppearanceImport());
- });
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new DistAppearance(), function (Show $show) {
- $show->field('id');
- $show->field('title');
- $show->field('folder');
- $show->field('cover_image')->as(function ($image) {
- // 开始生成 HTML
- $dataImages = [$image];
- return CommonHelper::displayImage($dataImages,100);
- })->unescape();
- $show->field('describe');
- $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled')));
- $show->field('created_at');
- $show->field('updated_at');
- $show->disableDeleteButton();
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new DistAppearance(), function (Form $form) {
- $form->display('id');
- $form->text('title');
- $form->text('folder');
- $form->image("cover_image")
- ->autoUpload()
- ->uniqueName()
- ->accept(config('admin.upload.oss_image.accept'))
- ->maxSize(config('admin.upload.oss_image.max_size'))
- ->dir(config("admin.upload.directory.image").'/appearance/'.date("Ymd"));//
- $form->textarea('describe');
- $form->switch('enabled')->default(0);
- $form->saving(function (Form $form) {
- if ($form->isCreating() && $form->input('enabled') == 1) {
- return $form->response()->error('Please create the template first, then import it, and finally enable it.');
- }
- if (!$form->isCreating()) {
- if ($form->input('enabled') == 1 && $form->model()->imported == 0) {
- return $form->response()->error('Please select the import option first, then enable it.');
- }
- }
- });
- $form->disableDeleteButton();
- });
- }
- }
|