补充提交
parent
0ff3e7c593
commit
3a630ae1a7
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Slowlyo\OwlAdmin\Admin;
|
||||
use Slowlyo\OwlAdmin\Renderers\Drawer;
|
||||
use Slowlyo\OwlAdmin\Renderers\Dialog;
|
||||
use Slowlyo\OwlAdmin\Renderers\DrawerAction;
|
||||
use Slowlyo\OwlAdmin\Renderers\DialogAction;
|
||||
use Slowlyo\OwlAdmin\Renderers\LinkAction;
|
||||
|
||||
trait CustomActionTrait
|
||||
{
|
||||
/**
|
||||
* 新增按钮
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $size
|
||||
* @param string $width
|
||||
*
|
||||
* @return DialogAction|DrawerAction|LinkAction
|
||||
*/
|
||||
protected function createTypeButton(string $type = '', string $size = '', string $width = ''): DialogAction|DrawerAction|LinkAction
|
||||
{
|
||||
switch ($type) {
|
||||
case 'drawer':
|
||||
$form = $this->form(false)->api($this->getStorePath())->onEvent([]);
|
||||
|
||||
$drawer = Drawer::make()->title(__('admin.create'))->body($form)->closeOnOutside();
|
||||
if($width){
|
||||
$drawer->width($width);
|
||||
}else{
|
||||
$drawer->size($size);
|
||||
}
|
||||
$button = DrawerAction::make()->drawer($drawer);
|
||||
break;
|
||||
case 'dialog':
|
||||
$form = $this->form(false)->api($this->getStorePath())->onEvent([]);
|
||||
|
||||
$button = DialogAction::make()->dialog(
|
||||
Dialog::make()->title(__('admin.create'))->body($form)->size($size)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$button = LinkAction::make()->link($this->getCreatePath());
|
||||
break;
|
||||
}
|
||||
|
||||
return $button->label(__('admin.create'))->icon('fa fa-add')->level('primary');
|
||||
}
|
||||
|
||||
/**
|
||||
* 行编辑按钮
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $size
|
||||
* @param string $width
|
||||
*
|
||||
* @return DialogAction|DrawerAction|LinkAction
|
||||
*/
|
||||
protected function rowEditTypeButton(string $type = '', string $size = '', string $width = ''): DialogAction|DrawerAction|LinkAction
|
||||
{
|
||||
switch ($type) {
|
||||
case 'drawer':
|
||||
$form = $this->form(true)
|
||||
->api($this->getUpdatePath())
|
||||
->initApi($this->getEditGetDataPath())
|
||||
->redirect('')
|
||||
->onEvent([]);
|
||||
|
||||
$drawer = Drawer::make()->title(__('admin.edit'))->body($form)->closeOnOutside();
|
||||
|
||||
if($width){
|
||||
$drawer->width($width);
|
||||
}else{
|
||||
$drawer->size($size);
|
||||
}
|
||||
|
||||
$button = DrawerAction::make()->drawer($drawer);
|
||||
break;
|
||||
case 'dialog':
|
||||
$form = $this->form(true)
|
||||
->api($this->getUpdatePath())
|
||||
->initApi($this->getEditGetDataPath())
|
||||
->redirect('')
|
||||
->onEvent([]);
|
||||
|
||||
$button = DialogAction::make()->dialog(
|
||||
Dialog::make()->title(__('admin.edit'))->body($form)->size($size)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$button = LinkAction::make()->link($this->getEditPath());
|
||||
break;
|
||||
}
|
||||
|
||||
return $button->label(__('admin.edit'))->icon('fa-regular fa-pen-to-square')->level('link');
|
||||
}
|
||||
|
||||
/**
|
||||
* 行详情按钮
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $size
|
||||
* @param string $width
|
||||
*
|
||||
* @return DialogAction|DrawerAction|LinkAction
|
||||
*/
|
||||
protected function rowShowTypeButton(string $type = '', string $size = '', string $width = ''): DialogAction|DrawerAction|LinkAction
|
||||
{
|
||||
switch ($type) {
|
||||
case 'drawer':
|
||||
$drawer = Drawer::make()->title(__('admin.show'))->name('detail_info')->body($this->detail('$id'))->closeOnOutside();
|
||||
|
||||
if($width){
|
||||
$drawer->width($width);
|
||||
}else{
|
||||
$drawer->size($size);
|
||||
}
|
||||
//补充详情操作按钮扩展
|
||||
try{
|
||||
$actions = $this->detailActions();
|
||||
}catch(\BadMethodCallException $e){
|
||||
$actions = [];
|
||||
}
|
||||
$drawer->actions($actions);
|
||||
|
||||
$button = DrawerAction::make()->drawer($drawer);
|
||||
break;
|
||||
case 'dialog':
|
||||
//补充详情操作按钮扩展
|
||||
$dialog = Dialog::make()->title(__('admin.show'))->name('detail_info')->body($this->detail('$id'))->size($size);
|
||||
try{
|
||||
$actions = $this->detailActions();
|
||||
}catch(\BadMethodCallException $e){
|
||||
$actions = [];
|
||||
}
|
||||
$dialog->actions($actions);
|
||||
$button = DialogAction::make()->dialog($dialog);
|
||||
break;
|
||||
default:
|
||||
$button = LinkAction::make()->link($this->getShowPath());
|
||||
break;
|
||||
}
|
||||
|
||||
return $button->label(__('admin.show'))->icon('fa-regular fa-eye')->level('link');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue