Parcourir la source

feat(GameItems): 添加物品数值属性展示

- 在物品列表中添加数值属性列,显示非零属性值
- 使用属性注释作为键名,提高可读性
- 优化属性展示样式,采用滚动条显示多条目
notfff il y a 7 mois
Parent
commit
2dd8da6bd0
1 fichiers modifiés avec 32 ajouts et 0 suppressions
  1. 32 0
      app/Module/GameItems/AdminControllers/ItemController.php

+ 32 - 0
app/Module/GameItems/AdminControllers/ItemController.php

@@ -84,6 +84,38 @@ class ItemController extends AdminController
                 $html .= '</div>';
                 return $html;
             });
+
+            // 添加数值属性列,只显示有效的属性(非0值),并使用注释作为键名
+            $grid->column('numeric_attributes', '数值属性')->display(function ($value) {
+                if (empty($value)) {
+                    return '-';
+                }
+                if (is_string($value)) {
+                    $value = json_decode($value, true);
+                }
+
+                // 属性名到注释的映射
+                $attributeNames = [
+                    'min_drop_count' => '宝箱最小数量',
+                    'max_drop_count' => '宝箱最大数量',
+                    'crop_growth_time' => '减少作物生长时间',
+                    'pet_power' => '增加宠物体力',
+                    'reward_group_id' => '随机奖励物品组',
+                    'pet_exp' => '增加宠物经验',
+                    'fram_pesticide_rate' => '除虫概率(%)',
+                    'fram_drought_rate' => '解决干旱概率(%)',
+                    'fram_weedicide_rate' => '除草概率(%)'
+                ];
+
+                $html = '<div style="max-width: 250px; max-height: 150px; overflow: auto;">';
+                foreach ((array)$value as $key => $val) {
+                    if (empty($val) || $val === 0) continue; // 过滤掉空值和0值
+                    $name = $attributeNames[$key] ?? $key;
+                    $html .= "<div><strong>{$name}</strong>: {$val}</div>";
+                }
+                $html .= '</div>';
+                return $html;
+            });
             $grid->column('is_unique', '单独属性')->bool();
             $grid->column('max_stack', '最大堆叠');
             $grid->column('tradable', '可交易')->bool();