djc-new/app/Traits/CustomActionTrait.php

87 lines
2.8 KiB
PHP

<?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
*
* @return DialogAction|DrawerAction|LinkAction
*/
protected function createTypeButton(string $type = '', string $size = ''): DialogAction|DrawerAction|LinkAction
{
switch ($type) {
case 'drawer':
$form = $this->form(false)->api($this->getStorePath())->onEvent([]);
$button = DrawerAction::make()->drawer(
Drawer::make()->title(__('admin.create'))->body($form)->size($size)
);
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
*
* @return DialogAction|DrawerAction|LinkAction
*/
protected function rowEditTypeButton(string $type = '', string $size = ''): DialogAction|DrawerAction|LinkAction
{
switch ($type) {
case 'drawer':
$form = $this->form(true)
->api($this->getUpdatePath())
->initApi($this->getEditGetDataPath())
->redirect('')
->onEvent([]);
$button = DrawerAction::make()->drawer(
Drawer::make()->title(__('admin.edit'))->body($form)->size($size)
);
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');
}
}