Skip to content

Commit 13b8ec2

Browse files
committed
example: update builder preview
1 parent 8dc7702 commit 13b8ec2

File tree

2 files changed

+108
-1080
lines changed

2 files changed

+108
-1080
lines changed

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

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
<el-card class="preview-card">
44
<div slot="header">
55
<span>动态表单示例</span>
6-
<el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
6+
<div class="pull-right">
7+
<a target="_blank" href="https://codetrial.github.io">@Codetrial</a>
8+
</div>
79
</div>
810
<el-row :gutter="24">
911
<el-col :span="8">
10-
<el-form-builder :config="config" :model="formValues" label-width="48px"></el-form-builder>
12+
<el-form-builder :config="formConfig" :model="formValues" label-width="80px">
13+
<el-button>提交</el-button>
14+
</el-form-builder>
1115
</el-col>
12-
<el-col :span="16">
13-
<el-input type="textarea"></el-input>
16+
<el-col :span="8">
17+
<el-input v-model="config.elements" type="textarea" rows="24"></el-input>
18+
</el-col>
19+
<el-col :span="8">
20+
<el-input v-model="config.rules" type="textarea" rows="24"></el-input>
1421
</el-col>
1522
</el-row>
1623
</el-card>
@@ -21,25 +28,61 @@
2128
export default {
2229
name: 'FormBuilderPreview',
2330
31+
watch: {
32+
config: {
33+
deep: true,
34+
immediate: true,
35+
handler({ rules, elements }) {
36+
try {
37+
this.formConfig = {
38+
rules: JSON.parse(rules),
39+
elements: JSON.parse(elements)
40+
}
41+
} catch (err) {
42+
console.error('[JSON Parse Error] -> ', err.message)
43+
}
44+
}
45+
}
46+
},
47+
2448
data() {
2549
return {
26-
config: {
50+
formValues: {
51+
title: ''
52+
},
53+
54+
formConfig: {
2755
rules: {},
28-
elements: [
29-
{
30-
tag: 'el-input',
31-
item: {
32-
label: '标题'
33-
},
34-
detail: {
35-
name: 'title'
36-
}
37-
}
38-
]
56+
elements: []
3957
},
4058
41-
formValues: {
42-
title: ''
59+
config: {
60+
rules: JSON.stringify(
61+
{
62+
title: [
63+
{ required: true, message: '请输入名称' },
64+
{ max: 5, message: '最多 5 个字符' }
65+
]
66+
},
67+
null,
68+
4
69+
),
70+
71+
elements: JSON.stringify(
72+
[
73+
{
74+
tag: 'el-input',
75+
item: {
76+
label: '标题'
77+
},
78+
detail: {
79+
name: 'title'
80+
}
81+
}
82+
],
83+
null,
84+
4
85+
)
4386
}
4487
}
4588
}
@@ -51,4 +94,8 @@ export default {
5194
height: 100%;
5295
margin: 48px;
5396
}
97+
98+
.pull-right {
99+
float: right;
100+
}
54101
</style>

0 commit comments

Comments
 (0)