Commit f2ec2ca2733a0edc5e9d41ae4c3dab47a444dbc2
Committed by
GitHub
1 parent
b66a83c1
feat: 添加更多配置项 (#2607)
Showing
1 changed file
with
152 additions
and
40 deletions
src/views/demo/form/UseForm.vue
... | ... | @@ -49,6 +49,17 @@ |
49 | 49 | { value: 'default', label: 'defualt' }, |
50 | 50 | ]; |
51 | 51 | |
52 | + const layoutList = [ | |
53 | + { value: 'vertical', label: 'vertical' }, | |
54 | + { value: 'inline', label: 'inline' }, | |
55 | + { value: 'horizontal', label: 'horizontal' }, | |
56 | + ]; | |
57 | + | |
58 | + const labelAlignList = [ | |
59 | + { value: 'left', label: 'left' }, | |
60 | + { value: 'right', label: 'right' }, | |
61 | + ]; | |
62 | + | |
52 | 63 | const schemas: FormSchema[] = [ |
53 | 64 | { |
54 | 65 | field: 'field1', |
... | ... | @@ -157,10 +168,9 @@ |
157 | 168 | }, |
158 | 169 | }, |
159 | 170 | ]; |
160 | - | |
161 | 171 | const formSchemas: FormSchema[] = [ |
162 | 172 | { |
163 | - field: '', | |
173 | + field: 'd1', | |
164 | 174 | component: 'Divider', |
165 | 175 | label: '基础属性', |
166 | 176 | colProps: { span: 24 }, |
... | ... | @@ -169,14 +179,38 @@ |
169 | 179 | }, |
170 | 180 | }, |
171 | 181 | { |
182 | + field: 'name', | |
183 | + defaultValue: 'useForm', | |
184 | + component: 'Input', | |
185 | + label: 'name', | |
186 | + colProps: { span: 24 }, | |
187 | + }, | |
188 | + { | |
189 | + field: 'layout', | |
190 | + defaultValue: 'horizontal', | |
191 | + component: 'RadioButtonGroup', | |
192 | + label: 'layout', | |
193 | + colProps: { span: 24 }, | |
194 | + componentProps: { | |
195 | + options: layoutList, | |
196 | + }, | |
197 | + }, | |
198 | + { | |
199 | + field: 'labelAlign', | |
200 | + defaultValue: 'right', | |
201 | + component: 'RadioButtonGroup', | |
202 | + label: 'labelAlign', | |
203 | + colProps: { span: 24 }, | |
204 | + componentProps: { | |
205 | + options: labelAlignList, | |
206 | + }, | |
207 | + }, | |
208 | + { | |
172 | 209 | field: 'labelWidth', |
173 | 210 | defaultValue: 120, |
174 | 211 | component: 'InputNumber', |
175 | 212 | label: 'labelWidth', |
176 | 213 | colProps: { span: 24 }, |
177 | - componentProps: { | |
178 | - size: 'small', | |
179 | - }, | |
180 | 214 | }, |
181 | 215 | { |
182 | 216 | field: 'size', |
... | ... | @@ -186,18 +220,21 @@ |
186 | 220 | colProps: { span: 24 }, |
187 | 221 | componentProps: { |
188 | 222 | options: sizeList, |
189 | - size: 'small', | |
190 | 223 | }, |
191 | 224 | }, |
192 | 225 | { |
226 | + field: 'colon', | |
227 | + defaultValue: false, | |
228 | + component: 'Switch', | |
229 | + label: 'colon', | |
230 | + colProps: { span: 24 }, | |
231 | + }, | |
232 | + { | |
193 | 233 | field: 'disabled', |
194 | 234 | defaultValue: false, |
195 | 235 | component: 'Switch', |
196 | 236 | label: 'disabled', |
197 | 237 | colProps: { span: 24 }, |
198 | - componentProps: { | |
199 | - size: 'small', | |
200 | - }, | |
201 | 238 | }, |
202 | 239 | { |
203 | 240 | field: 'compact', |
... | ... | @@ -205,32 +242,99 @@ |
205 | 242 | component: 'Switch', |
206 | 243 | label: 'compact', |
207 | 244 | colProps: { span: 24 }, |
208 | - componentProps: { | |
209 | - size: 'small', | |
210 | - }, | |
211 | 245 | }, |
212 | 246 | { |
213 | - field: '', | |
247 | + field: 'autoSetPlaceHolder', | |
248 | + defaultValue: true, | |
249 | + component: 'Switch', | |
250 | + label: 'autoSetPlaceHolder', | |
251 | + colProps: { span: 24 }, | |
252 | + }, | |
253 | + { | |
254 | + field: 'autoSubmitOnEnter', | |
255 | + defaultValue: false, | |
256 | + component: 'Switch', | |
257 | + label: 'autoSubmitOnEnter', | |
258 | + colProps: { span: 24 }, | |
259 | + }, | |
260 | + { | |
261 | + field: 'showAdvancedButton', | |
262 | + defaultValue: false, | |
263 | + component: 'Switch', | |
264 | + label: 'showAdvancedButton', | |
265 | + colProps: { span: 24 }, | |
266 | + }, | |
267 | + | |
268 | + { | |
269 | + field: 'd2', | |
214 | 270 | component: 'Divider', |
215 | - label: '网格布局', | |
271 | + label: '网格布局(rowProps)', | |
216 | 272 | colProps: { span: 24 }, |
217 | 273 | componentProps: { |
218 | 274 | orientation: 'center', |
219 | 275 | }, |
220 | 276 | }, |
221 | 277 | { |
222 | - field: 'actionColOptions.span', | |
223 | - component: 'Slider', | |
224 | - defaultValue: 24, | |
225 | - label: 'span', | |
278 | + field: 'rowProps.gutter.0', | |
279 | + component: 'InputNumber', | |
280 | + defaultValue: 0, | |
281 | + label: 'Horizontal Gutter', | |
226 | 282 | colProps: { span: 24 }, |
227 | 283 | componentProps: { |
228 | - min: 1, | |
229 | - max: 24, | |
284 | + addonAfter: 'px', | |
230 | 285 | }, |
231 | 286 | }, |
232 | 287 | { |
233 | - field: '', | |
288 | + field: 'rowProps.gutter.1', | |
289 | + component: 'InputNumber', | |
290 | + defaultValue: 0, | |
291 | + label: 'Vertical Gutter', | |
292 | + colProps: { span: 24 }, | |
293 | + componentProps: { | |
294 | + addonAfter: 'px', | |
295 | + }, | |
296 | + }, | |
297 | + { | |
298 | + field: 'rowProps.align', | |
299 | + defaultValue: 'top', | |
300 | + component: 'Select', | |
301 | + label: 'align', | |
302 | + colProps: { span: 24 }, | |
303 | + componentProps: { | |
304 | + options: [ | |
305 | + { value: 'stretch', label: 'stretch' }, | |
306 | + { value: 'bottom', label: 'bottom' }, | |
307 | + { value: 'top', label: 'top' }, | |
308 | + { value: 'middle', label: 'middle' }, | |
309 | + ], | |
310 | + }, | |
311 | + }, | |
312 | + { | |
313 | + field: 'rowProps.justify', | |
314 | + defaultValue: 'start', | |
315 | + component: 'Select', | |
316 | + label: 'justify', | |
317 | + colProps: { span: 24 }, | |
318 | + componentProps: { | |
319 | + options: [ | |
320 | + { value: 'space-around', label: 'space-around' }, | |
321 | + { value: 'space-between', label: 'space-between' }, | |
322 | + { value: 'center', label: 'center' }, | |
323 | + { value: 'end', label: 'end' }, | |
324 | + { value: 'start', label: 'start' }, | |
325 | + ], | |
326 | + }, | |
327 | + }, | |
328 | + { | |
329 | + field: 'wrap', | |
330 | + defaultValue: true, | |
331 | + component: 'Switch', | |
332 | + label: 'wrap', | |
333 | + colProps: { span: 24 }, | |
334 | + }, | |
335 | + | |
336 | + { | |
337 | + field: 'd3', | |
234 | 338 | component: 'Divider', |
235 | 339 | label: '操作按钮', |
236 | 340 | colProps: { span: 24 }, |
... | ... | @@ -242,11 +346,10 @@ |
242 | 346 | field: 'showActionButtonGroup', |
243 | 347 | defaultValue: true, |
244 | 348 | component: 'Switch', |
245 | - label: '操作按钮', | |
349 | + label: 'showActionButtonGroup', | |
246 | 350 | colProps: { span: 24 }, |
247 | 351 | componentProps: ({ formActionType }) => { |
248 | 352 | return { |
249 | - size: 'small', | |
250 | 353 | onChange: async (val: boolean) => { |
251 | 354 | formActionType.updateSchema([ |
252 | 355 | { field: 'showResetButton', componentProps: { disabled: !val } }, |
... | ... | @@ -254,6 +357,10 @@ |
254 | 357 | field: 'showSubmitButton', |
255 | 358 | componentProps: { disabled: !val }, |
256 | 359 | }, |
360 | + { | |
361 | + field: 'actionColOptions.span', | |
362 | + componentProps: { disabled: !val }, | |
363 | + }, | |
257 | 364 | ]); |
258 | 365 | }, |
259 | 366 | }; |
... | ... | @@ -263,24 +370,36 @@ |
263 | 370 | field: 'showResetButton', |
264 | 371 | defaultValue: true, |
265 | 372 | component: 'Switch', |
266 | - label: '重置按钮', | |
373 | + label: 'showResetButton', | |
267 | 374 | colProps: { span: 24 }, |
268 | - componentProps: { | |
269 | - size: 'small', | |
270 | - }, | |
271 | 375 | }, |
272 | 376 | { |
273 | 377 | field: 'showSubmitButton', |
274 | 378 | defaultValue: true, |
275 | 379 | component: 'Switch', |
276 | - label: '提交按钮', | |
380 | + label: 'showSubmitButton', | |
381 | + colProps: { span: 24 }, | |
382 | + }, | |
383 | + | |
384 | + { | |
385 | + field: 'd4', | |
386 | + component: 'Divider', | |
387 | + label: '操作按钮网格布局(actionColOptions)', | |
277 | 388 | colProps: { span: 24 }, |
278 | 389 | componentProps: { |
279 | - size: 'small', | |
390 | + orientation: 'center', | |
280 | 391 | }, |
281 | 392 | }, |
282 | 393 | { |
283 | - field: '', | |
394 | + field: 'actionColOptions.span', | |
395 | + component: 'Slider', | |
396 | + defaultValue: 24, | |
397 | + label: 'span', | |
398 | + colProps: { span: 24 }, | |
399 | + componentProps: { min: 0, max: 24 }, | |
400 | + }, | |
401 | + { | |
402 | + field: 'd5', | |
284 | 403 | component: 'Divider', |
285 | 404 | label: '其他事件', |
286 | 405 | colProps: { span: 24 }, |
... | ... | @@ -309,32 +428,29 @@ |
309 | 428 | const visible = ref<boolean>(false); |
310 | 429 | const settingFormRef = ref(); |
311 | 430 | const [registerSetting] = useForm({ |
312 | - labelWidth: 80, | |
431 | + size: 'small', | |
313 | 432 | schemas: formSchemas, |
314 | 433 | compact: true, |
315 | 434 | actionColOptions: { span: 24 }, |
316 | 435 | showActionButtonGroup: false, |
317 | 436 | }); |
318 | - | |
319 | 437 | const resetSettings = async () => { |
320 | 438 | setProps({ resetButtonOptions: { disabled: false, text: '重置' } }); |
321 | 439 | setProps({ submitButtonOptions: { disabled: false, loading: false } }); |
322 | 440 | await setFieldsValue({ field9: [] }); |
323 | 441 | await settingFormRef.value?.resetFields(); |
324 | 442 | }; |
325 | - | |
326 | 443 | const handleSubmitSetting = async (values: Recordable) => { |
444 | + console.log(values); | |
327 | 445 | await setProps(values); |
328 | 446 | visible.value = false; |
329 | 447 | }; |
330 | - | |
331 | 448 | const [register, { setProps, setFieldsValue, updateSchema }] = useForm({ |
332 | 449 | labelWidth: 120, |
333 | 450 | schemas, |
334 | 451 | actionColOptions: { span: 24 }, |
335 | 452 | fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']], |
336 | 453 | }); |
337 | - | |
338 | 454 | async function handleLoad() { |
339 | 455 | const promiseFn = function () { |
340 | 456 | return new Promise((resolve) => { |
... | ... | @@ -348,9 +464,7 @@ |
348 | 464 | }, 1000); |
349 | 465 | }); |
350 | 466 | }; |
351 | - | |
352 | 467 | const item = await promiseFn(); |
353 | - | |
354 | 468 | const { field9, province, city, district } = item as any; |
355 | 469 | await updateSchema({ |
356 | 470 | field: 'field9', |
... | ... | @@ -359,16 +473,14 @@ |
359 | 473 | }, |
360 | 474 | }); |
361 | 475 | await setFieldsValue({ field9 }); |
476 | + visible.value = false; | |
362 | 477 | } |
363 | - | |
364 | 478 | const showDrawer = () => { |
365 | 479 | visible.value = true; |
366 | 480 | }; |
367 | - | |
368 | 481 | const onSettings = () => { |
369 | 482 | settingFormRef.value?.submit(); |
370 | 483 | }; |
371 | - | |
372 | 484 | const withClose = (formProps: Partial<FormProps>) => { |
373 | 485 | setProps(formProps); |
374 | 486 | visible.value = false; | ... | ... |