BasicInfoForm.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <Form :rules="rules" @register="register" />
  3. </template>
  4. <script setup lang="ts">
  5. import { onMounted, PropType, reactive, ref, watch } from 'vue'
  6. import { required } from '@/utils/formRules'
  7. import { useForm } from '@/hooks/web/useForm'
  8. import { Form } from '@/components/Form'
  9. import { FormSchema } from '@/types/form'
  10. import { CodegenTableVO } from '@/api/infra/codegen/types'
  11. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  12. import { listSimpleMenusApi } from '@/api/system/menu'
  13. import { handleTree, defaultProps } from '@/utils/tree'
  14. const props = defineProps({
  15. basicInfo: {
  16. type: Object as PropType<Nullable<CodegenTableVO>>,
  17. default: () => null
  18. }
  19. })
  20. const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
  21. const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
  22. const menuOptions = ref<any>([]) // 树形结构
  23. const getTree = async () => {
  24. const res = await listSimpleMenusApi()
  25. menuOptions.value = handleTree(res)
  26. }
  27. const rules = reactive({
  28. tableName: [required],
  29. tableComment: [required],
  30. className: [required],
  31. author: [required],
  32. templateType: [required],
  33. scene: [required],
  34. moduleName: [required],
  35. businessName: [required],
  36. businessPackage: [required],
  37. classComment: [required]
  38. })
  39. const schema = reactive<FormSchema[]>([
  40. {
  41. label: '上级菜单',
  42. field: 'parentMenuId',
  43. component: 'TreeSelect',
  44. componentProps: {
  45. data: menuOptions,
  46. props: defaultProps,
  47. checkStrictly: true,
  48. nodeKey: 'id'
  49. },
  50. labelMessage: '分配到指定菜单下,例如 系统管理',
  51. colProps: {
  52. span: 24
  53. }
  54. },
  55. {
  56. label: '表名称',
  57. field: 'tableName',
  58. component: 'Input',
  59. colProps: {
  60. span: 12
  61. }
  62. },
  63. {
  64. label: '表描述',
  65. field: 'tableComment',
  66. component: 'Input',
  67. colProps: {
  68. span: 12
  69. }
  70. },
  71. {
  72. label: '实体类名称',
  73. field: 'className',
  74. component: 'Input',
  75. colProps: {
  76. span: 12
  77. }
  78. },
  79. {
  80. label: '类名称',
  81. field: 'className',
  82. component: 'Input',
  83. labelMessage: '类名称(首字母大写),例如SysUser、SysMenu、SysDictData 等等',
  84. colProps: {
  85. span: 12
  86. }
  87. },
  88. {
  89. label: '生成模板',
  90. field: 'templateType',
  91. component: 'Select',
  92. componentProps: {
  93. options: templateTypeOptions
  94. },
  95. colProps: {
  96. span: 12
  97. }
  98. },
  99. {
  100. label: '生成场景',
  101. field: 'scene',
  102. component: 'Select',
  103. componentProps: {
  104. options: sceneOptions
  105. },
  106. colProps: {
  107. span: 12
  108. }
  109. },
  110. {
  111. label: '模块名',
  112. field: 'moduleName',
  113. component: 'Input',
  114. labelMessage: '模块名,即一级目录,例如 system、infra、tool 等等',
  115. colProps: {
  116. span: 12
  117. }
  118. },
  119. {
  120. label: '业务名',
  121. field: 'businessName',
  122. component: 'Input',
  123. labelMessage: '业务名,即二级目录,例如 user、permission、dict 等等',
  124. colProps: {
  125. span: 12
  126. }
  127. },
  128. {
  129. label: '类描述',
  130. field: 'classComment',
  131. component: 'Input',
  132. labelMessage: '用作类描述,例如 用户',
  133. colProps: {
  134. span: 12
  135. }
  136. },
  137. {
  138. label: '作者',
  139. field: 'author',
  140. component: 'Input',
  141. colProps: {
  142. span: 12
  143. }
  144. },
  145. {
  146. label: '备注',
  147. field: 'remark',
  148. component: 'Input',
  149. componentProps: {
  150. type: 'textarea',
  151. rows: 4
  152. },
  153. colProps: {
  154. span: 24
  155. }
  156. }
  157. ])
  158. const { register, methods, elFormRef } = useForm({
  159. schema
  160. })
  161. watch(
  162. () => props.basicInfo,
  163. (basicInfo) => {
  164. if (!basicInfo) return
  165. const { setValues } = methods
  166. setValues(basicInfo)
  167. },
  168. {
  169. deep: true,
  170. immediate: true
  171. }
  172. )
  173. // ========== 初始化 ==========
  174. onMounted(async () => {
  175. await getTree()
  176. })
  177. defineExpose({
  178. elFormRef,
  179. getFormData: methods.getFormData
  180. })
  181. </script>