GenInfoForm.vue 3.5 KB

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