FormRender.vue
6.99 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<template>
<template v-for="field of formFields">
<a-form-item v-if="category===field.category" :labelCol="config[field.lineMode].labelCol" :wrapperCol="config[field.lineMode].wrapperCol"
:key="field.fieldName" :colon="field.colon" :label="field.label" :name="field.fieldName" style="text-align: left" :class="{'row': field.lineMode !== 'double'}">
<!-- text -->
<template v-if="field.type === 'text'">
<a-input v-if="!field.password" v-model:value="form[field.fieldName]" :addon-before="field.addonBefore" :addon-after="field.addonAfter" :placeholder="field.placeholder"
:allowClear="field.allowClear" :disabled="field.disabled" :maxlength="field.maxlength"/>
<!-- password -->
<a-input-password v-if="field.password" v-model:value="form[field.fieldName]" :addon-before="field.addonBefore" :addon-after="field.addonAfter"
:placeholder="field.placeholder" :allowClear="field.allowClear" :visibilityToggle="field.visibilityToggle" :disabled="field.disabled"
:maxlength="field.maxlength"/>
</template>
<!-- number -->
<a-input-number v-if="field.type === 'number'" v-model:value="form[field.fieldName]" :min="field.min" :max="field.max" :step="field.step" :placeholder="field.placeholder"
:allowClear="field.allowClear" class="form-item-control" :disabled="field.disabled" :precision="field.precision"/>
<!-- textarea -->
<a-textarea v-if="field.type === 'textarea'" v-model:value="form[field.fieldName]" :placeholder="field.placeholder" :rows="field.rows" :autoSize="field.autosize"
:allowClear="field.allowClear" :disabled="field.disabled"/>
<!-- date -->
<a-date-picker v-if="field.type === 'date'" v-model:value="form[field.fieldName]" :placeholder="field.placeholder" :allowClear="field.allowClear" :format="field.format"
@change="field.onChange" class="form-item-control" :disabled="field.disabled" :showTime="field.showTime"
:picker="field.picker"/>
<!-- date-range -->
<a-range-picker v-if="field.type === 'range'" v-model:value="form[field.fieldName]" :placeholder="field.placeholder" :allowClear="field.allowClear"
:format="field.format" class="form-item-control" :disabled="field.disabled"/>
<!-- time -->
<a-time-picker show-time v-if="field.type === 'time'" v-model:value="form[field.fieldName]" :placeholder="field.placeholder" :allowClear="field.allowClear"
:format="field.format" class="form-item-control" :disabled="field.disabled"/>
<!-- time-range -->
<a-time-range-picker show-time v-if="field.type === 'time-range'" v-model:value="form[field.fieldName]" :placeholder="field.placeholder" :allowClear="field.allowClear"
:format="field.format" class="form-item-control" :disabled="field.disabled"/>
<!-- checkbox -->
<a-checkbox v-if="field.type === 'checkbox'" v-model:checked="form[field.fieldName]" :disabled="field.disabled">{{ field.label }}</a-checkbox>
<!-- checkbox-group -->
<a-checkbox-group v-if="field.type === 'checkbox-group'" v-model:value="form[field.fieldName]" :options="field.optionItems" :disabled="field.disabled"/>
<!-- radio -->
<a-radio v-if="field.type === 'radio'" v-model:checked="form[field.fieldName]" :disabled="field.disabled">{{ field.label }}</a-radio>
<!-- radio-group -->
<a-radio-group v-if="field.type === 'radio-group'" v-model:value="form[field.fieldName]" :options="field.optionItems" :disabled="field.disabled"/>
<!-- switch -->
<a-switch v-if="field.type === 'switch'" v-model:checked="form[field.fieldName]" :checked-children="field.checkedChildren" :un-checked-children="field.unCheckedChildren"
:disabled="field.disabled"/>
<!-- rate -->
<template v-if="field.type === 'rate'">
<a-rate :character="field.character" :count="field.count" v-model:value="form[field.fieldName]" :tooltips="field.tooltips" :disabled="field.disabled"
:allow-clear="field.allowHalf" :autofocus="field.autofocus"/>
</template>
<!-- select -->
<a-select v-if="field.type === 'select'" v-model:value="form[field.fieldName]" :mode="field.mode" class="form-item-control"
@change="field.change" :showSearch="field.showSearch" @search="field.search(value)" :token-separators="field.tokenSeparators"
:placeholder="field.placeholder" :allowClear="field.allowClear" :options="field.optionItems" :disabled="field.disabled"/>
<!-- tree-select -->
<a-tree-select v-if="field.type === 'tree-select'" v-model:value="form[field.fieldName]" show-search class="form-item-control" :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
:placeholder="field.placeholder" :allowClear="field.allowClear" multiple tree-default-expand-all :tree-data="treeData"></a-tree-select>
<template v-if="field.type === 'slot'">
<slot :name="field.name"></slot>
</template>
</a-form-item>
<a-divider v-if="field.divider.enabled" :key="field.fieldName" :text="field.divider.text"/>
</template>
</template>
<script lang="ts">
import {Component, Prop, Vue} from "vue-facing-decorator";
import {FormOptionsType} from "lib/src/core/form/FormField";
@Component({
name: "MFormRender",
components: {}
})
export default class FormRender extends Vue {
/**
* 表单item布局配置
*/
@Prop() config = {
/* Item与控件均占50%,一行两个控件 */
double: {labelCol: {span: 6, offset: 0}, wrapperCol: {span: 14, offset: 0}},
/* Item占100%、控件均占50%,一行一个控件 */
whole: {labelCol: {span: 3, offset: 0}, wrapperCol: {span: 7, offset: 0}},
/* Item占100%、控件均占100%,一行一个控件 */
single: {labelCol: {span: 3, offset: 0}, wrapperCol: {span: 19, offset: 0}}
};
/**
* 表单对象
*/
@Prop() form: { [key: string]: any } = {};
/**
* 字段列表
*/
@Prop() fields: FormOptionsType[] = [];
/**
* 分类
*/
@Prop() category = 'default';
get formFields() {
return this.fields;
}
}
</script>
<style>
.card-form .ant-card-body {
padding: 20px 0 0;
}
.inner-form {
background: #fff;
padding: 15px;
display: flex;
flex-wrap: wrap;
max-height: calc(100vh - 232px);
overflow-y: auto;
}
.inner-form .ant-form-item {
flex: 0 0 50%;
margin-bottom: 20px;
}
.form-item-control {
width: 100%;
}
.inner-form .row {
flex: 0 0 100% !important;
}
.mr-10 {
margin-right: 10px;
}
</style>