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 = [];
$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

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

View File

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

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();

View File

@ -69,7 +69,7 @@ class Api
* @access public
* @param Request $request Request 对象
*/
public function __construct(Request $request = null)
public function __construct(?Request $request = null)
{
$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({
type: type,
url: url,
data: form.find('input, select, textarea, keygen') // 找到所有可序列化的元素
data: form.find(':input') // 找到所有可序列化的元素
.not('.fieldlist[data-ignoreorigin="true"] [fieldlist-item] *') // 排除掉 fieldlist 中的元素
.serialize() + (Object.keys(params).length > 0 ? '&' + $.param(params) : ''),
dataType: 'json',