Skip to content

Commit 17e44f1

Browse files
committed
example: update preview demo
1 parent 13b8ec2 commit 17e44f1

File tree

6 files changed

+126
-7
lines changed

6 files changed

+126
-7
lines changed

.github/preview.gif

2.27 MB
Loading

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# element-form-builder
22

3-
Build form of element-ui using JSON configuration.
3+
[![Version](https://img.shields.io/npm/v/element-form-builder.svg)](https://www.npmjs.com/package/element-form-builder)
4+
[![License](https://img.shields.io/npm/l/element-form-builder.svg)](https://www.npmjs.com/package/element-form-builder)
5+
[![Dependencies](https://img.shields.io/david/codetrial/element-form-builder.svg)](https://www.npmjs.com/package/element-form-builder)
6+
7+
Build element-ui forms with JSON schema.
8+
9+
## Example
10+
11+
![Screen Capture](.github/preview.gif)

dist/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ var FormBuilder = {
9696
}
9797
}, [].concat(toConsumableArray(vm.$slots.prepend || []), toConsumableArray(vm.renderFormItems(h) || []), toConsumableArray(vm.$slots.append || [])));
9898
},
99+
created: function created() {
100+
this.$emit('input', this.formValues);
101+
},
99102

100103

101104
methods: {

examples/simple-demo/src/components/FormBuilderPreview.vue

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
</div>
1010
<el-row :gutter="24">
1111
<el-col :span="8">
12-
<el-form-builder :config="formConfig" :model="formValues" label-width="80px">
13-
<el-button>提交</el-button>
12+
<el-form-builder :config="formConfig" v-model="formValues" label-width="80px">
13+
<div slot="append" class="submit-item">
14+
<el-button type="primary" @click="showResultModal = true">提交</el-button>
15+
</div>
1416
</el-form-builder>
1517
</el-col>
1618
<el-col :span="8">
@@ -21,6 +23,13 @@
2123
</el-col>
2224
</el-row>
2325
</el-card>
26+
27+
<el-dialog title="提交结果" :visible.sync="showResultModal" width="30%">
28+
<pre>{{ JSON.stringify(formValues, null, 4) }}</pre>
29+
<span slot="footer" class="dialog-footer">
30+
<el-button type="primary" @click="showResultModal = false">确 定</el-button>
31+
</span>
32+
</el-dialog>
2433
</div>
2534
</template>
2635

@@ -47,8 +56,15 @@ export default {
4756
4857
data() {
4958
return {
59+
showResultModal: false,
60+
5061
formValues: {
51-
title: ''
62+
title: '',
63+
desc: '',
64+
date: null,
65+
area: [],
66+
subject: [],
67+
tag: []
5268
},
5369
5470
formConfig: {
@@ -76,7 +92,81 @@ export default {
7692
label: '标题'
7793
},
7894
detail: {
79-
name: 'title'
95+
name: 'title',
96+
defaultValue: '默认标题'
97+
}
98+
},
99+
{
100+
tag: 'el-input',
101+
item: {
102+
label: '描述'
103+
},
104+
detail: {
105+
type: 'textarea',
106+
name: 'desc',
107+
placeholder: '请填写一个精彩的描述',
108+
rows: 3
109+
}
110+
},
111+
{
112+
tag: 'el-date-picker',
113+
item: {
114+
label: '日期'
115+
},
116+
detail: {
117+
name: 'date',
118+
placeholder: '请选择日期',
119+
valueFormat: 'yyyyMMdd'
120+
}
121+
},
122+
{
123+
tag: 'el-radio',
124+
item: {
125+
label: '地区'
126+
},
127+
detail: {
128+
name: 'area',
129+
items: [
130+
{ text: '北京', label: '1' },
131+
{ text: '上海', label: '2' },
132+
{ text: '广州', label: '3' },
133+
{ text: '深圳', label: '4' }
134+
]
135+
}
136+
},
137+
{
138+
tag: 'el-checkbox',
139+
item: {
140+
label: '主题'
141+
},
142+
detail: {
143+
name: 'subject',
144+
items: [
145+
{ text: '历史', label: '1' },
146+
{ text: '战争', label: '2' },
147+
{ text: '科幻', label: '3' },
148+
{ text: '爱情', label: '4' },
149+
{ text: '文艺', label: '5' },
150+
{ text: '生活', label: '6' }
151+
]
152+
}
153+
},
154+
{
155+
tag: 'el-select',
156+
item: {
157+
label: '标签'
158+
},
159+
detail: {
160+
name: 'tag',
161+
multiple: true,
162+
items: [
163+
{ label: '温暖', value: '1' },
164+
{ label: '感动', value: '2' },
165+
{ label: '刺激', value: '3' },
166+
{ label: '紧张', value: '4' },
167+
{ label: '有爱', value: '5' },
168+
{ label: '搞笑', value: '6' }
169+
]
80170
}
81171
}
82172
],
@@ -89,13 +179,27 @@ export default {
89179
}
90180
</script>
91181

92-
<style scoped>
182+
<style>
93183
.preview {
94184
height: 100%;
95185
margin: 48px;
96186
}
97187
188+
.submit-item {
189+
margin-left: 80px;
190+
}
191+
98192
.pull-right {
99193
float: right;
100194
}
195+
196+
.el-radio-group .el-radio,
197+
.el-checkbox-group .el-checkbox {
198+
margin-right: 30px;
199+
}
200+
201+
.el-radio-group .el-radio + .el-radio,
202+
.el-checkbox-group .el-checkbox + .el-checkbox {
203+
margin-left: 0;
204+
}
101205
</style>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "element-form-builder",
33
"version": "0.1.0",
4-
"description": "Build form of element-ui using JSON configuration.",
4+
"description": "Build element-ui forms with JSON schema.",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "node scripts/build.js",

src/formbuilder.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export default {
7474
)
7575
},
7676

77+
created () {
78+
this.$emit('input', this.formValues)
79+
},
80+
7781
methods: {
7882
mergeValues () {
7983
const vm = this

0 commit comments

Comments
 (0)