@@ -8,9 +8,11 @@ import {
88
99import { validateFormDataAndTransformMsg } from '@lljj/vjsf-utils/schema/validate' ;
1010import { IconQuestion } from '@lljj/vjsf-utils/icons' ;
11+ import { fallbackLabel } from '@lljj/vjsf-utils/formUtils' ;
1112
1213export default {
1314 name : 'Widget' ,
15+ inject : [ 'genFormProvide' ] ,
1416 props : {
1517 // 是否同步formData的值,默认表单元素都需要
1618 // oneOf anyOf 中的select属于formData之外的数据
@@ -165,8 +167,10 @@ export default {
165167 render ( h ) {
166168 const self = this ;
167169
170+ const { curNodePath } = this . $props ;
171+
168172 // 判断是否为根节点
169- const isRootNode = isRootNodePath ( this . curNodePath ) ;
173+ const isRootNode = isRootNodePath ( curNodePath ) ;
170174
171175 const miniDesModel = self . globalOptions . HELPERS . isMiniDes ( self . formProps ) ;
172176
@@ -212,6 +216,9 @@ export default {
212216 } : { } )
213217 } ;
214218
219+ // 运行配置回退到 属性名
220+ const label = fallbackLabel ( self . label , ( self . widget && this . genFormProvide . fallbackLabel ) , curNodePath ) ;
221+
215222 return h (
216223 COMPONENT_MAP . formItem ,
217224 {
@@ -225,7 +232,7 @@ export default {
225232 ...self . labelWidth ? { labelWidth : self . labelWidth } : { } ,
226233 ...this . isFormData ? {
227234 // 这里对根节点打特殊标志,绕过elementUi无prop属性不校验
228- prop : isRootNode ? '__$$root' : path2prop ( self . curNodePath ) ,
235+ prop : isRootNode ? '__$$root' : path2prop ( curNodePath ) ,
229236 rules : [
230237 {
231238 validator ( rule , value , callback ) {
@@ -239,15 +246,15 @@ export default {
239246 customFormats : self . $props . customFormats ,
240247 errorSchema : self . errorSchema ,
241248 required : self . required ,
242- propPath : path2prop ( self . curNodePath )
249+ propPath : path2prop ( curNodePath )
243250 } ) ;
244251 if ( errors . length > 0 ) return callback ( errors [ 0 ] . message ) ;
245252
246253 // customRule 如果存在自定义校验
247254 const curCustomRule = self . $props . customRule ;
248255 if ( curCustomRule && ( typeof curCustomRule === 'function' ) ) {
249256 return curCustomRule ( {
250- field : self . curNodePath ,
257+ field : curNodePath ,
251258 value,
252259 rootFormData : self . rootFormData ,
253260 callback
@@ -274,14 +281,14 @@ export default {
274281 } ,
275282 } ,
276283 [
277- self . label ? h ( 'span' , {
284+ label ? h ( 'span' , {
278285 slot : 'label' ,
279286 class : {
280287 genFormLabel : true ,
281288 genFormItemRequired : self . required ,
282289 } ,
283290 } , [
284- `${ self . label } ` ,
291+ `${ label } ` ,
285292 miniDescriptionVNode ,
286293 `${ ( self . formProps && self . formProps . labelSuffix ) || '' } `
287294 ] ) : null ,
0 commit comments