Parcourir la source

refactor(farm): 重构神像配置功能

- 移除了生成 JSON 数据的冗余代码- 更新了显示属性和数值属性的表单字段类型
-简化了 FarmShrineConfigRepository 的结构
- 添加了嵌套表单的注释
notfff il y a 7 mois
Parent
commit
620f56af8a

+ 1 - 0
UCore/DcatAdmin/FormHelper.php

@@ -58,6 +58,7 @@ class FormHelper
 
     /**
      * 嵌套表单
+     * json,cats model
      *
      * @param $field
      * @param $lable

+ 2 - 31
app/Module/Farm/AdminControllers/FarmShrineConfigController.php

@@ -22,36 +22,7 @@ use UCore\DcatAdmin\AdminController;
 #[Resource('farm-shrine-configs', names: 'dcat.admin.farm-shrine-configs')]
 class FarmShrineConfigController extends AdminController
 {
-    /**
-     * 生成神像配置JSON数据
-     */
-    #[Get('farm-shrine-configs/generate-json')]
-    public function generateJson()
-    {
-        try {
-            // 直接调用命令生成JSON
-            $process = new \Symfony\Component\Process\Process(['php', 'artisan', 'farm:generate-shrine-json']);
-            $process->setWorkingDirectory(base_path());
-            $process->run();
-
-            if (!$process->isSuccessful()) {
-                return response()->json([
-                    'status'  => 'error',
-                    'message' => 'JSON生成失败: ' . $process->getErrorOutput()
-                ]);
-            }
 
-            return response()->json([
-                'status'  => 'success',
-                'message' => 'JSON生成成功'
-            ]);
-        } catch (\Exception $e) {
-            return response()->json([
-                'status'  => 'error',
-                'message' => 'JSON生成失败: ' . $e->getMessage()
-            ]);
-        }
-    }
 
     /**
      * 构建表格
@@ -141,8 +112,8 @@ class FarmShrineConfigController extends AdminController
             $form->number('item_id', '对应物品ID')
                 ->min(1)
                 ->required();
-            $helper->formKeyValueJson('display_attributes', '显示属性');
-            $helper->formKeyValueJson('numeric_attributes', '数值属性');
+            $helper->embedsCats('display_attributes', '显示属性');
+            $helper->embedsCats('numeric_attributes', '数值属性');
 
             $form->display('created_at', '创建时间');
             $form->display('updated_at', '更新时间');

+ 1 - 9
app/Module/Farm/Repositories/FarmShrineConfigRepository.php

@@ -10,13 +10,5 @@ use Dcat\Admin\Repositories\EloquentRepository;
  */
 class FarmShrineConfigRepository extends EloquentRepository
 {
-    /**
-     * 模型类名
-     *
-     * @return string
-     */
-    public function model()
-    {
-        return FarmShrineConfig::class;
-    }
+    protected $eloquentClass = FarmShrineConfig::class;
 }