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,6 +49,17 @@ | ||
49 | { value: 'default', label: 'defualt' }, | 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 | const schemas: FormSchema[] = [ | 63 | const schemas: FormSchema[] = [ |
53 | { | 64 | { |
54 | field: 'field1', | 65 | field: 'field1', |
@@ -157,10 +168,9 @@ | @@ -157,10 +168,9 @@ | ||
157 | }, | 168 | }, |
158 | }, | 169 | }, |
159 | ]; | 170 | ]; |
160 | - | ||
161 | const formSchemas: FormSchema[] = [ | 171 | const formSchemas: FormSchema[] = [ |
162 | { | 172 | { |
163 | - field: '', | 173 | + field: 'd1', |
164 | component: 'Divider', | 174 | component: 'Divider', |
165 | label: '基础属性', | 175 | label: '基础属性', |
166 | colProps: { span: 24 }, | 176 | colProps: { span: 24 }, |
@@ -169,14 +179,38 @@ | @@ -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 | field: 'labelWidth', | 209 | field: 'labelWidth', |
173 | defaultValue: 120, | 210 | defaultValue: 120, |
174 | component: 'InputNumber', | 211 | component: 'InputNumber', |
175 | label: 'labelWidth', | 212 | label: 'labelWidth', |
176 | colProps: { span: 24 }, | 213 | colProps: { span: 24 }, |
177 | - componentProps: { | ||
178 | - size: 'small', | ||
179 | - }, | ||
180 | }, | 214 | }, |
181 | { | 215 | { |
182 | field: 'size', | 216 | field: 'size', |
@@ -186,18 +220,21 @@ | @@ -186,18 +220,21 @@ | ||
186 | colProps: { span: 24 }, | 220 | colProps: { span: 24 }, |
187 | componentProps: { | 221 | componentProps: { |
188 | options: sizeList, | 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 | field: 'disabled', | 233 | field: 'disabled', |
194 | defaultValue: false, | 234 | defaultValue: false, |
195 | component: 'Switch', | 235 | component: 'Switch', |
196 | label: 'disabled', | 236 | label: 'disabled', |
197 | colProps: { span: 24 }, | 237 | colProps: { span: 24 }, |
198 | - componentProps: { | ||
199 | - size: 'small', | ||
200 | - }, | ||
201 | }, | 238 | }, |
202 | { | 239 | { |
203 | field: 'compact', | 240 | field: 'compact', |
@@ -205,32 +242,99 @@ | @@ -205,32 +242,99 @@ | ||
205 | component: 'Switch', | 242 | component: 'Switch', |
206 | label: 'compact', | 243 | label: 'compact', |
207 | colProps: { span: 24 }, | 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 | component: 'Divider', | 270 | component: 'Divider', |
215 | - label: '网格布局', | 271 | + label: '网格布局(rowProps)', |
216 | colProps: { span: 24 }, | 272 | colProps: { span: 24 }, |
217 | componentProps: { | 273 | componentProps: { |
218 | orientation: 'center', | 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 | colProps: { span: 24 }, | 282 | colProps: { span: 24 }, |
227 | componentProps: { | 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 | component: 'Divider', | 338 | component: 'Divider', |
235 | label: '操作按钮', | 339 | label: '操作按钮', |
236 | colProps: { span: 24 }, | 340 | colProps: { span: 24 }, |
@@ -242,11 +346,10 @@ | @@ -242,11 +346,10 @@ | ||
242 | field: 'showActionButtonGroup', | 346 | field: 'showActionButtonGroup', |
243 | defaultValue: true, | 347 | defaultValue: true, |
244 | component: 'Switch', | 348 | component: 'Switch', |
245 | - label: '操作按钮', | 349 | + label: 'showActionButtonGroup', |
246 | colProps: { span: 24 }, | 350 | colProps: { span: 24 }, |
247 | componentProps: ({ formActionType }) => { | 351 | componentProps: ({ formActionType }) => { |
248 | return { | 352 | return { |
249 | - size: 'small', | ||
250 | onChange: async (val: boolean) => { | 353 | onChange: async (val: boolean) => { |
251 | formActionType.updateSchema([ | 354 | formActionType.updateSchema([ |
252 | { field: 'showResetButton', componentProps: { disabled: !val } }, | 355 | { field: 'showResetButton', componentProps: { disabled: !val } }, |
@@ -254,6 +357,10 @@ | @@ -254,6 +357,10 @@ | ||
254 | field: 'showSubmitButton', | 357 | field: 'showSubmitButton', |
255 | componentProps: { disabled: !val }, | 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,24 +370,36 @@ | ||
263 | field: 'showResetButton', | 370 | field: 'showResetButton', |
264 | defaultValue: true, | 371 | defaultValue: true, |
265 | component: 'Switch', | 372 | component: 'Switch', |
266 | - label: '重置按钮', | 373 | + label: 'showResetButton', |
267 | colProps: { span: 24 }, | 374 | colProps: { span: 24 }, |
268 | - componentProps: { | ||
269 | - size: 'small', | ||
270 | - }, | ||
271 | }, | 375 | }, |
272 | { | 376 | { |
273 | field: 'showSubmitButton', | 377 | field: 'showSubmitButton', |
274 | defaultValue: true, | 378 | defaultValue: true, |
275 | component: 'Switch', | 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 | colProps: { span: 24 }, | 388 | colProps: { span: 24 }, |
278 | componentProps: { | 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 | component: 'Divider', | 403 | component: 'Divider', |
285 | label: '其他事件', | 404 | label: '其他事件', |
286 | colProps: { span: 24 }, | 405 | colProps: { span: 24 }, |
@@ -309,32 +428,29 @@ | @@ -309,32 +428,29 @@ | ||
309 | const visible = ref<boolean>(false); | 428 | const visible = ref<boolean>(false); |
310 | const settingFormRef = ref(); | 429 | const settingFormRef = ref(); |
311 | const [registerSetting] = useForm({ | 430 | const [registerSetting] = useForm({ |
312 | - labelWidth: 80, | 431 | + size: 'small', |
313 | schemas: formSchemas, | 432 | schemas: formSchemas, |
314 | compact: true, | 433 | compact: true, |
315 | actionColOptions: { span: 24 }, | 434 | actionColOptions: { span: 24 }, |
316 | showActionButtonGroup: false, | 435 | showActionButtonGroup: false, |
317 | }); | 436 | }); |
318 | - | ||
319 | const resetSettings = async () => { | 437 | const resetSettings = async () => { |
320 | setProps({ resetButtonOptions: { disabled: false, text: '重置' } }); | 438 | setProps({ resetButtonOptions: { disabled: false, text: '重置' } }); |
321 | setProps({ submitButtonOptions: { disabled: false, loading: false } }); | 439 | setProps({ submitButtonOptions: { disabled: false, loading: false } }); |
322 | await setFieldsValue({ field9: [] }); | 440 | await setFieldsValue({ field9: [] }); |
323 | await settingFormRef.value?.resetFields(); | 441 | await settingFormRef.value?.resetFields(); |
324 | }; | 442 | }; |
325 | - | ||
326 | const handleSubmitSetting = async (values: Recordable) => { | 443 | const handleSubmitSetting = async (values: Recordable) => { |
444 | + console.log(values); | ||
327 | await setProps(values); | 445 | await setProps(values); |
328 | visible.value = false; | 446 | visible.value = false; |
329 | }; | 447 | }; |
330 | - | ||
331 | const [register, { setProps, setFieldsValue, updateSchema }] = useForm({ | 448 | const [register, { setProps, setFieldsValue, updateSchema }] = useForm({ |
332 | labelWidth: 120, | 449 | labelWidth: 120, |
333 | schemas, | 450 | schemas, |
334 | actionColOptions: { span: 24 }, | 451 | actionColOptions: { span: 24 }, |
335 | fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']], | 452 | fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']], |
336 | }); | 453 | }); |
337 | - | ||
338 | async function handleLoad() { | 454 | async function handleLoad() { |
339 | const promiseFn = function () { | 455 | const promiseFn = function () { |
340 | return new Promise((resolve) => { | 456 | return new Promise((resolve) => { |
@@ -348,9 +464,7 @@ | @@ -348,9 +464,7 @@ | ||
348 | }, 1000); | 464 | }, 1000); |
349 | }); | 465 | }); |
350 | }; | 466 | }; |
351 | - | ||
352 | const item = await promiseFn(); | 467 | const item = await promiseFn(); |
353 | - | ||
354 | const { field9, province, city, district } = item as any; | 468 | const { field9, province, city, district } = item as any; |
355 | await updateSchema({ | 469 | await updateSchema({ |
356 | field: 'field9', | 470 | field: 'field9', |
@@ -359,16 +473,14 @@ | @@ -359,16 +473,14 @@ | ||
359 | }, | 473 | }, |
360 | }); | 474 | }); |
361 | await setFieldsValue({ field9 }); | 475 | await setFieldsValue({ field9 }); |
476 | + visible.value = false; | ||
362 | } | 477 | } |
363 | - | ||
364 | const showDrawer = () => { | 478 | const showDrawer = () => { |
365 | visible.value = true; | 479 | visible.value = true; |
366 | }; | 480 | }; |
367 | - | ||
368 | const onSettings = () => { | 481 | const onSettings = () => { |
369 | settingFormRef.value?.submit(); | 482 | settingFormRef.value?.submit(); |
370 | }; | 483 | }; |
371 | - | ||
372 | const withClose = (formProps: Partial<FormProps>) => { | 484 | const withClose = (formProps: Partial<FormProps>) => { |
373 | setProps(formProps); | 485 | setProps(formProps); |
374 | visible.value = false; | 486 | visible.value = false; |