BasicInfoForm.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script setup lang="ts">
  2. import { PropType, reactive, watch } from 'vue'
  3. import { required } from '@/utils/formRules'
  4. import { CodegenTableVO } from '@/api/infra/codegen/types'
  5. import { Form } from '@/components/Form'
  6. import { useForm } from '@/hooks/web/useForm'
  7. import { FormSchema } from '@/types/form'
  8. const props = defineProps({
  9. basicInfo: {
  10. type: Object as PropType<Nullable<CodegenTableVO>>,
  11. default: () => null
  12. }
  13. })
  14. const rules = reactive({
  15. tableName: [required],
  16. tableComment: [required],
  17. className: [required],
  18. author: [required]
  19. })
  20. const schema = reactive<FormSchema[]>([
  21. {
  22. label: '表名称',
  23. field: 'tableName',
  24. component: 'Input',
  25. colProps: {
  26. span: 12
  27. }
  28. },
  29. {
  30. label: '表描述',
  31. field: 'tableComment',
  32. component: 'Input',
  33. colProps: {
  34. span: 12
  35. }
  36. },
  37. {
  38. label: '实体类名称',
  39. field: 'className',
  40. component: 'Input',
  41. colProps: {
  42. span: 12
  43. }
  44. },
  45. {
  46. label: '作者',
  47. field: 'author',
  48. component: 'Input',
  49. colProps: {
  50. span: 12
  51. }
  52. },
  53. {
  54. label: '备注',
  55. field: 'remark',
  56. component: 'Input',
  57. componentProps: {
  58. type: 'textarea',
  59. rows: 4
  60. },
  61. colProps: {
  62. span: 12
  63. }
  64. }
  65. ])
  66. const { register, methods, elFormRef } = useForm({
  67. schema
  68. })
  69. watch(
  70. () => props.basicInfo,
  71. (basicInfo) => {
  72. if (!basicInfo) return
  73. const { setValues } = methods
  74. setValues(basicInfo)
  75. },
  76. {
  77. deep: true,
  78. immediate: true
  79. }
  80. )
  81. defineExpose({
  82. elFormRef,
  83. getFormData: methods.getFormData
  84. })
  85. </script>
  86. <template>
  87. <Form :rules="rules" @register="register" />
  88. </template>