BasicFormCompact.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!-- 操作禁用表单 -->
  2. <template>
  3. <div style="margin: 20px auto; text-align: center">
  4. <!-- 通过setProps 可以设置 userForm 中的属性 -->
  5. <!-- 表单大小,默认为 default -->
  6. <a-button @click="setProps({ size: 'large' })" class="mr-2"> 更改大小为最大 </a-button>
  7. <a-button @click="setProps({ size: 'default' })" class="mr-2"> 还原大小 </a-button>
  8. <a-button @click="setProps({ size: 'small' })" class="mr-2"> 更改大小为最小 </a-button>
  9. <!-- disabled表单禁用 -->
  10. <a-button @click="setProps({ disabled: true })" class="mr-2"> 禁用表单 </a-button>
  11. <a-button @click="setProps({ disabled: false })" class="mr-2"> 解除禁用 </a-button>
  12. <!-- compact 是否为紧凑表单 -->
  13. <a-button @click="setProps({ compact: true })" class="mr-2"> 紧凑表单 </a-button>
  14. <a-button @click="setProps({ compact: false })" class="mr-2"> 还原正常间距 </a-button>
  15. </div>
  16. <!-- 自定义表单 -->
  17. <BasicForm @register="registerForm" style="margin-top: 20px" />
  18. </template>
  19. <script lang="ts" setup>
  20. //引入依赖
  21. import { useForm, BasicForm, FormSchema } from '/@/components/Form';
  22. import { CollapseContainer } from '/@/components/Container';
  23. //自定义表单字段
  24. const formSchemas: FormSchema[] = [
  25. {
  26. field: 'visitor',
  27. label: '来访人员',
  28. component: 'Input',
  29. },
  30. {
  31. field: 'accessed',
  32. label: '来访日期',
  33. component: 'DatePicker',
  34. },
  35. {
  36. field: 'phone',
  37. label: '来访人手机号',
  38. component: 'Input',
  39. },
  40. ];
  41. /**
  42. * BasicForm绑定注册;
  43. * setProps方法可以动态设置useForm中的属性
  44. */
  45. const [registerForm, { setProps }] = useForm({
  46. schemas: formSchemas,
  47. labelWidth: '150px',
  48. //隐藏操作按钮
  49. showActionButtonGroup: false,
  50. //默认聚焦第一个,只支持input
  51. autoFocusFirstItem: true,
  52. });
  53. </script>
  54. <style scoped></style>