Compare commits

..

4 Commits

Author SHA1 Message Date
Karson aee632be9d CRUD复选框模板强制类型转换 2025-06-17 15:55:01 +08:00
Karson 037570a866 优化PHP8.4兼容 2025-06-17 15:54:11 +08:00
Karson d959d24716 优化表单提交元素选择 2025-06-17 14:12:13 +08:00
Karson cef5b1920d 新增CRUD强制类型转换 2025-06-17 14:09:46 +08:00
8 changed files with 21 additions and 7 deletions

View File

@ -711,6 +711,7 @@ class Crud extends Command
$getAttrArr = []; $getAttrArr = [];
$getEnumArr = []; $getEnumArr = [];
$appendAttrList = []; $appendAttrList = [];
$typeDefineList = [];
$controllerAssignList = []; $controllerAssignList = [];
$headingHtml = '{:build_heading()}'; $headingHtml = '{:build_heading()}';
$controllerImport = ''; $controllerImport = '';
@ -743,10 +744,17 @@ class Crud extends Command
if ($v['COLUMN_COMMENT'] != '') { if ($v['COLUMN_COMMENT'] != '') {
$langList[] = $this->getLangItem($field, $v['COLUMN_COMMENT']); $langList[] = $this->getLangItem($field, $v['COLUMN_COMMENT']);
} }
$inputType = '';
$inputType = $this->getFieldType($v);
// 强制类型转换
if ($inputType === 'number' && $v['DATA_TYPE'] == 'bigint') {
$typeDefineList[] = <<<EOD
'{$field}' => 'string'
EOD;
}
//保留字段不能修改和添加 //保留字段不能修改和添加
if ($v['COLUMN_KEY'] != 'PRI' && !in_array($field, $this->reservedField) && !in_array($field, $this->ignoreFields)) { if ($v['COLUMN_KEY'] != 'PRI' && !in_array($field, $this->reservedField) && !in_array($field, $this->ignoreFields)) {
$inputType = $this->getFieldType($v);
// 如果是number类型时增加一个步长 // 如果是number类型时增加一个步长
$step = $inputType == 'number' && $v['NUMERIC_SCALE'] > 0 ? "0." . str_repeat(0, $v['NUMERIC_SCALE'] - 1) . "1" : 0; $step = $inputType == 'number' && $v['NUMERIC_SCALE'] > 0 ? "0." . str_repeat(0, $v['NUMERIC_SCALE'] - 1) . "1" : 0;
@ -1135,6 +1143,7 @@ class Crud extends Command
'recyclebinHtml' => $recyclebinHtml, 'recyclebinHtml' => $recyclebinHtml,
'visibleFieldList' => $fields ? "\$row->visible(['" . implode("','", array_filter(in_array($priKey, explode(',', $fields)) ? explode(',', $fields) : explode(',', $priKey . ',' . $fields))) . "']);" : '', 'visibleFieldList' => $fields ? "\$row->visible(['" . implode("','", array_filter(in_array($priKey, explode(',', $fields)) ? explode(',', $fields) : explode(',', $priKey . ',' . $fields))) . "']);" : '',
'appendAttrList' => implode(",\n", $appendAttrList), 'appendAttrList' => implode(",\n", $appendAttrList),
'typeDefineList' => implode(",\n", $typeDefineList),
'getEnumList' => implode("\n\n", $getEnumArr), 'getEnumList' => implode("\n\n", $getEnumArr),
'getAttrList' => implode("\n\n", $getAttrArr), 'getAttrList' => implode("\n\n", $getAttrArr),
'setAttrList' => implode("\n\n", $setAttrArr), 'setAttrList' => implode("\n\n", $setAttrArr),
@ -1273,6 +1282,7 @@ EOD;
return; return;
} }
$attrField = ucfirst($this->getCamelizeName($field)); $attrField = ucfirst($this->getCamelizeName($field));
$return = '';
if ($inputType == 'datetime') { if ($inputType == 'datetime') {
$return = <<<EOD $return = <<<EOD
return \$value === '' ? null : (\$value && !is_numeric(\$value) ? strtotime(\$value) : \$value); return \$value === '' ? null : (\$value && !is_numeric(\$value) ? strtotime(\$value) : \$value);

View File

@ -2,7 +2,7 @@
public function {%methodName%}($value, $data) public function {%methodName%}($value, $data)
{ {
$value = $value ?: ($data['{%field%}'] ?? ''); $value = $value ?: ($data['{%field%}'] ?? '');
$valueArr = explode(',', $value); $valueArr = explode(',', (string) $value);
$list = $this->{%listMethodName%}(); $list = $this->{%listMethodName%}();
return implode(',', array_intersect_key($list, array_flip($valueArr))); return implode(',', array_intersect_key($list, array_flip($valueArr)));
} }

View File

@ -27,6 +27,11 @@ class {%modelName%} extends Model
protected $append = [ protected $append = [
{%appendAttrList%} {%appendAttrList%}
]; ];
// 类型转换
protected $type = [
{%typeDefineList%}
];
{%modelInit%} {%modelInit%}

View File

@ -333,7 +333,6 @@ class Install extends Command
foreach ($checkDirs as $k => $v) { foreach ($checkDirs as $k => $v) {
if (!is_dir(ROOT_PATH . $v)) { if (!is_dir(ROOT_PATH . $v)) {
throw new Exception(__('Please go to the official website to download the full package or resource package and try to install')); throw new Exception(__('Please go to the official website to download the full package or resource package and try to install'));
break;
} }
} }
return true; return true;

View File

@ -256,6 +256,7 @@ class Menu extends Command
\think\Lang::load(dirname(__DIR__) . DS . 'lang/zh-cn.php'); \think\Lang::load(dirname(__DIR__) . DS . 'lang/zh-cn.php');
//先导入菜单的数据 //先导入菜单的数据
$name = '';
$pid = 0; $pid = 0;
foreach ($controllerArr as $k => $v) { foreach ($controllerArr as $k => $v) {
$key = $k + 1; $key = $k + 1;

View File

@ -175,7 +175,6 @@ class Group extends Backend
} }
} }
$this->error(); $this->error();
return;
} }
$this->view->assign("row", $row); $this->view->assign("row", $row);
return $this->view->fetch(); return $this->view->fetch();

View File

@ -69,7 +69,7 @@ class Api
* @access public * @access public
* @param Request $request Request 对象 * @param Request $request Request 对象
*/ */
public function __construct(Request $request = null) public function __construct(?Request $request = null)
{ {
$this->request = is_null($request) ? Request::instance() : $request; $this->request = is_null($request) ? Request::instance() : $request;

View File

@ -682,7 +682,7 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
Fast.api.ajax({ Fast.api.ajax({
type: type, type: type,
url: url, url: url,
data: form.find('input, select, textarea, keygen') // 找到所有可序列化的元素 data: form.find(':input') // 找到所有可序列化的元素
.not('.fieldlist[data-ignoreorigin="true"] [fieldlist-item] *') // 排除掉 fieldlist 中的元素 .not('.fieldlist[data-ignoreorigin="true"] [fieldlist-item] *') // 排除掉 fieldlist 中的元素
.serialize() + (Object.keys(params).length > 0 ? '&' + $.param(params) : ''), .serialize() + (Object.keys(params).length > 0 ? '&' + $.param(params) : ''),
dataType: 'json', dataType: 'json',