BasicFormModal.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!-- 弹出层表单 -->
  2. <template>
  3. <div style="margin: 20px auto">
  4. <a-button type="primary" @click="openPopup" class="mr-2"> 打开弹窗 </a-button>
  5. </div>
  6. <!-- 自定义弹窗组件 -->
  7. <BasicModal @register="registerModal" title="弹出层表单">
  8. <!-- 自定义表单 -->
  9. <BasicForm @register="registerForm" />
  10. </BasicModal>
  11. </template>
  12. <script lang="ts" setup>
  13. //引入依赖
  14. import { useForm, BasicForm, FormSchema } from '/@/components/Form';
  15. import { BasicModal } from '/@/components/Modal';
  16. import { useModal } from '/@/components/Modal';
  17. //自定义表单字段
  18. const formSchemas: FormSchema[] = [
  19. {
  20. label: '员工姓名',
  21. field: 'name',
  22. component: 'Input',
  23. },
  24. {
  25. label: '性别',
  26. field: 'sex',
  27. component: 'Select',
  28. //填写组件的属性
  29. componentProps: {
  30. options: [
  31. { label: '男', value: 1 },
  32. { label: '女', value: 2 },
  33. { label: '未知', value: 3 },
  34. ],
  35. },
  36. //默认值
  37. defaultValue: 3,
  38. },
  39. {
  40. label: '年龄',
  41. field: 'age',
  42. component: 'Input',
  43. },
  44. {
  45. label: '入职时间',
  46. subLabel: '( 选填 )',
  47. field: 'entryTime',
  48. component: 'TimePicker',
  49. },
  50. ];
  51. //BasicModal绑定注册;
  52. const [registerModal, { openModal }] = useModal();
  53. /**
  54. * BasicForm绑定注册;
  55. */
  56. const [registerForm, { validate, resetFields }] = useForm({
  57. schemas: formSchemas,
  58. //隐藏操作按钮
  59. showActionButtonGroup: false,
  60. });
  61. /**
  62. * 打开弹窗
  63. */
  64. async function openPopup() {
  65. //详见 BasicModal模块
  66. openModal(true, {});
  67. }
  68. </script>
  69. <style scoped>
  70. /** 时间和数字输入框样式 */
  71. :deep(.ant-input-number) {
  72. width: 100%;
  73. }
  74. :deep(.ant-picker) {
  75. width: 100%;
  76. }
  77. </style>