mirror of https://gitee.com/karson/fastadmin.git
新增CRUD强制类型转换
parent
c6a3251840
commit
cef5b1920d
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,11 @@ class {%modelName%} extends Model
|
||||||
protected $append = [
|
protected $append = [
|
||||||
{%appendAttrList%}
|
{%appendAttrList%}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// 类型转换
|
||||||
|
protected $type = [
|
||||||
|
{%typeDefineList%}
|
||||||
|
];
|
||||||
|
|
||||||
{%modelInit%}
|
{%modelInit%}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue