GenInfoForm.vue 2.6 KB

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