From 6dcd0c8d1f513e24e74d337fab70c691b901ed0f Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Fri, 7 Jun 2024 11:35:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=A1=B5=E9=9D=A2=E6=97=B6=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=A1=A8=E5=AD=97=E6=AE=B5=E6=B3=A8=E9=87=8A=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/service/curd/BuildCurd.php | 36 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/app/admin/service/curd/BuildCurd.php b/app/admin/service/curd/BuildCurd.php index 2e17240..3925586 100644 --- a/app/admin/service/curd/BuildCurd.php +++ b/app/admin/service/curd/BuildCurd.php @@ -177,7 +177,7 @@ class BuildCurd * 时间字段后缀 * @var array */ - protected array $dateFieldSuffix = ['time', 'date']; + protected array $dateFieldSuffix = ['date', 'time']; /** * 开关组件字段 @@ -328,7 +328,7 @@ class BuildCurd try { $columns = Db::query("SHOW FULL COLUMNS FROM {$this->tablePrefix}{$relationTable}"); $formatColumns = []; - $delete = false; + $delete = false; if (!empty($bindSelectField) && !in_array($bindSelectField, array_column($columns, 'Field'))) { throw new TableException("关联表{$relationTable}不存在该字段: {$bindSelectField}"); } @@ -642,8 +642,9 @@ class BuildCurd if (!empty($formTypeMatch) && isset($formTypeMatch[0])) { $colum['comment'] = str_replace($formTypeMatch[0], '', $colum['comment']); $formType = trim(str_replace('}', '', str_replace('{', '', $formTypeMatch[0]))); - if (in_array($formType, $this->formTypeArray)) { - $colum['formType'] = $formType; + $_formType = $this->checkCommentFormType($formType); + if ($_formType) { + $colum['formType'] = $_formType; } } @@ -744,8 +745,8 @@ class BuildCurd */ protected function buildOptionView($field, string $select = '') { - $field = CommonTool::lineToHump(ucfirst($field)); - $name = "get{$field}List"; + $field = CommonTool::lineToHump(ucfirst($field)); + $name = "get{$field}List"; return CommonTool::replaceTemplate( $this->getTemplate("view{$this->DS}module{$this->DS}option"), [ @@ -1021,7 +1022,7 @@ class BuildCurd protected function renderModel(): static { // 主表模型 - $modelFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}model{$this->DS}{$this->modelFilename}.php"; + $modelFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}model{$this->DS}{$this->modelFilename}.php"; $relationList = ''; if (!empty($this->relationArray)) { foreach ($this->relationArray as $key => $val) { @@ -1428,7 +1429,7 @@ class BuildCurd protected function checkContain($string, $array): bool { foreach ($array as $vo) { - if (str_starts_with($string, $vo)) { + if (str_starts_with($vo, $string)) { return true; } } @@ -1455,4 +1456,23 @@ class BuildCurd return file_get_contents("{$this->dir}{$this->DS}templates{$this->DS}{$name}.code"); } + /** + * 检测字段注释归类的类型 + * @param string $formType + * @return string|null + */ + protected function checkCommentFormType(string $formType = ''): ?string + { + $classProperties = get_class_vars(get_class($this)); + foreach ($classProperties as $property => $classProperty) { + if (empty($property)) continue; + if (str_ends_with($property, 'FieldSuffix')) { + if (in_array($formType, $this->$property)) { + return $this->$property[0] ?? ''; + } + } + } + return ''; + } + } \ No newline at end of file