@@ -17,6 +17,7 @@ import { upperFirst, cloneDeep } from 'lodash-es';
1717import { useItemLabelWidth } from './hooks/useLabelWidth' ;
1818import { ComponentType } from './types' ;
1919import { isNumber } from '/@/utils/is' ;
20+ import { useI18n } from '/@/hooks/web/useI18n' ;
2021
2122export default defineComponent ( {
2223 name : 'BasicFormItem' ,
@@ -46,6 +47,8 @@ export default defineComponent({
4647 } ,
4748 } ,
4849 setup ( props , { slots } ) {
50+ const { t } = useI18n ( 'component.form' ) ;
51+ // @ts -ignore
4952 const itemLabelWidthRef = useItemLabelWidth ( toRef ( props , 'schema' ) , toRef ( props , 'formProps' ) ) ;
5053
5154 const getValuesRef = computed ( ( ) => {
@@ -132,7 +135,7 @@ export default defineComponent({
132135 let rules : ValidationRule [ ] = cloneDeep ( defRules ) as ValidationRule [ ] ;
133136
134137 if ( ( ! rules || rules . length === 0 ) && required ) {
135- rules = [ { required } ] ;
138+ rules = [ { required, type : 'string' } ] ;
136139 }
137140
138141 const requiredRuleIndex : number = rules . findIndex (
@@ -142,6 +145,9 @@ export default defineComponent({
142145 if ( requiredRuleIndex !== - 1 ) {
143146 const rule = rules [ requiredRuleIndex ] ;
144147 if ( rule . required && component ) {
148+ if ( ! Reflect . has ( rule , 'type' ) ) {
149+ rule . type = 'string' ;
150+ }
145151 const joinLabel = Reflect . has ( props . schema , 'rulesMessageJoinLabel' )
146152 ? rulesMessageJoinLabel
147153 : globalRulesMessageJoinLabel ;
@@ -157,11 +163,9 @@ export default defineComponent({
157163 component . includes ( 'TimePicker' )
158164 ) {
159165 rule . type = 'object' ;
160- }
161- if ( component . includes ( 'RangePicker' ) || component . includes ( 'Upload' ) ) {
166+ } else if ( component . includes ( 'RangePicker' ) || component . includes ( 'Upload' ) ) {
162167 rule . type = 'array' ;
163- }
164- if ( component . includes ( 'InputNumber' ) ) {
168+ } else if ( component . includes ( 'InputNumber' ) ) {
165169 rule . type = 'number' ;
166170 }
167171 }
@@ -171,7 +175,7 @@ export default defineComponent({
171175 const characterInx = rules . findIndex ( ( val ) => val . max ) ;
172176 if ( characterInx !== - 1 && ! rules [ characterInx ] . validator ) {
173177 rules [ characterInx ] . message =
174- rules [ characterInx ] . message || `字符数应小于 ${ rules [ characterInx ] . max } 位` ;
178+ rules [ characterInx ] . message || t ( 'maxTip' , [ rules [ characterInx ] . max ] ) ;
175179 }
176180 return rules ;
177181 }
@@ -237,6 +241,7 @@ export default defineComponent({
237241 const bindValue = {
238242 [ valueField || ( isCheck ? 'checked' : 'value' ) ] : handleValue ( component , field ) ,
239243 } ;
244+
240245 if ( ! renderComponentContent ) {
241246 return < Comp { ...propsData } { ...on } { ...bindValue } /> ;
242247 }
0 commit comments