Skip to content

Commit 1a86316

Browse files
committed
feat(widget): widget 组件支持透传 $attrs
render函数widget attrs和props 合并通过attrs传递,用来实现透传组件参数。同时 array类型items配置枚举会默认传递multiple参数到widget组件 fix #16
1 parent 7f973c8 commit 1a86316

File tree

16 files changed

+57
-61
lines changed

16 files changed

+57
-61
lines changed

packages/demo/src/index/views/Demo/schemaTypes/1.Simple/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ export default {
7373
'ui:options': {
7474
placeholder: '请输入你的签名',
7575
type: 'textarea',
76-
attrs: {
77-
rows: 6
78-
}
76+
rows: 6
7977
}
8078
}
8179
},

packages/demo/src/index/views/Demo/schemaTypes/5.Widgets/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ export default {
104104
textarea: {
105105
'ui:options': {
106106
type: 'textarea',
107-
attrs: {
108-
rows: 6,
109-
},
107+
rows: 6,
110108
autosize: {
111109
minRows: 2,
112110
maxRows: 4

packages/demo/src/vue-editor/views/editor/config/mDefaultItems.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
export default [
66
{
7-
name: 'CarouselImg',
7+
name: 'MCarouselImg',
88
value: {
99
imgList: [
1010
{
@@ -27,7 +27,7 @@ export default [
2727
}
2828
},
2929
{
30-
name: 'CategoryList',
30+
name: 'MCategoryList',
3131
value: {
3232
imgList: [
3333
{
@@ -69,14 +69,14 @@ export default [
6969
}
7070
},
7171
{
72-
name: 'Text',
72+
name: 'MText',
7373
value: {
7474
txt: '推荐商品',
7575
txtColor: '#e46028'
7676
}
7777
},
7878
{
79-
name: 'RecommendGoods',
79+
name: 'MRecommendGoods',
8080
value: {
8181
title: '推荐商品',
8282
imgList: [
@@ -100,14 +100,14 @@ export default [
100100
}
101101
},
102102
{
103-
name: 'Text',
103+
name: 'MText',
104104
value: {
105105
txt: '抢购商品',
106106
txtColor: '#0A96ED'
107107
}
108108
},
109109
{
110-
name: 'RecommendGoods',
110+
name: 'MRecommendGoods',
111111
value: {
112112
title: '抢购商品',
113113
imgList: [

packages/demo/src/vue-editor/views/editor/viewComponentsM/CarouselImg/CarouselImg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"id": "CarouselImg",
3+
"id": "MCarouselImg",
44
"type": "object",
55
"properties": {
66
"imgList": {

packages/demo/src/vue-editor/views/editor/viewComponentsM/CategoryList/propsSchema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"id": "CategoryList",
3+
"id": "MCategoryList",
44
"type": "object",
55
"title": "配置分类条",
66
"description": "分别配置每个分类的名称以及图片链接,最多配置10组,最少配置3组",

packages/demo/src/vue-editor/views/editor/viewComponentsM/RecommendGoods/propsSchema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"id": "RecommendGoods",
3+
"id": "MRecommendGoods",
44
"type": "object",
55
"title": "配置分类条",
66
"description": "分别配置每个分类的名称以及图片链接,最多配置10组,最少配置3组",
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"id": "Text",
4-
"title": "单文本输入组件",
5-
"description":"单文本输入组件,用于在页面配置一条文字信息" ,
6-
"type": "object",
7-
"required": ["txt"],
8-
"properties": {
9-
"txt": {
10-
"title": "文字",
11-
"type": "string"
12-
},
13-
"txtColor": {
14-
"title": "选择文字颜色",
15-
"type": "string",
16-
"default": "#ff0132"
17-
}
18-
}
19-
}
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"id": "MText",
4+
"title": "单文本输入组件",
5+
"description":"单文本输入组件,用于在页面配置一条文字信息" ,
6+
"type": "object",
7+
"required": ["txt"],
8+
"properties": {
9+
"txt": {
10+
"title": "文字",
11+
"type": "string"
12+
},
13+
"txtColor": {
14+
"title": "选择文字颜色",
15+
"type": "string",
16+
"default": "#ff0132"
17+
}
18+
}
19+
}

packages/docs/docs/zh/guide/basic-config.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ uiSchema = {
129129
showDescription: '是否显示描述信息', // 只对type为 `object`、`array` 类型有效
130130
attrs: {
131131
// 通过 vue render函数 attrs 传递给 Widget 组件,只能配置在叶子节点
132+
// 你也配置在外层,程序会合并 attrs 和 其它外层属性 通过 attrs 传递给子组件
132133
autofocus: true
133134
},
134135
style: {
@@ -195,9 +196,7 @@ uiSchema = {
195196
"ui:options": {
196197
"type": "textarea",
197198
"placeholder": "请输入FirstName(配置在schema中)",
198-
"attrs": {
199-
"rows": 4
200-
}
199+
"rows": 4
201200
}
202201
}
203202
}
@@ -241,9 +240,7 @@ export default {
241240
'ui:options': {
242241
type: 'textarea',
243242
placeholder: 'placeholder(配置在schema中)',
244-
attrs: {
245-
rows: 4
246-
}
243+
rows: 4
247244
}
248245
},
249246
inputText: {
@@ -268,17 +265,15 @@ export default {
268265
'ui:description': '这里重置了描述信息',
269266
'ui:emptyValue': '',
270267
'ui:options': {
271-
attrs: {
272-
autofocus: true,
273-
rows: 6,
274-
},
275268
style: {
276269
boxShadow: '0 0 6px 2px #2b9939'
277270
},
278271
class: {
279272
className_hei: true
280273
},
281274
type: 'textarea',
275+
autofocus: true,
276+
rows: 6,
282277
placeholder: '请输入你的内容'
283278
}
284279
},

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,12 @@ export default {
233233
h( // 关键输入组件
234234
self.widget,
235235
{
236-
props: {
237-
...self.uiProps,
238-
value: this.value, // v-model
239-
},
240236
style: self.widgetStyle,
241237
class: self.widgetClass,
242238
attrs: {
243-
placeholder: self.uiProps.placeholder, // 兼容placeholder配置在 外层或者attr内
244-
...self.widgetAttrs
239+
...self.widgetAttrs,
240+
...self.uiProps,
241+
value: this.value, // v-model
245242
},
246243
on: {
247244
input(event) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export default {
3636
}));
3737

3838
// 存在枚举数据列表 传入 enumOptions
39+
widgetConfig.uiProps.multiple = true;
40+
3941
if (enumOptions) {
4042
widgetConfig.uiProps.enumOptions = enumOptions;
4143
}

0 commit comments

Comments
 (0)