refactor(CRUD):完善模型设置器和获取器的类型定义

This commit is contained in:
妙码生花 2022-11-24 09:39:52 +08:00
parent 7a25845155
commit aa589ff052
8 changed files with 16 additions and 6 deletions

View File

@ -587,6 +587,10 @@ class Crud extends Backend
$modelData['methods'][] = Helper::assembleStub('mixins/model/getters/htmlDecode', [
'field' => $fieldName
]);
} elseif ($field['originalDesignType'] == 'float') {
$modelData['methods'][] = Helper::assembleStub('mixins/model/getters/float', [
'field' => $fieldName
]);
}
}

View File

@ -553,7 +553,8 @@ class Helper
*/
public static function analyseField(&$field)
{
$field['type'] = self::analyseFieldType($field);
$field['type'] = self::analyseFieldType($field);
$field['originalDesignType'] = $field['designType'];
// 表单项类型转换对照表
$designTypeComparison = [

View File

@ -0,0 +1,5 @@
public function get{%field%}Attr($value): float
{
return (float)$value;
}

View File

@ -1,5 +1,5 @@
public function get{%field%}Attr($value)
public function get{%field%}Attr($value): string
{
return !$value ? '' : htmlspecialchars_decode($value);
}

View File

@ -1,5 +1,5 @@
public function get{%field%}Attr($value)
public function get{%field%}Attr($value): array
{
return !$value ? [] : json_decode($value, true);
}

View File

@ -1,5 +1,5 @@
public function get{%field%}Attr($value)
public function get{%field%}Attr($value): array
{
if (!$value) return [];
if (!is_array($value)) {

View File

@ -1,5 +1,5 @@
public function set{%field%}Attr($value)
public function set{%field%}Attr($value): string
{
return $value ? (is_array($value) ? implode(',', $value) : $value) : '';
}

View File

@ -1,5 +1,5 @@
public function set{%field%}Attr($value)
public function set{%field%}Attr($value): string
{
return $value ? date('H:i:s', strtotime($value)) : '';
}