新增CRUD强制类型转换

pull/515/head
Karson 2025-06-17 14:09:46 +08:00
parent c6a3251840
commit cef5b1920d
5 changed files with 18 additions and 4 deletions

View File

@ -711,6 +711,7 @@ class Crud extends Command
$getAttrArr = [];
$getEnumArr = [];
$appendAttrList = [];
$typeDefineList = [];
$controllerAssignList = [];
$headingHtml = '{:build_heading()}';
$controllerImport = '';
@ -743,10 +744,17 @@ class Crud extends Command
if ($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)) {
$inputType = $this->getFieldType($v);
// 如果是number类型时增加一个步长
$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,
'visibleFieldList' => $fields ? "\$row->visible(['" . implode("','", array_filter(in_array($priKey, explode(',', $fields)) ? explode(',', $fields) : explode(',', $priKey . ',' . $fields))) . "']);" : '',
'appendAttrList' => implode(",\n", $appendAttrList),
'typeDefineList' => implode(",\n", $typeDefineList),
'getEnumList' => implode("\n\n", $getEnumArr),
'getAttrList' => implode("\n\n", $getAttrArr),
'setAttrList' => implode("\n\n", $setAttrArr),
@ -1273,6 +1282,7 @@ EOD;
return;
}
$attrField = ucfirst($this->getCamelizeName($field));
$return = '';
if ($inputType == 'datetime') {
$return = <<<EOD
return \$value === '' ? null : (\$value && !is_numeric(\$value) ? strtotime(\$value) : \$value);

View File

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

View File

@ -333,7 +333,6 @@ class Install extends Command
foreach ($checkDirs as $k => $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'));
break;
}
}
return true;

View File

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

View File

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