Skip to content

Commit b85b69f

Browse files
committed
feat(field): filed组件 支持通过uiSchema配置 className、attrs、style
re #8
1 parent 88781d0 commit b85b69f

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

packages/lib/src/JsonSchemaForm/common/formUtils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export function getUiOptions({
143143
}
144144

145145
// 获取当前节点的ui 配置 (options + widget)
146+
// 处理成 Widget 组件需要的格式
146147
export function getWidgetConfig({
147148
schema = {},
148149
uiSchema = {}
@@ -164,8 +165,11 @@ export function getWidgetConfig({
164165
labelWidth,
165166
description,
166167
attrs: widgetAttrs,
167-
class: widgetClassName,
168+
class: widgetClass,
168169
style: widgetStyle,
170+
fieldAttrs,
171+
fieldStyle,
172+
fieldClass,
169173
emptyValue,
170174
...uiProps
171175
} = widgetConfig;
@@ -176,8 +180,11 @@ export function getWidgetConfig({
176180
labelWidth,
177181
description,
178182
widgetAttrs,
179-
widgetClassName,
183+
widgetClass,
180184
widgetStyle,
185+
fieldAttrs,
186+
fieldStyle,
187+
fieldClass,
181188
emptyValue,
182189
uiProps
183190
};

packages/lib/src/JsonSchemaForm/fieldComponents/Widget.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,36 @@ export default {
8484
type: String,
8585
default: ''
8686
},
87-
// attrs
87+
// Widget attrs
8888
widgetAttrs: {
8989
type: Object,
9090
default: () => ({})
9191
},
92-
// className
93-
widgetClassName: {
92+
// Widget className
93+
widgetClass: {
9494
type: Object,
9595
default: () => ({})
9696
},
97-
// style
97+
// Widget style
9898
widgetStyle: {
9999
type: Object,
100100
default: () => ({})
101101
},
102+
// Field attrs
103+
fieldAttrs: {
104+
type: Object,
105+
default: () => ({})
106+
},
107+
// Field className
108+
fieldClass: {
109+
type: Object,
110+
default: () => ({})
111+
},
112+
// Field style
113+
fieldStyle: {
114+
type: Object,
115+
default: () => ({})
116+
},
102117
// props
103118
uiProps: {
104119
type: Object,
@@ -142,8 +157,11 @@ export default {
142157
'el-form-item',
143158
{
144159
class: {
160+
...self.fieldClass,
145161
'is-required': self.required
146162
},
163+
style: self.fieldStyle,
164+
attrs: self.fieldAttrs,
147165
props: {
148166
label: self.label,
149167
labelWidth: self.labelWidth,
@@ -220,7 +238,7 @@ export default {
220238
value: this.value, // v-model
221239
},
222240
style: self.widgetStyle,
223-
class: self.widgetClassName,
241+
class: self.widgetClass,
224242
attrs: {
225243
placeholder: self.uiProps.placeholder, // 兼容placeholder配置在 外层或者attr内
226244
...self.widgetAttrs

packages/lib/src/JsonSchemaForm/fields/ArrayField/arrayTypes/ArrayFieldNormal.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ export default {
2626
} = this.$props;
2727

2828
const {
29-
title, description, addable, sortable, removable, showTitle, showDescription
29+
title,
30+
description,
31+
addable,
32+
sortable,
33+
removable,
34+
showTitle,
35+
showDescription,
36+
fieldClass,
37+
fieldAttrs,
38+
fieldStyle,
3039
} = getUiOptions({
3140
schema,
3241
uiSchema
@@ -59,6 +68,9 @@ export default {
5968
showTitle,
6069
showDescription
6170
},
71+
class: fieldClass,
72+
attrs: fieldAttrs,
73+
style: fieldStyle,
6274
},
6375
[
6476
h(

packages/lib/src/JsonSchemaForm/fields/ArrayField/arrayTypes/ArrayFieldTuple.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ export default {
6161
} = this.$props;
6262

6363
const {
64-
title, description, addable, sortable, removable, showTitle, showDescription
64+
title,
65+
description,
66+
addable,
67+
sortable,
68+
removable,
69+
showTitle,
70+
showDescription,
71+
fieldClass,
72+
fieldAttrs,
73+
fieldStyle,
6574
} = getUiOptions({
6675
schema,
6776
uiSchema
@@ -116,7 +125,10 @@ export default {
116125
description,
117126
showTitle,
118127
showDescription
119-
}
128+
},
129+
class: fieldClass,
130+
attrs: fieldAttrs,
131+
style: fieldStyle,
120132
},
121133
[
122134
// 先显示Tuple固定项

packages/lib/src/JsonSchemaForm/fields/ObjectField/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default {
3535
} = props;
3636

3737
const {
38-
title, description, showTitle, showDescription, order
38+
title, description, showTitle, showDescription, order, fieldClass, fieldAttrs, fieldStyle
3939
} = getUiOptions({
4040
schema,
4141
uiSchema
@@ -72,6 +72,9 @@ export default {
7272
showTitle,
7373
showDescription
7474
},
75+
class: fieldClass,
76+
attrs: fieldAttrs,
77+
style: fieldStyle
7578
},
7679
[
7780
h(

0 commit comments

Comments
 (0)