genInfoForm.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <ProForm ref="formRef" :items-options="items" :model="model" :form-options="_formOptions"> </ProForm>
  3. <template v-if="model.tplCategory !== 'crud'">
  4. <h4 class="form-header">其他信息</h4>
  5. </template>
  6. <ProForm ref="formRef2" :items-options="treeItemsOptions" :model="infoForm" :form-options="_formOptions"> </ProForm>
  7. </template>
  8. <script lang="ts" name="GenBasicInfo" setup>
  9. import { defineProps, ref, computed, watch } from 'vue'
  10. import ProForm from '@/components/ProForm/index.vue'
  11. const formRef = ref<InstanceType<typeof ProForm> | null>(null)
  12. const formRef2 = ref<InstanceType<typeof ProForm> | null>(null)
  13. export interface InfoProps {
  14. tables: any[] // 表格数据
  15. menus: any[] // 菜单
  16. model: any // 详情数据
  17. }
  18. const props = withDefaults(defineProps<InfoProps>(), {
  19. tables: () => [],
  20. menus: () => [],
  21. model: () => null
  22. })
  23. const subColumns = ref<any>([])
  24. const setSubTableColumns = (value: string) => {
  25. props.tables.forEach((item: any) => {
  26. const name = item.tableName
  27. if (value === name) {
  28. subColumns.value = item.columns
  29. return
  30. }
  31. })
  32. }
  33. const infoForm = computed(() => props.model)
  34. watch(
  35. () => infoForm.value.subTableName,
  36. val => {
  37. setSubTableColumns(val)
  38. }
  39. )
  40. const tplData = [
  41. {
  42. label: '单表(增删改查)',
  43. value: 'crud'
  44. },
  45. {
  46. label: '树表(增删改查)',
  47. value: 'tree'
  48. },
  49. {
  50. label: '主子表(增删改查)',
  51. value: 'sub'
  52. }
  53. ]
  54. const genTypeData = [
  55. {
  56. label: 'zip压缩包',
  57. value: '0'
  58. },
  59. {
  60. label: '自定义路径',
  61. value: '1'
  62. }
  63. ]
  64. const _formOptions = {
  65. hasFooter: false,
  66. labelWidth: 160
  67. }
  68. let treeItemsOptions: ProForm.ItemsOptions[] = []
  69. const setItemsOptions = () => {
  70. treeItemsOptions = [
  71. {
  72. label: '树编码字段',
  73. prop: 'treeCode',
  74. span: 12,
  75. tooltip: '树显示的编码字段名, 如:dept_id',
  76. rules: [{ required: true, message: '树编码字段为空', trigger: 'change' }],
  77. show: () => {
  78. return props.model.tplCategory === 'tree'
  79. },
  80. compOptions: {
  81. elTagName: 'select',
  82. clearable: true,
  83. style: 'width: 80%',
  84. enum: props.model.columns.map((item: any) => {
  85. return {
  86. label: `${item.columnName}:${item.columnComment}`,
  87. value: item.columnName
  88. }
  89. }),
  90. placeholder: '请选择'
  91. }
  92. },
  93. {
  94. label: '树父编码字段',
  95. prop: 'treeParentCode',
  96. span: 12,
  97. tooltip: '树显示的父编码字段名, 如:parent_Id',
  98. show: () => {
  99. return props.model.tplCategory === 'tree'
  100. },
  101. compOptions: {
  102. elTagName: 'select',
  103. clearable: true,
  104. style: 'width: 80%',
  105. enum: infoForm.value.columns.map((item: any) => {
  106. return {
  107. label: `${item.columnName}:${item.columnComment}`,
  108. value: item.columnName
  109. }
  110. }),
  111. placeholder: '请选择'
  112. }
  113. },
  114. {
  115. label: '树名称字段',
  116. prop: 'treeName',
  117. span: 12,
  118. tooltip: '树节点的显示名称字段名, 如:dept_name',
  119. show: () => {
  120. return props.model.tplCategory === 'tree'
  121. },
  122. compOptions: {
  123. elTagName: 'select',
  124. clearable: true,
  125. style: 'width: 80%',
  126. enum: props.model.columns.map((item: any) => {
  127. return {
  128. label: `${item.columnName}:${item.columnComment}`,
  129. value: item.columnName
  130. }
  131. }),
  132. placeholder: '请选择'
  133. }
  134. },
  135. {
  136. label: '关联子表的表名',
  137. prop: 'subTableName',
  138. span: 12,
  139. tooltip: '关联子表的表名, 如:sys_user',
  140. show: () => {
  141. return props.model.tplCategory === 'sub'
  142. },
  143. compOptions: {
  144. elTagName: 'select',
  145. clearable: true,
  146. style: 'width: 80%',
  147. enum: props.tables.map((item: any) => {
  148. return {
  149. label: `${item.tableName}:${item.tableComment}`,
  150. value: item.tableName
  151. }
  152. }),
  153. placeholder: '请选择',
  154. onChange: () => {
  155. setItemsOptions()
  156. infoForm.value.subTableFkName = ''
  157. }
  158. }
  159. },
  160. {
  161. label: '子表关联的外键名',
  162. prop: 'subTableFkName',
  163. span: 12,
  164. tooltip: '子表关联的外键名, 如:user_id',
  165. show: () => {
  166. return props.model.tplCategory === 'sub'
  167. },
  168. compOptions: {
  169. elTagName: 'select',
  170. clearable: true,
  171. style: 'width: 80%',
  172. enum: subColumns.value.map((item: any) => {
  173. return {
  174. label: `${item.columnName}:${item.columnComment}`,
  175. value: item.columnName
  176. }
  177. }),
  178. placeholder: '请选择'
  179. }
  180. }
  181. ]
  182. }
  183. let items: ProForm.ItemsOptions[] = []
  184. const setItem = () => {
  185. items = [
  186. {
  187. label: '生成模板',
  188. prop: 'tplCategory',
  189. span: 12,
  190. rules: [{ required: true, message: '生成模板不能为空', trigger: 'change' }],
  191. compOptions: {
  192. elTagName: 'select',
  193. clearable: true,
  194. style: 'width: 80%',
  195. enum: tplData,
  196. placeholder: '请输入生成模板',
  197. onChange: (val: string) => {
  198. if (val !== 'sub') {
  199. infoForm.value.subTableName = ''
  200. infoForm.value.subTableFkName = ''
  201. }
  202. }
  203. }
  204. },
  205. {
  206. label: '生成包路径',
  207. prop: 'packageName',
  208. tooltip: '生成在哪个java包下,例如 com.km.system',
  209. span: 12,
  210. rules: [{ required: true, message: '生成包路径不能为空', trigger: 'blur' }],
  211. compOptions: {
  212. elTagName: 'input',
  213. clearable: true,
  214. placeholder: '请输入生成包路径'
  215. }
  216. },
  217. {
  218. label: '生成模块名',
  219. prop: 'moduleName',
  220. span: 12,
  221. tooltip: '可理解为子系统名,例如 system',
  222. rules: [{ required: true, message: '生成模块名不能为空', trigger: 'blur' }],
  223. compOptions: {
  224. elTagName: 'input',
  225. clearable: true,
  226. placeholder: '请输入生成模块名'
  227. }
  228. },
  229. {
  230. label: '生成业务名',
  231. prop: 'businessName',
  232. tooltip: '可理解为功能英文名,例如 user',
  233. span: 12,
  234. rules: [{ required: true, message: '生成业务名不能为空', trigger: 'blur' }],
  235. compOptions: {
  236. elTagName: 'input',
  237. clearable: true,
  238. placeholder: '请输入生成业务名'
  239. }
  240. },
  241. {
  242. label: '生成功能名',
  243. prop: 'functionName',
  244. tooltip: '用作类描述,例如 用户',
  245. span: 12,
  246. rules: [{ required: true, message: '生成功能名不能为空', trigger: 'blur' }],
  247. compOptions: {
  248. elTagName: 'input',
  249. clearable: true,
  250. placeholder: '请输入生成功能名'
  251. }
  252. },
  253. {
  254. label: '上级菜单',
  255. prop: 'parentMenuId',
  256. span: 10,
  257. tooltip: '分配到指定菜单下,例如 系统管理',
  258. compOptions: {
  259. elTagName: 'tree-select',
  260. clearable: true,
  261. valueKey: 'menuId',
  262. placeholder: '请选择上级菜单',
  263. appendToBody: true,
  264. checkStrictly: true,
  265. enum: props.menus,
  266. filterable: true,
  267. props: {
  268. value: 'menuId',
  269. label: 'menuName',
  270. children: 'children'
  271. }
  272. }
  273. },
  274. {
  275. label: '生成方式',
  276. prop: 'functionAuthor',
  277. tooltip: '默认为zip压缩包下载,也可以自定义生成路径',
  278. span: 12,
  279. compOptions: {
  280. elTagName: 'radio-group',
  281. value: '0',
  282. enum: genTypeData,
  283. clearable: true,
  284. placeholder: '请输入作者'
  285. }
  286. }
  287. ]
  288. }
  289. setItem()
  290. setItemsOptions()
  291. defineExpose({
  292. formRef,
  293. formRef2
  294. })
  295. </script>