File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed
docs/src/components/common-ui
packages/@core/ui-kit/form-ui/src Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -395,7 +395,7 @@ export interface FormCommonConfig {
395
395
* 所有表单项的栅格布局
396
396
* @default " "
397
397
*/
398
- formItemClass? : string ;
398
+ formItemClass? : (() => string ) | string ;
399
399
/**
400
400
* 隐藏所有表单项label
401
401
* @default false
Original file line number Diff line number Diff line change @@ -12,7 +12,12 @@ import type {
12
12
import { computed } from ' vue' ;
13
13
14
14
import { Form } from ' @vben-core/shadcn-ui' ;
15
- import { cn , isString , mergeWithArrayOverride } from ' @vben-core/shared/utils' ;
15
+ import {
16
+ cn ,
17
+ isFunction ,
18
+ isString ,
19
+ mergeWithArrayOverride ,
20
+ } from ' @vben-core/shared/utils' ;
16
21
17
22
import { provideFormRenderProps } from ' ./context' ;
18
23
import { useExpandable } from ' ./expandable' ;
@@ -110,6 +115,17 @@ const computedSchema = computed(
110
115
? keepIndex <= index
111
116
: false ;
112
117
118
+ // 处理函数形式的formItemClass
119
+ let resolvedSchemaFormItemClass = schema .formItemClass ;
120
+ if (isFunction (schema .formItemClass )) {
121
+ try {
122
+ resolvedSchemaFormItemClass = schema .formItemClass ();
123
+ } catch (error ) {
124
+ console .error (' Error calling formItemClass function:' , error );
125
+ resolvedSchemaFormItemClass = ' ' ;
126
+ }
127
+ }
128
+
113
129
return {
114
130
colon ,
115
131
disabled ,
@@ -133,7 +149,7 @@ const computedSchema = computed(
133
149
' flex-shrink-0' ,
134
150
{ hidden },
135
151
formItemClass ,
136
- schema . formItemClass ,
152
+ resolvedSchemaFormItemClass ,
137
153
),
138
154
labelClass: cn (labelClass , schema .labelClass ),
139
155
};
Original file line number Diff line number Diff line change @@ -174,10 +174,10 @@ export interface FormCommonConfig {
174
174
*/
175
175
formFieldProps ?: FormFieldOptions ;
176
176
/**
177
- * 所有表单项的栅格布局
177
+ * 所有表单项的栅格布局,支持函数形式
178
178
* @default ""
179
179
*/
180
- formItemClass ?: string ;
180
+ formItemClass ?: ( ( ) => string ) | string ;
181
181
/**
182
182
* 隐藏所有表单项label
183
183
* @default false
You can’t perform that action at this time.
0 commit comments