Skip to content

Commit 0f4d3b4

Browse files
committed
feat(schema-generator): 更新schema生成器 支持配置数组
1 parent 590e37d commit 0f4d3b4

File tree

7 files changed

+81
-8
lines changed

7 files changed

+81
-8
lines changed

packages/demo/src/schema-generator/views/editor/Editor.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<template>
22
<div v-loading="loading">
33
<EditorHeader default-active="4">
4-
<el-button @click="handleToDemo">在 Demo 页验证</el-button>
4+
<el-button plain @click="handleToDemo">Playground中验证</el-button>
5+
<el-button type="primary" plain @click="handlePreview">预览展示</el-button>
56
<el-button type="primary" @click="handleExportSchema">导出Schema</el-button>
67
</EditorHeader>
78

@@ -204,6 +205,20 @@
204205
formProps: filter(formProps, defaultConfig.formProps)
205206
};
206207
},
208+
handlePreview() {
209+
const props = this.getExportCode();
210+
componentWithDialog({
211+
VueComponent: VueJsonFrom,
212+
dialogProps: {
213+
title: '预览展示',
214+
width: '1000px'
215+
},
216+
componentProps: {
217+
value: {},
218+
...props
219+
}
220+
});
221+
},
207222
handleExportSchema() {
208223
componentWithDialog({
209224
VueComponent: ExportSchemaView,

packages/demo/src/schema-generator/views/editor/common/editorData.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export function editorItem2SchemaFieldProps(editorItem, formData) {
130130
disabled: false,
131131
showPassword: false,
132132
showWordLimit: false,
133-
type: 'text'
133+
type: 'text',
134+
135+
showTitle: true,
136+
showDescription: true,
134137
};
135138

136139
// uiSchema

packages/demo/src/schema-generator/views/editor/components/NestedEditor.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
w100: showNestedEditor(item),
1313
[$style.formItem]: true
1414
}"
15+
:style=" item.componentValue.baseValue.uiOptions.width ? {
16+
width: item.componentValue.baseValue.uiOptions.width,
17+
flexBasis: item.componentValue.baseValue.uiOptions.width
18+
} : {}"
1519
>
1620
<ViewComponentWrap
1721
:form-data="formData"
@@ -179,6 +183,12 @@
179183
align-items: center;
180184
justify-content: flex-start;
181185
align-content: flex-start;
186+
:global {
187+
.el-form-item {
188+
width: 100% !important;
189+
flex-basis: 100% !important;
190+
}
191+
}
182192
}
183193
}
184194
&.layoutColumn-1 {

packages/demo/src/schema-generator/views/editor/components/ViewComponentWrap.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,31 @@
1313
:class="$style.toolBarBtn"
1414
class="el-icon-caret-top"
1515
title="上移"
16+
type="button"
1617
@click="$emit('onOperate', { item: editorItem, command: 'moveUp'})"
1718
></button>
1819
<button
1920
:disabled="editorItem.toolBar.moveDownDisabled"
2021
:class="$style.toolBarBtn"
2122
class="el-icon-caret-bottom"
2223
title="下移"
24+
type="button"
2325
@click="$emit('onOperate', { item: editorItem, command: 'moveDown'})"
2426
></button>
2527
<button
2628
:disabled="editorItem.toolBar.copyDisabled"
2729
:class="[$style.toolBarBtn]"
2830
class="el-icon-copy-document"
2931
title="复制"
32+
type="button"
3033
@click="$emit('onOperate', { item: editorItem, command: 'copy' })"
3134
></button>
3235
<button
3336
:disabled="editorItem.toolBar.removeDisabled"
3437
:class="$style.toolBarBtn"
3538
class="el-icon-delete"
3639
title="移除"
40+
type="button"
3741
@click="$emit('onOperate', { item: editorItem, command: 'remove' })"
3842
></button>
3943
</div>

packages/demo/src/schema-generator/views/editor/viewComponents/genSchema.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ function genBaseVal(type = 'string') {
3232
title: '默认值',
3333
type,
3434
'ui:placeholder': '输入默认值'
35+
},
36+
} : {},
37+
...['array'].includes(type) ? {
38+
minItems: {
39+
title: '最少子元素',
40+
type: 'number'
41+
},
42+
maxItems: {
43+
title: '最多子元素',
44+
type: 'number'
45+
},
46+
uniqueItems: {
47+
type: 'boolean',
48+
title: '不允许重复项',
49+
'ui:widget': 'el-switch',
50+
default: false
3551
}
3652
} : {}
3753
}
@@ -40,6 +56,12 @@ function genBaseVal(type = 'string') {
4056
type: 'object',
4157
properties: {
4258
...!['array', 'object'].includes(type) ? {
59+
width: {
60+
title: '宽度',
61+
type: 'string',
62+
description: '请输入style width 支持的格式,<br />比如<strong style="font-weight: bold;">10%、100px</strong>等,推荐百分比单位',
63+
'ui:placeholder': '请输入FormItem宽度'
64+
},
4365
labelWidth: {
4466
title: '标签宽度',
4567
type: 'number',
@@ -55,7 +77,20 @@ function genBaseVal(type = 'string') {
5577
type: 'boolean',
5678
default: false
5779
}
58-
} : {}
80+
} : {
81+
showTitle: {
82+
title: '显示标题',
83+
type: 'boolean',
84+
default: true,
85+
'ui:widget': 'el-switch'
86+
},
87+
showDescription: {
88+
title: '显示描述',
89+
type: 'boolean',
90+
default: true,
91+
'ui:widget': 'el-switch'
92+
}
93+
},
5994
}
6095
}
6196
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export default {
183183

184184
const miniDescriptionVnode = (miniDesModel && descriptionVnode) ? h('el-popover', {
185185
style: {
186-
marginLeft: '4px',
186+
margin: '0 2px',
187187
fontSize: '16px',
188188
cursor: 'pointer'
189189
},
@@ -278,8 +278,9 @@ export default {
278278
miniDescriptionVnode ? h('template', {
279279
slot: 'label',
280280
}, [
281-
`${self.label || ''}${self.formProps.labelSuffix || ''}`,
282-
miniDescriptionVnode
281+
`${self.label || ''}`,
282+
miniDescriptionVnode,
283+
`${self.formProps.labelSuffix || ''}`
283284
]) : null,
284285

285286
// description

packages/lib/src/JsonSchemaForm/index.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
/* validateWidget 单独的校验不属于输入框的*/
109109
.validateWidget {
110110
margin-bottom: 0;
111+
width: 100% !important;
112+
flex-basis: 100% !important;
111113
.formItemErrorBox {
112114
padding: 5px 0;
113115
position: relative;
@@ -127,7 +129,7 @@
127129
}
128130
.arrayOrderList_item {
129131
position: relative;
130-
padding: 25px 10px 20px;
132+
padding: 25px 10px 12px;
131133
border-radius: 2px;
132134
margin-bottom: 6px;
133135
display: flex;
@@ -145,7 +147,7 @@
145147
/*box-shadow: 0 3px 1px -2px rgba(0,0,0,0.2), 0 2px 2px 1px rgba(0,0,0,0.1);*/
146148
}
147149
.arrayListItem_content {
148-
padding-top: 6px;
150+
padding-top: 15px;
149151
flex: 1;
150152
margin: 0 auto;
151153
box-shadow: 0 -1px 0 0 rgba(0,0,0,0.05);
@@ -227,6 +229,9 @@
227229
}
228230
}
229231
&.el-form--label-top {
232+
.arrayListItem_content {
233+
padding-top: 8px;
234+
}
230235
.el-form-item__label {
231236
line-height: 26px;
232237
padding-bottom: 6px;

0 commit comments

Comments
 (0)