From 07e11a1c45eec7fe621cbf7cf118696478dc7764 Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Mon, 3 Mar 2025 17:42:52 +0800 Subject: [PATCH] fix(curd): improve CURD generation logic - Update relation handling in BuildCurd.php: - Modify how foreign key relationships are constructed - Remove unnecessary template generation for non-editable fields - Enhance command processing in CurdGenerate.php: - Filter and re-index command arguments to improve flexibility --- app/admin/controller/system/CurdGenerate.php | 1 + app/admin/service/curd/BuildCurd.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/admin/controller/system/CurdGenerate.php b/app/admin/controller/system/CurdGenerate.php index a237c14..d27d47b 100644 --- a/app/admin/controller/system/CurdGenerate.php +++ b/app/admin/controller/system/CurdGenerate.php @@ -137,6 +137,7 @@ class CurdGenerate extends AdminController $command = $request->post('command', ''); if (empty($command)) $this->error('请输入命令'); $commandExp = explode(' ', $command); + $commandExp = array_values(array_filter($commandExp)); try { $output = Console::call('curd', [...$commandExp]); diff --git a/app/admin/service/curd/BuildCurd.php b/app/admin/service/curd/BuildCurd.php index db248cc..d06bf8d 100644 --- a/app/admin/service/curd/BuildCurd.php +++ b/app/admin/service/curd/BuildCurd.php @@ -1040,7 +1040,7 @@ class BuildCurd $relation = CommonTool::lineToHump($key); $relationCode = "->withJoin('{$relation}', 'LEFT')\r"; if (!empty($val['bindSelectField']) && !empty($val['primaryKey'])) { - $constructRelation = '$notes["' . lcfirst($val['modelFilename']) . ucfirst($val['bindSelectField']) . '"] = \app\admin\model\\' . $val['modelFilename'] . '::column("' . $val['bindSelectField'] . '", "' . $val['primaryKey'] . '");'; + $constructRelation = '$notes["' . lcfirst($val['foreignKey']) . '"] = \app\admin\model\\' . $val['modelFilename'] . '::column("' . $val['bindSelectField'] . '", "' . $val['primaryKey'] . '");'; } } $controllerIndexMethod = CommonTool::replaceTemplate( @@ -1417,7 +1417,7 @@ class BuildCurd } elseif (in_array($field, $this->sortFields)) { $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', edit: 'text'}"; } else { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}"; + $templateValue = ""; } $indexCols .= $this->formatColsRow("{$templateValue},\r");