ItemQuantityAction.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers\Actions;
  3. use App\Module\GameItems\AdminControllers\Actions\ItemQuantityForm;
  4. use Dcat\Admin\Widgets\Modal;
  5. use UCore\DcatAdmin\RowAction;
  6. /**
  7. * 物品数量操作行动作
  8. *
  9. * 提供快捷的物品数量增加/减少操作
  10. */
  11. class ItemQuantityAction extends RowAction
  12. {
  13. /**
  14. * 操作按钮标题
  15. *
  16. * @var string
  17. */
  18. protected $title = '数量操作';
  19. /**
  20. * 检查是否允许显示此操作
  21. *
  22. * @return bool
  23. */
  24. public function allowed()
  25. {
  26. // 只对普通物品(非单独属性物品)显示
  27. $row = $this->getRow();
  28. return empty($row->instance_id);
  29. }
  30. /**
  31. * 渲染操作按钮
  32. *
  33. * @return string
  34. */
  35. public function render2()
  36. {
  37. $row = $this->getRow();
  38. // 实例化表单类并传递自定义参数
  39. $form = ItemQuantityForm::make();
  40. $form->payload([
  41. 'id' => $this->getKey(),
  42. 'user_id' => $row->user_id,
  43. 'item_id' => $row->item_id,
  44. 'current_quantity' => $row->quantity,
  45. 'item_name' => $row->item->name ?? '未知物品'
  46. ]);
  47. return Modal::make()
  48. ->lg()
  49. ->title($this->title())
  50. ->body($form)
  51. ->button('<i class="feather icon-edit-3"></i> ' . $this->title());
  52. }
  53. }