diff --git a/app/Traits/CustomActionTrait.php b/app/Traits/CustomActionTrait.php new file mode 100644 index 0000000..4407920 --- /dev/null +++ b/app/Traits/CustomActionTrait.php @@ -0,0 +1,148 @@ +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'); + } +} \ No newline at end of file