| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Module\GameItems\AdminControllers\Actions;
- use App\Module\GameItems\AdminControllers\Actions\ItemQuantityForm;
- use Dcat\Admin\Widgets\Modal;
- use UCore\DcatAdmin\RowAction;
- /**
- * 物品数量操作行动作
- *
- * 提供快捷的物品数量增加/减少操作
- */
- class ItemQuantityAction extends RowAction
- {
- /**
- * 操作按钮标题
- *
- * @var string
- */
- protected $title = '数量操作';
- /**
- * 检查是否允许显示此操作
- *
- * @return bool
- */
- public function allowed()
- {
- // 只对普通物品(非单独属性物品)显示
- $row = $this->getRow();
- return empty($row->instance_id);
- }
- /**
- * 渲染操作按钮
- *
- * @return string
- */
- public function render2()
- {
- $row = $this->getRow();
- // 实例化表单类并传递自定义参数
- $form = ItemQuantityForm::make();
- $form->payload([
- 'id' => $this->getKey(),
- 'user_id' => $row->user_id,
- 'item_id' => $row->item_id,
- 'current_quantity' => $row->quantity,
- 'item_name' => $row->item->name ?? '未知物品'
- ]);
- return Modal::make()
- ->lg()
- ->title($this->title())
- ->body($form)
- ->button('<i class="feather icon-edit-3"></i> ' . $this->title());
- }
- }
|