BasicFixedWidthForm.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!-- 固定label标题的宽度 -->
  2. <template>
  3. <!-- 自定义表单 -->
  4. <BasicForm @register="registerForm" @submit="handleSubmit" style="margin-top: 20px" />
  5. </template>
  6. <script lang="ts" setup>
  7. //引入依赖
  8. import { useForm, BasicForm, FormSchema } from '/@/components/Form';
  9. //自定义表单字段
  10. const formSchemas: FormSchema[] = [
  11. {
  12. label: '姓名',
  13. field: 'name',
  14. component: 'Input',
  15. },
  16. {
  17. label: '年龄',
  18. field: 'password',
  19. component: 'InputNumber',
  20. },
  21. {
  22. label: '生日',
  23. field: 'birthday',
  24. component: 'DatePicker',
  25. },
  26. {
  27. label: '头像',
  28. field: 'avatar',
  29. component: 'JImageUpload',
  30. },
  31. ];
  32. /**
  33. * BasicForm绑定注册;
  34. */
  35. const [registerForm] = useForm({
  36. //注册表单列
  37. schemas: formSchemas,
  38. showResetButton: false,
  39. submitButtonOptions: { text: '提交', preIcon: '' },
  40. actionColOptions: { span: 17 },
  41. //使用labelWidth控制标题宽度
  42. labelWidth: '150px',
  43. //使用labelCol的样式属性来控制标题宽度
  44. labelCol: { style: { width: '150px' } },
  45. //标题对齐方式(left:左对齐,right:右对齐),默认右对齐
  46. labelAlign: 'right',
  47. });
  48. /**
  49. * 点击提交按钮的value值
  50. * @param values
  51. */
  52. function handleSubmit(values: any) {
  53. console.log('提交按钮数据::::', values);
  54. }
  55. </script>
  56. <style scoped>
  57. /** 时间和数字输入框样式 */
  58. :deep(.ant-input-number) {
  59. width: 100%;
  60. }
  61. :deep(.ant-picker) {
  62. width: 100%;
  63. }
  64. </style>