|
1
|
<template>
|
vben
authored
|
2
|
<PageWrapper title="UseForm操作示例">
|
|
3
|
<div class="mb-4">
|
vben
authored
|
4
5
6
7
8
9
10
11
|
<a-button @click="setProps({ labelWidth: 150 })" class="mr-2"> 更改labelWidth </a-button>
<a-button @click="setProps({ labelWidth: 120 })" class="mr-2"> 还原labelWidth </a-button>
<a-button @click="setProps({ size: 'large' })" class="mr-2"> 更改Size </a-button>
<a-button @click="setProps({ size: 'default' })" class="mr-2"> 还原Size </a-button>
<a-button @click="setProps({ disabled: true })" class="mr-2"> 禁用表单 </a-button>
<a-button @click="setProps({ disabled: false })" class="mr-2"> 解除禁用 </a-button>
<a-button @click="setProps({ compact: true })" class="mr-2"> 紧凑表单 </a-button>
<a-button @click="setProps({ compact: false })" class="mr-2"> 还原正常间距 </a-button>
|
|
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
|
<a-button @click="setProps({ actionColOptions: { span: 8 } })" class="mr-2">
操作按钮位置
</a-button>
</div>
<div class="mb-4">
<a-button @click="setProps({ showActionButtonGroup: false })" class="mr-2">
隐藏操作按钮
</a-button>
<a-button @click="setProps({ showActionButtonGroup: true })" class="mr-2">
显示操作按钮
</a-button>
<a-button @click="setProps({ showResetButton: false })" class="mr-2"> 隐藏重置按钮 </a-button>
<a-button @click="setProps({ showResetButton: true })" class="mr-2"> 显示重置按钮 </a-button>
<a-button @click="setProps({ showSubmitButton: false })" class="mr-2">
隐藏查询按钮
</a-button>
<a-button @click="setProps({ showSubmitButton: true })" class="mr-2"> 显示查询按钮 </a-button>
<a-button
@click="
setProps({
resetButtonOptions: {
disabled: true,
text: '重置New',
},
})
"
class="mr-2"
>
修改重置按钮
</a-button>
<a-button
@click="
setProps({
submitButtonOptions: {
disabled: true,
loading: true,
},
})
"
class="mr-2"
>
修改查询按钮
</a-button>
|
Jobin
authored
|
55
|
<a-button @click="handleLoad" class="mr-2"> 联动回显 </a-button>
|
|
56
57
58
59
|
</div>
<CollapseContainer title="useForm示例">
<BasicForm @register="register" @submit="handleSubmit" />
</CollapseContainer>
|
vben
authored
|
60
|
</PageWrapper>
|
|
61
62
63
64
65
66
|
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
import { CollapseContainer } from '/@/components/Container/index';
import { useMessage } from '/@/hooks/web/useMessage';
|
vben
authored
|
67
|
import { PageWrapper } from '/@/components/Page';
|
Jobin
authored
|
68
|
import { areaRecord } from '/@/api/demo/cascader';
|
vben
authored
|
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
|
const schemas: FormSchema[] = [
{
field: 'field1',
component: 'Input',
label: '字段1',
colProps: {
span: 8,
},
componentProps: {
placeholder: '自定义placeholder',
onChange: (e: any) => {
console.log(e);
},
},
},
{
field: 'field2',
component: 'Input',
label: '字段2',
colProps: {
span: 8,
},
},
{
field: 'field3',
component: 'DatePicker',
label: '字段3',
colProps: {
span: 8,
},
},
{
|
Vben
authored
|
102
103
104
105
106
107
108
109
|
field: 'fieldTime',
component: 'RangePicker',
label: '时间字段',
colProps: {
span: 8,
},
},
{
|
|
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
field: 'field4',
component: 'Select',
label: '字段4',
colProps: {
span: 8,
},
componentProps: {
options: [
{
label: '选项1',
value: '1',
key: '1',
},
{
label: '选项2',
value: '2',
key: '2',
},
],
},
},
{
field: 'field5',
component: 'CheckboxGroup',
label: '字段5',
colProps: {
span: 8,
},
componentProps: {
options: [
{
label: '选项1',
value: '1',
},
{
label: '选项2',
value: '2',
},
],
},
},
{
field: 'field7',
component: 'RadioGroup',
label: '字段7',
colProps: {
span: 8,
},
componentProps: {
options: [
{
label: '选项1',
value: '1',
},
{
label: '选项2',
value: '2',
},
],
},
},
|
Jobin
authored
|
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
{
field: 'field8',
component: 'ApiCascader',
label: '联动',
colProps: {
span: 8,
},
componentProps: {
api: areaRecord,
apiParamKey: 'parentCode',
dataField: 'data',
labelField: 'name',
valueField: 'code',
initFetchParams: {
parentCode: '',
},
isLeaf: (record) => {
return !(record.levelType < 3);
},
},
},
{
field: 'field9',
component: 'ApiCascader',
label: '联动回显',
colProps: {
span: 8,
},
componentProps: {
api: areaRecord,
apiParamKey: 'parentCode',
dataField: 'data',
labelField: 'name',
valueField: 'code',
initFetchParams: {
parentCode: '',
},
isLeaf: (record) => {
return !(record.levelType < 3);
},
},
},
|
|
213
214
215
|
];
export default defineComponent({
|
vben
authored
|
216
|
components: { BasicForm, CollapseContainer, PageWrapper },
|
|
217
218
|
setup() {
const { createMessage } = useMessage();
|
vben
authored
|
219
|
|
Jobin
authored
|
220
|
const [register, { setProps, setFieldsValue, updateSchema }] = useForm({
|
|
221
222
223
224
225
|
labelWidth: 120,
schemas,
actionColOptions: {
span: 24,
},
|
Vben
authored
|
226
|
fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']],
|
|
227
|
});
|
Jobin
authored
|
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
async function handleLoad() {
const promiseFn = function () {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
field9: ['430000', '430100', '430102'],
province: '湖南省',
city: '长沙市',
district: '岳麓区',
});
}, 1000);
});
};
const item = await promiseFn();
const { field9, province, city, district } = item as any;
await updateSchema({
field: 'field9',
componentProps: {
displayRenderArray: [province, city, district],
},
});
await setFieldsValue({
field9,
});
}
|
|
257
258
259
|
return {
register,
schemas,
|
vben
authored
|
260
|
handleSubmit: (values: Recordable) => {
|
|
261
262
263
|
createMessage.success('click search,values:' + JSON.stringify(values));
},
setProps,
|
Jobin
authored
|
264
|
handleLoad,
|
|
265
266
267
268
|
};
},
});
</script>
|