index.vue
1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<script>
export default {
name: 'FormItem',
props: {
label: String,
labelWidth: String,
value: [Number, String, Array, Boolean, Object],
prop: String,
span: [Number, String],
xs: [Number, Object],
sm: [Number, Object],
md: [Number, Object],
lg: [Number, Object],
xl: [Number, Object],
},
provide() {
return {
zFormItem: this,
};
},
inject: {
zForm: {
default: undefined,
},
},
render(h) {
let scopedSlots = this.$scopedSlots;
let content = '';
if (scopedSlots.default) {
content = scopedSlots.default();
} else {
if (!scopedSlots.default) {
if (this.zForm && this.zForm.itemComponent) {
content = h(this.zForm.itemComponent, {
props: {
value: this.value,
...this.$attrs,
},
on: {
input: value => {
this.$emit('input', value);
},
},
});
} else {
content = this.value;
}
}
}
return h('el-col', { props: this.colProps(['span', 'xs', 'sm', 'md', 'lg', 'xl']) }, [
h(
'el-form-item',
{
props: { label: this.label, 'label-width': this.labelWidth, prop: this.prop, ...this.$attrs },
scopedSlots,
},
[content],
),
]);
},
methods: {
colProps(props) {
return props.reduce((result, key) => {
if (this[key]) {
result[key] = Number(this[key]);
} else {
result[key] = this.zForm ? Number(this.zForm[key]) : undefined;
}
return result;
}, {});
},
},
};
</script>