columnId(); $grid->column('chest.name', '宝箱名称'); $grid->column('item.name', '物品名称'); $grid->column('group.name', '物品组名称'); $grid->column('min_quantity', '最小数量'); $grid->column('max_quantity', '最大数量'); $grid->column('weight', '权重'); $grid->column('allow_duplicate', '允许重复')->bool(); $grid->column('pity_count', '保底次数'); $grid->column('pity_weight_factor', '保底权重因子'); $grid->column('created_at', '创建时间'); $grid->column('updated_at', '更新时间'); // 添加行操作 $grid->actions(function (Grid\Displayers\Actions $actions) { // 添加复制按钮 $actions->append(new DuplicateChestContentAction()); }); // 筛选 $grid->filter(function ($filter) { $helper = new FilterHelper($filter, $this); $helper->equal('id', 'ID'); $helper->equalSelectModelChestItem('item_id'); }); }); } /** * 详情页 * * @param mixed $id * @return Show */ protected function detail($id) { return Show::make($id, new ItemChestContentRepository(), function (Show $show) { $helper = new ShowHelper($show, $this); $helper->field('id', 'ID'); $show->field('chest.name', '宝箱名称'); $show->field('item.name', '物品名称'); $show->field('group.name', '物品组名称'); $helper->field('min_quantity', '最小数量'); $helper->field('max_quantity', '最大数量'); $helper->field('weight', '权重'); $show->field('allow_duplicate', '允许重复')->as(function ($allowDuplicate) { return $allowDuplicate ? '是' : '否'; }); $helper->field('pity_count', '保底次数'); $helper->field('pity_weight_factor', '保底权重因子'); $helper->field('created_at', '创建时间'); $helper->field('updated_at', '更新时间'); }); } /** * 表单 * * @return Form */ protected function form() { return Form::make(new ItemChestContentRepository(), function (Form $form) { $helper = new FormHelper($form, $this); $helper->selectModelChestItem('chest_id'); // 物品和物品组二选一 $form->radio('content_type', '内容类型') ->options([ 'item' => '物品', 'group' => '物品组' ]) ->default('item') ->when('item', function (Form $form) { $helper = new FormHelper($form, $this); $helper->selectModelItem('item_id', '物品'); }) ->when('group', function (Form $form) { $helper = new FormHelper($form, $this); $helper->selectModelChestItemGroup('group_id', '物品组'); }); $helper->number('min_quantity','最少数量') ->default(1) ->min(1) ->required(); $helper->number('max_quantity','最多数量') ->default(1) ->min(1) ->required(); $helper->number('weight','权重') ->default(1.0) ->min(0.001) ->required() ->help('权重越高,掉落概率越大,所有内容权重总和为100'); $form->switch('allow_duplicate', '允许重复') ->default(false) ->help('是否允许在一次开箱中重复获得该内容'); $helper->number('pity_count','保底次数') ->default(0) ->min(0) ->help('连续未获得该内容的次数达到此值时,必定获得该内容,0表示不启用保底机制'); $helper->number('pity_weight_factor','保底递增权重') ->default(1.0) ->min(0) ->help('每次未获得该内容时,权重增加的倍数,默认为1.0'); // 保存前回调 $form->saving(function (Form $form) { // 根据内容类型设置对应的字段 if ($form->content_type == 'item') { $form->group_id = null; } else { $form->item_id = null; } $form->deleteInput('content_type'); }); }); } }