GenInfoForm.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 { DICT_TYPE, getDictOptions } from '@/utils/dict'
  8. const props = defineProps({
  9. currentRow: {
  10. type: Object as PropType<Nullable<CodegenTableVO>>,
  11. default: () => null
  12. }
  13. })
  14. const rules = reactive({
  15. templateType: [required],
  16. scene: [required],
  17. moduleName: [required],
  18. businessName: [required],
  19. businessPackage: [required],
  20. className: [required],
  21. classComment: [required]
  22. })
  23. const schema = reactive<FormSchema[]>([
  24. {
  25. label: '生成模板',
  26. field: 'templateType',
  27. component: 'Select',
  28. componentProps: {
  29. options: getDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
  30. },
  31. colProps: {
  32. span: 12
  33. }
  34. },
  35. {
  36. label: '生成场景',
  37. field: 'scene',
  38. component: 'Select',
  39. componentProps: {
  40. options: getDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
  41. },
  42. colProps: {
  43. span: 12
  44. }
  45. },
  46. {
  47. label: '模块名',
  48. field: 'moduleName',
  49. component: 'Input',
  50. labelMessage: '模块名,即一级目录,例如 system、infra、tool 等等',
  51. colProps: {
  52. span: 12
  53. }
  54. },
  55. {
  56. label: '业务名',
  57. field: 'businessName',
  58. component: 'Input',
  59. labelMessage: '业务名,即二级目录,例如 user、permission、dict 等等',
  60. colProps: {
  61. span: 12
  62. }
  63. },
  64. {
  65. label: '类名称',
  66. field: 'className',
  67. component: 'Input',
  68. labelMessage: '类名称(首字母大写),例如SysUser、SysMenu、SysDictData 等等',
  69. colProps: {
  70. span: 12
  71. }
  72. },
  73. {
  74. label: '类描述',
  75. field: 'classComment',
  76. component: 'Input',
  77. labelMessage: '用作类描述,例如 用户',
  78. colProps: {
  79. span: 12
  80. }
  81. },
  82. {
  83. label: '上级菜单',
  84. field: 'parentMenuId',
  85. component: 'Input',
  86. labelMessage: '分配到指定菜单下,例如 系统管理',
  87. colProps: {
  88. span: 12
  89. }
  90. }
  91. ])
  92. const { register, methods, elFormRef } = useForm({
  93. schema
  94. })
  95. watch(
  96. () => props.currentRow,
  97. (currentRow) => {
  98. if (!currentRow) return
  99. const { setValues } = methods
  100. setValues(currentRow)
  101. },
  102. {
  103. deep: true,
  104. immediate: true
  105. }
  106. )
  107. defineExpose({
  108. elFormRef,
  109. getFormData: methods.getFormData
  110. })
  111. </script>
  112. <template>
  113. <Form :rules="rules" @register="register" />
  114. </template>