From 0c85045e7d70b22223ce1acd81dd50f43e0706b4 Mon Sep 17 00:00:00 2001 From: Karson Date: Thu, 15 Jan 2026 10:31:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96CRUD=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Crud.php | 33 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index dc55d91e..2bc69e7b 100755 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -1005,7 +1005,7 @@ EOD; } //过滤text类型字段 - if ($v['DATA_TYPE'] != 'text' && $inputType != 'fieldlist') { + if (!preg_match("/text$/i", $v['DATA_TYPE']) && $inputType != 'fieldlist') { //主键 if ($v['COLUMN_KEY'] == 'PRI' && !$priDefined) { $priDefined = true; @@ -1070,7 +1070,7 @@ EOD; } //过滤text类型字段 - if ($v['DATA_TYPE'] != 'text') { + if (!preg_match("/text$/i", $v['DATA_TYPE'])) { //构造JS列信息 $javascriptList[] = $this->getJsColumn($relationField, $v['DATA_TYPE'], '', [], $v); } @@ -1646,11 +1646,11 @@ EOD; $inputType = "datetimerange"; } // 指定后缀结尾JSON配置 - if ($this->isMatchSuffix($fieldsName, $this->jsonSuffix) && ($v['DATA_TYPE'] == 'varchar' || $v['DATA_TYPE'] == 'text')) { + if ($this->isMatchSuffix($fieldsName, $this->jsonSuffix) && ($v['DATA_TYPE'] == 'varchar' || preg_match("/text$/i", $v['DATA_TYPE']))) { $inputType = "fieldlist"; } // 指定后缀结尾标签配置 - if ($this->isMatchSuffix($fieldsName, $this->tagSuffix) && ($v['DATA_TYPE'] == 'varchar' || $v['DATA_TYPE'] == 'text')) { + if ($this->isMatchSuffix($fieldsName, $this->tagSuffix) && ($v['DATA_TYPE'] == 'varchar' || preg_match("/text$/i", $v['DATA_TYPE']))) { $inputType = "tagsinput"; } return $inputType; @@ -1734,7 +1734,22 @@ EOD; { $lang = mb_ucfirst($field); $formatter = ''; - foreach ($this->fieldFormatterSuffix as $k => $v) { + $fieldFormatterSuffix = $this->fieldFormatterSuffix; + foreach (['switch', 'image', 'file', 'tag', 'intDate'] as $index => $item) { + $property = $item . (in_array($item, ['image', 'file']) ? 'Field' : 'Suffix'); + if (!isset($this->$property) || !$this->isMatchSuffix($field, $this->$property)) { + continue; + } + if ($item == 'intDate') { + $fieldFormatterSuffix[$field] = ['type' => ['int', 'bigint', 'timestamp'], 'name' => 'datetime']; + } else if (in_array($item, ['image', 'file'])) { + $fieldFormatterSuffix[$field] = $this->fieldFormatterSuffix[$item . (preg_match("/s$/i", $field) ? 's' : '')]; + } else { + $fieldFormatterSuffix[$field] = $this->fieldFormatterSuffix[$item]; + } + break; + } + foreach ($fieldFormatterSuffix as $k => $v) { if (preg_match("/{$k}$/i", $field)) { if (is_array($v)) { if (in_array($datatype, $v['type'])) { @@ -1765,7 +1780,13 @@ EOD; } // 文件、图片、权重等字段默认不加入搜索栏,字符串类型默认LIKE - $noSearchFiles = ['file$', 'files$', 'image$', 'images$', '^weigh$']; + $noSearchFiles = ['file$', 'files$', 'image$', 'images$', '^' . $this->sortField . '$']; + $noSearchFiles = array_merge($noSearchFiles, array_map(function ($item) { + return $item . '$'; + }, $this->imageField), array_map(function ($item) { + return $item . '$'; + }, $this->fileField)); + if (preg_match("/" . implode('|', $noSearchFiles) . "/i", $field)) { $html .= ", operate: false"; } elseif (in_array($datatype, ['varchar'])) {