1 创建Action并调用
1.使用命令创建Action类(TestAction)
php artisan admin:action
详见手册https://learnku.com/docs/dcat-admin/1.x/basic-use/8124
2.在控制器grid()中添加额外行操作
protected function grid()
{
return Grid::make(), function (Grid $grid) {
$grid->column('xxxx');
···
···
···
···
//添加额外的操作
$grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->append(new TestAction());
});
});
}
2 自定义弹框页面的实现
方法一:通过js实现
<?php
namespace App\Admin\Actions;
use Dcat\Admin\Grid\RowAction;
class TestAction extends RowAction
{
/**
* @return string
*/
protected $title = 'Title';
protected $model;
public function __construct(string $model = null)
{
$this->model = $model;
}
public function title()
{
return 'test';
}
protected function script()
{
return <<<JS
$('.grid-check-row').on('click',function (){
layer.open({
type: 2,
title: '我是标题',
closeBtn: 1,
shadeClose: true,
//页面路由
content: "/test/page",
area:["800px","310px"]
});
});
JS;
}
public function html()
{
$id = $this->getKey();
$name = $this->row->receiver_name;
$this->setHtmlAttribute(['data-id'=>$id,'receiver_name'=>$name,'class'=>'grid-check-row']);
return parent::html();
}
}
方法二:调用Action中的render()
<?php
namespace App\Admin\Actions;
use App\Admin\Renderable\OrderDetailTable;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Widgets\Modal;
class TestAction extends RowAction
{
/**
* @return string
*/
protected $title = 'test';
public function render()
{
$form = OrderDetailTable::make(['id'=>$this->getKey()]);
return Modal::make()
->xl()
->title($this->title)
->body($form)
->button('test');
}
}
OrderDetailTable.php
<?php
namespace App\Admin\Renderable;
use Dcat\Admin\Support\LazyRenderable;
class OrderDetailTable extends LazyRenderable
{
public function render()
{
//自定义页面
return view('upTest');
}
}
如果想实现表格弹框可对OrderDetailTable.php进行如下修改(注意继承的LazyRenderable)
<?php
namespace App\Admin\Renderable;
use App\Models\OrderDetail;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
class OrderDetailTable extends LazyRenderable
{
public function grid(): Grid
{
return Grid::make(new OrderDetail(),function (Grid $grid){
$grid->column('id');
// $grid->disableActions();
});
}
}
如果想实现表单弹框,可参考官方文档-工具表单