GroupItemController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers;
  3. use App\Module\GameItems\Models\ItemGroup;
  4. use App\Module\GameItems\Models\ItemGroupItem;
  5. use App\Module\GameItems\Models\ItemItem;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Show;
  9. use UCore\DcatAdmin\AdminController;
  10. use Spatie\RouteAttributes\Attributes\Resource;
  11. #[Resource('game-items-group-items', names: 'dcat.admin.game-items-group-items')]
  12. class GroupItemController extends AdminController
  13. {
  14. /**
  15. * 标题
  16. *
  17. * @var string
  18. */
  19. protected $title = '物品组内容管理';
  20. /**
  21. * 列表页
  22. *
  23. * @return Grid
  24. */
  25. protected function grid()
  26. {
  27. return Grid::make(new ItemGroupItem(), function (Grid $grid) {
  28. $grid->column('id', 'ID')->sortable();
  29. $grid->column('group.name', '物品组');
  30. $grid->column('item.name', '物品');
  31. $grid->column('weight', '权重');
  32. $grid->column('created_at', '创建时间');
  33. $grid->column('updated_at', '更新时间');
  34. // 筛选
  35. $grid->filter(function ($filter) {
  36. $filter->equal('id', 'ID');
  37. $filter->equal('group_id', '物品组')->select(
  38. ItemGroup::pluck('name', 'id')
  39. );
  40. $filter->equal('item_id', '物品')->select(
  41. ItemItem::pluck('name', 'id')
  42. );
  43. });
  44. });
  45. }
  46. /**
  47. * 详情页
  48. *
  49. * @param mixed $id
  50. * @return Show
  51. */
  52. protected function detail($id)
  53. {
  54. return Show::make(ItemGroupItem::findOrFail($id), function (Show $show) {
  55. $show->field('id', 'ID');
  56. $show->field('group.name', '物品组');
  57. $show->field('item.name', '物品');
  58. $show->field('weight', '权重');
  59. $show->field('created_at', '创建时间');
  60. $show->field('updated_at', '更新时间');
  61. });
  62. }
  63. /**
  64. * 表单
  65. *
  66. * @return Form
  67. */
  68. protected function form()
  69. {
  70. return Form::make(new ItemGroupItem(), function (Form $form) {
  71. $form->select('group_id', '物品组')
  72. ->options(ItemGroup::pluck('name', 'id'))
  73. ->required();
  74. $form->select('item_id', '物品')
  75. ->options(ItemItem::pluck('name', 'id'))
  76. ->required();
  77. $form->number('weight', '权重')
  78. ->default(1.0)
  79. ->min(0.001)
  80. ->step(0.001)
  81. ->required()
  82. ->help('权重越高,随机选择时概率越大');
  83. });
  84. }
  85. }