diff --git a/app/admin/controller/crud/Crud.php b/app/admin/controller/crud/Crud.php index 55db1582..044c52b0 100644 --- a/app/admin/controller/crud/Crud.php +++ b/app/admin/controller/crud/Crud.php @@ -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 + ]); } } diff --git a/app/admin/library/crud/Helper.php b/app/admin/library/crud/Helper.php index 338fc9af..27bd1c33 100644 --- a/app/admin/library/crud/Helper.php +++ b/app/admin/library/crud/Helper.php @@ -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 = [ diff --git a/app/admin/library/crud/stubs/mixins/model/getters/float.stub b/app/admin/library/crud/stubs/mixins/model/getters/float.stub new file mode 100644 index 00000000..1ac2d68a --- /dev/null +++ b/app/admin/library/crud/stubs/mixins/model/getters/float.stub @@ -0,0 +1,5 @@ + + public function get{%field%}Attr($value): float + { + return (float)$value; + } \ No newline at end of file diff --git a/app/admin/library/crud/stubs/mixins/model/getters/htmlDecode.stub b/app/admin/library/crud/stubs/mixins/model/getters/htmlDecode.stub index 121eb832..47ea9469 100644 --- a/app/admin/library/crud/stubs/mixins/model/getters/htmlDecode.stub +++ b/app/admin/library/crud/stubs/mixins/model/getters/htmlDecode.stub @@ -1,5 +1,5 @@ - public function get{%field%}Attr($value) + public function get{%field%}Attr($value): string { return !$value ? '' : htmlspecialchars_decode($value); } \ No newline at end of file diff --git a/app/admin/library/crud/stubs/mixins/model/getters/jsonDecode.stub b/app/admin/library/crud/stubs/mixins/model/getters/jsonDecode.stub index 94ddca39..6ae96a71 100644 --- a/app/admin/library/crud/stubs/mixins/model/getters/jsonDecode.stub +++ b/app/admin/library/crud/stubs/mixins/model/getters/jsonDecode.stub @@ -1,5 +1,5 @@ - public function get{%field%}Attr($value) + public function get{%field%}Attr($value): array { return !$value ? [] : json_decode($value, true); } \ No newline at end of file diff --git a/app/admin/library/crud/stubs/mixins/model/getters/stringToArray.stub b/app/admin/library/crud/stubs/mixins/model/getters/stringToArray.stub index 75e3d8a0..67937091 100644 --- a/app/admin/library/crud/stubs/mixins/model/getters/stringToArray.stub +++ b/app/admin/library/crud/stubs/mixins/model/getters/stringToArray.stub @@ -1,5 +1,5 @@ - public function get{%field%}Attr($value) + public function get{%field%}Attr($value): array { if (!$value) return []; if (!is_array($value)) { diff --git a/app/admin/library/crud/stubs/mixins/model/setters/arrayToString.stub b/app/admin/library/crud/stubs/mixins/model/setters/arrayToString.stub index ff15cce0..a54fc9d6 100644 --- a/app/admin/library/crud/stubs/mixins/model/setters/arrayToString.stub +++ b/app/admin/library/crud/stubs/mixins/model/setters/arrayToString.stub @@ -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) : ''; } \ No newline at end of file diff --git a/app/admin/library/crud/stubs/mixins/model/setters/time.stub b/app/admin/library/crud/stubs/mixins/model/setters/time.stub index f7812029..27a749f3 100644 --- a/app/admin/library/crud/stubs/mixins/model/setters/time.stub +++ b/app/admin/library/crud/stubs/mixins/model/setters/time.stub @@ -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)) : ''; } \ No newline at end of file