tools([ new SyncFarmLandJsonTool() ]); $helper->columnId(); $grid->column('from_type_id', '起始土地类型')->display(function ($fromTypeId) { return $this->fromType ? $this->fromType->name : "未知类型 (ID: {$fromTypeId})"; })->sortable(); $grid->column('to_type_id', '目标土地类型')->display(function ($toTypeId) { return $this->toType ? $this->toType->name : "未知类型 (ID: {$toTypeId})"; })->sortable(); // 添加消耗组详情列 $helper->columnConsumeGroupDetails(); // 添加条件组详情列 $helper->columnConditionGroupDetails(); $helper->columnCreatedAt(); $helper->columnUpdatedAt(); $grid->filter(function (Grid\Filter $filter) { $filterHelper = new FilterHelper($filter, $this); $filterHelper->equalId(); $filter->equal('from_type_id', '起始土地类型ID'); $filter->equal('to_type_id', '目标土地类型ID'); $filterHelper->betweenDatetime('created_at', '创建时间'); }); }); } /** * 构建详情页 * * @param mixed $id * @return Show */ protected function detail($id) { return Show::make($id, new FarmLandUpgradeConfigRepository(), function (Show $show) { $helper = new ShowHelper($show, $this); $show->field('id', 'ID'); $show->field('from_type_id', '起始土地类型')->as(function ($fromTypeId) { return $this->fromType ? "{$this->fromType->name} (ID: {$fromTypeId})" : "未知类型 (ID: {$fromTypeId})"; }); $show->field('to_type_id', '目标土地类型')->as(function ($toTypeId) { return $this->toType ? "{$this->toType->name} (ID: {$toTypeId})" : "未知类型 (ID: {$toTypeId})"; }); $show->field('materials', '消耗组')->as(function ($materialsGroupId) { if (!$materialsGroupId) { return '使用 materials 字段'; } $consumeGroup = GameConsumeGroup::find($materialsGroupId); return $consumeGroup ? "{$consumeGroup->name} ({$consumeGroup->code})" : "未知 ({$materialsGroupId})"; }); $show->field('conditions', '条件组')->as(function ($conditionsGroupId) { if (!$conditionsGroupId) { return '使用 conditions 字段'; } $conditionGroup = GameConditionGroup::find($conditionsGroupId); return $conditionGroup ? "{$conditionGroup->name} ({$conditionGroup->code})" : "未知 ({$conditionsGroupId})"; }); $show->field('created_at', '创建时间'); $show->field('updated_at', '更新时间'); }); } /** * 构建表单 * * @return Form */ protected function form() { return Form::make(new FarmLandUpgradeConfigRepository(), function (Form $form) { $helper = new FormHelper($form, $this); $form->display('id', 'ID'); $helper->selectModelOption('from_type_id', '起始土地类型', FarmLandType::class, 'name', 'id'); $helper->selectModelOption('to_type_id', '目标土地类型', FarmLandType::class, 'name', 'id'); // 添加消耗组选择(使用表格选择器) $consumeGroupTable = GameConsumeGroupLazyRenderable::make(); $form->selectTable('materials', '消耗组') ->from($consumeGroupTable) ->title('选择消耗组') ->model($consumeGroupTable->getModel(), $consumeGroupTable->getModelSelectId(), $consumeGroupTable->getModelViewName()) ->help('选择消耗组后,将使用消耗组中的消耗项作为升级所需材料,而不使用 materials 字段'); // 添加条件组选择(使用表格选择器) $conditionGroupTable = GameConditionGroupLazyRenderable::make(); $form->selectTable('conditions', '条件组') ->from($conditionGroupTable) ->title('选择条件组') ->model($conditionGroupTable->getModel(), $conditionGroupTable->getModelSelectId(), $conditionGroupTable->getModelViewName()) ->help('选择条件组后,将使用条件组中的条件项作为升级条件,而不使用 conditions 字段'); $form->divider('以下字段仅在未选择消耗组时使用'); $form->display('created_at', '创建时间'); $form->display('updated_at', '更新时间'); // 验证起始和目标土地类型不能相同 $form->saving(function (Form $form) { if ($form->from_type_id == $form->to_type_id) { return $form->error('起始土地类型和目标土地类型不能相同'); } }); }); } }