1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Distributor\Controllers;
- use App\Distributor\Repositories\SiteBanner;
- 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 SiteBannerController extends AdminDistController
- {
- public function title()
- {
- return admin_trans('admin.banner_list');
- }
- /**
- * page index
- */
- public function index(Content $content)
- {
- return $content
- ->header($this->title())
- ->body($this->grid());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new SiteBanner(), function (Grid $grid) {
- $grid->column('id')->display(function () {
- return $this->_index+1;
- });
- $grid->column('title')->width('25%');
- $grid->column('subtitle')->width('25%');
- $grid->column('image_url',admin_trans_label('images'))->display(function ($image) {
- // 开始生成 HTML
- $dataImages = [$image];
- return CommonHelper::displayImage($dataImages,100);
- });
- $grid->column('position');
- $grid->column('order');
- $grid->column('show')->switch();
- $grid->disableViewButton();
- $grid->showQuickEditButton();
- $grid->enableDialogCreate();
- $grid->disableEditButton();
- $grid->model()->where('dist_id', getDistributorId())->orderBy('order', 'desc')->orderBy('id', 'desc');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new SiteBanner(), function (Form $form) {
- $form->text('title')->required();
- $form->text('subtitle');
- $form->image("image_url", admin_trans_label('images'))
- ->retainable()//禁止删OSS图
- ->autoUpload()
- ->uniqueName()
- ->accept(config('distributor.upload.oss_image.accept'))
- ->maxSize(config('distributor.upload.oss_image.max_size'))
- ->dir(config("distributor.upload.directory.image").'/banner/'.date("Ymd"));
- $form->text('banner_url');
- $form->number('position')->default(1);
- $form->number('order')->default(0);
- $form->switch('show')->default(1);
- $form->hidden('dist_id');
- $form->saving(function (Form $form) {
- $form->dist_id =getDistributorId();//保存时直接写死dist_id
- });
- });
- }
- }
|