GenInfoForm.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <script setup lang="ts">
  2. import { onMounted, PropType, reactive, ref, watch } from 'vue'
  3. import { required } from '@/utils/formRules'
  4. import { handleTree } from '@/utils/tree'
  5. import { ElTreeSelect } from 'element-plus'
  6. import { useForm } from '@/hooks/web/useForm'
  7. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  8. import { listSimpleMenusApi } from '@/api/system/menu'
  9. import { CodegenTableVO } from '@/api/infra/codegen/types'
  10. import { FormSchema } from '@/types/form'
  11. const props = defineProps({
  12. genInfo: {
  13. type: Object as PropType<Nullable<CodegenTableVO>>,
  14. default: () => null
  15. }
  16. })
  17. const menuProps = {
  18. checkStrictly: true,
  19. children: 'children',
  20. label: 'name',
  21. value: 'id'
  22. }
  23. const rules = reactive({
  24. templateType: [required],
  25. scene: [required],
  26. moduleName: [required],
  27. businessName: [required],
  28. businessPackage: [required],
  29. className: [required],
  30. classComment: [required]
  31. })
  32. const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
  33. const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
  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 parentMenuId = ref<number>()
  115. //子组件像父组件传值
  116. const emit = defineEmits(['menu'])
  117. const handleNodeClick = () => {
  118. emit('menu', parentMenuId.value)
  119. }
  120. // ========== 初始化 ==========
  121. onMounted(async () => {
  122. await getTree()
  123. })
  124. watch(
  125. () => props.genInfo,
  126. (genInfo) => {
  127. if (!genInfo) return
  128. const { setValues } = methods
  129. setValues(genInfo)
  130. },
  131. {
  132. deep: true,
  133. immediate: true
  134. }
  135. )
  136. defineExpose({
  137. elFormRef,
  138. getFormData: methods.getFormData
  139. })
  140. </script>
  141. <template>
  142. <Form :rules="rules" @register="register">
  143. <template #parentMenuId>
  144. <el-tree-select
  145. v-model="parentMenuId"
  146. ref="treeRef"
  147. node-key="id"
  148. :props="menuProps"
  149. :data="menuOptions"
  150. check-strictly
  151. @change="handleNodeClick"
  152. />
  153. </template>
  154. </Form>
  155. </template>