@@ -8,9 +8,11 @@ import {
8
8
9
9
import { validateFormDataAndTransformMsg } from '@lljj/vjsf-utils/schema/validate' ;
10
10
import { IconQuestion } from '@lljj/vjsf-utils/icons' ;
11
+ import { fallbackLabel } from '@lljj/vjsf-utils/formUtils' ;
11
12
12
13
export default {
13
14
name : 'Widget' ,
15
+ inject : [ 'genFormProvide' ] ,
14
16
props : {
15
17
// 是否同步formData的值,默认表单元素都需要
16
18
// oneOf anyOf 中的select属于formData之外的数据
@@ -165,8 +167,10 @@ export default {
165
167
render ( h ) {
166
168
const self = this ;
167
169
170
+ const { curNodePath } = this . $props ;
171
+
168
172
// 判断是否为根节点
169
- const isRootNode = isRootNodePath ( this . curNodePath ) ;
173
+ const isRootNode = isRootNodePath ( curNodePath ) ;
170
174
171
175
const miniDesModel = self . globalOptions . HELPERS . isMiniDes ( self . formProps ) ;
172
176
@@ -212,6 +216,9 @@ export default {
212
216
} : { } )
213
217
} ;
214
218
219
+ // 运行配置回退到 属性名
220
+ const label = fallbackLabel ( self . label , ( self . widget && this . genFormProvide . fallbackLabel ) , curNodePath ) ;
221
+
215
222
return h (
216
223
COMPONENT_MAP . formItem ,
217
224
{
@@ -225,7 +232,7 @@ export default {
225
232
...self . labelWidth ? { labelWidth : self . labelWidth } : { } ,
226
233
...this . isFormData ? {
227
234
// 这里对根节点打特殊标志,绕过elementUi无prop属性不校验
228
- prop : isRootNode ? '__$$root' : path2prop ( self . curNodePath ) ,
235
+ prop : isRootNode ? '__$$root' : path2prop ( curNodePath ) ,
229
236
rules : [
230
237
{
231
238
validator ( rule , value , callback ) {
@@ -239,15 +246,15 @@ export default {
239
246
customFormats : self . $props . customFormats ,
240
247
errorSchema : self . errorSchema ,
241
248
required : self . required ,
242
- propPath : path2prop ( self . curNodePath )
249
+ propPath : path2prop ( curNodePath )
243
250
} ) ;
244
251
if ( errors . length > 0 ) return callback ( errors [ 0 ] . message ) ;
245
252
246
253
// customRule 如果存在自定义校验
247
254
const curCustomRule = self . $props . customRule ;
248
255
if ( curCustomRule && ( typeof curCustomRule === 'function' ) ) {
249
256
return curCustomRule ( {
250
- field : self . curNodePath ,
257
+ field : curNodePath ,
251
258
value,
252
259
rootFormData : self . rootFormData ,
253
260
callback
@@ -274,14 +281,14 @@ export default {
274
281
} ,
275
282
} ,
276
283
[
277
- self . label ? h ( 'span' , {
284
+ label ? h ( 'span' , {
278
285
slot : 'label' ,
279
286
class : {
280
287
genFormLabel : true ,
281
288
genFormItemRequired : self . required ,
282
289
} ,
283
290
} , [
284
- `${ self . label } ` ,
291
+ `${ label } ` ,
285
292
miniDescriptionVNode ,
286
293
`${ ( self . formProps && self . formProps . labelSuffix ) || '' } `
287
294
] ) : null ,
0 commit comments