codeGenerate.data.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. import { BasicColumn } from '/@/components/Table';
  2. import { FormSchema } from '/@/components/Table';
  3. import {
  4. getMenuList,
  5. getDictDataDropdown,
  6. getDatabaseList,
  7. getTableList,
  8. getColumnList,
  9. } from '/@/api/sys/admin';
  10. const apiDatabaseList = async (param: any) => {
  11. const result = await getDatabaseList(param);
  12. return result;
  13. };
  14. let currentCongidId = '';
  15. let tableList: any[] = [];
  16. const apiTableList = async (param: any) => {
  17. //const result = await getTableList(param);
  18. //return result;
  19. if (tableList.length === 0 || currentCongidId !== param) {
  20. //console.log(param);
  21. const result = await getTableList(param);
  22. tableList = result;
  23. } else {
  24. }
  25. currentCongidId = param;
  26. return tableList;
  27. };
  28. let currentTable = '';
  29. let columnList: any[] = [];
  30. const apiColumnList = async (param: any) => {
  31. //if (typeof param !== 'string') return [];
  32. if (columnList.length === 0 || currentTable !== param.e) {
  33. //console.log('param:' + param);
  34. const result = await getColumnList(param.configId, param.e);
  35. columnList = result;
  36. } else {
  37. }
  38. currentTable = param.e;
  39. return columnList;
  40. };
  41. const apiDictTypeDropDown = async () => {
  42. const result = await getDictDataDropdown('code_gen_create_type');
  43. return result;
  44. };
  45. export const codeShowColumns: BasicColumn[] = [
  46. {
  47. title: '库定位器',
  48. dataIndex: 'configId',
  49. },
  50. {
  51. title: '表名称',
  52. dataIndex: 'tableName',
  53. },
  54. {
  55. title: '业务名',
  56. dataIndex: 'busName',
  57. },
  58. {
  59. title: '命名空间',
  60. dataIndex: 'nameSpace',
  61. },
  62. {
  63. title: '作者姓名',
  64. dataIndex: 'authorName',
  65. },
  66. {
  67. title: '生成方式',
  68. dataIndex: 'generateType',
  69. slots: { customRender: 'generateType' },
  70. },
  71. ];
  72. export const codeFormSchema: FormSchema[] = [
  73. {
  74. field: 'id',
  75. label: 'Id',
  76. component: 'Input',
  77. show: false,
  78. },
  79. {
  80. field: 'configId',
  81. label: '库定位器',
  82. component: 'ApiSelect',
  83. componentProps: ({ formModel, formActionType }) => {
  84. return {
  85. api: apiDatabaseList,
  86. fieldNames: {
  87. label: 'configId',
  88. value: 'configId',
  89. },
  90. onChange: (e: any, option: any) => {
  91. formModel.tableName = undefined;
  92. formModel.dbType = option.dbType;
  93. formModel.connectionString = option.connectionString;
  94. const { updateSchema } = formActionType;
  95. updateSchema([
  96. {
  97. field: 'dbType',
  98. componentProps: {
  99. // api: apiTableList,
  100. // immediate: false,
  101. // params: e,
  102. //fieldNames: {
  103. // label: 'dbType',
  104. // value: 'dbType',
  105. //},
  106. },
  107. },
  108. {
  109. field: 'connectionString',
  110. componentProps: {
  111. // api: apiTableList,
  112. // immediate: false,
  113. // params: e,
  114. //fieldNames: {
  115. // label: 'connectionString',
  116. // value: 'connectionString',
  117. //},
  118. },
  119. },
  120. {
  121. field: 'tableName',
  122. componentProps: {
  123. api: apiTableList,
  124. immediate: false,
  125. params: e,
  126. fieldNames: {
  127. label: 'tableName',
  128. value: 'entityName',
  129. },
  130. },
  131. },
  132. ]);
  133. },
  134. };
  135. },
  136. },
  137. {
  138. field: 'dbType',
  139. label: '数据库类型',
  140. component: 'Input',
  141. dynamicDisabled: true,
  142. },
  143. {
  144. field: 'connectionString',
  145. label: '链接串',
  146. component: 'InputTextArea',
  147. dynamicDisabled: true,
  148. },
  149. {
  150. field: 'tableName',
  151. label: '生成表',
  152. component: 'ApiSelect',
  153. // componentProps: {
  154. // api: apiTableList,
  155. // fieldNames: {
  156. // label: 'tableName',
  157. // value: 'entityName',
  158. // },
  159. // },
  160. },
  161. {
  162. field: 'busName',
  163. label: '业务名',
  164. component: 'Input',
  165. required: true,
  166. },
  167. {
  168. field: 'menuPid',
  169. label: '父级菜单',
  170. component: 'ApiTreeSelect',
  171. componentProps: {
  172. api: getMenuList,
  173. fieldNames: {
  174. title: 'title',
  175. key: 'id',
  176. value: 'id',
  177. },
  178. getPopupContainer: () => document.body,
  179. },
  180. },
  181. {
  182. field: 'nameSpace',
  183. label: '命名空间',
  184. component: 'Input',
  185. required: true,
  186. defaultValue: 'Admin.NET.Application',
  187. },
  188. {
  189. field: 'authorName',
  190. label: '作者姓名',
  191. component: 'Input',
  192. required: true,
  193. defaultValue: 'one',
  194. },
  195. {
  196. field: 'generateType',
  197. label: '生成方式',
  198. component: 'ApiSelect',
  199. componentProps: {
  200. api: apiDictTypeDropDown,
  201. fieldNames: {
  202. label: 'label',
  203. value: 'value',
  204. },
  205. },
  206. defaultValue: '2',
  207. required: true,
  208. },
  209. ];
  210. // 表头
  211. export const columns = [
  212. {
  213. title: '字段',
  214. dataIndex: 'columnName',
  215. align: 'center',
  216. },
  217. {
  218. title: '描述',
  219. dataIndex: 'columnComment',
  220. align: 'center',
  221. width: 150,
  222. slots: {
  223. customRender: 'columnComment',
  224. },
  225. },
  226. {
  227. title: '类型',
  228. dataIndex: 'netType',
  229. align: 'center',
  230. },
  231. // {
  232. // title: 'java类型',
  233. // dataIndex: 'javaType',
  234. // slots: { customRender: 'javaType' }
  235. // },
  236. {
  237. title: '作用类型',
  238. dataIndex: 'effectType',
  239. align: 'center',
  240. slots: {
  241. customRender: 'effectType',
  242. },
  243. },
  244. {
  245. title: '字典',
  246. dataIndex: 'dictTypeCode',
  247. align: 'center',
  248. slots: {
  249. customRender: 'dictTypeCode',
  250. },
  251. },
  252. {
  253. title: '列表显示',
  254. align: 'center',
  255. dataIndex: 'whetherTable',
  256. slots: {
  257. customRender: 'whetherTable',
  258. },
  259. },
  260. {
  261. title: '增改',
  262. align: 'center',
  263. dataIndex: 'whetherAddUpdate',
  264. slots: {
  265. customRender: 'whetherAddUpdate',
  266. },
  267. },
  268. {
  269. title: '必填',
  270. align: 'center',
  271. dataIndex: 'whetherRequired',
  272. slots: {
  273. customRender: 'whetherRequired',
  274. },
  275. },
  276. {
  277. title: '是否是查询',
  278. align: 'center',
  279. dataIndex: 'queryWhether',
  280. slots: {
  281. customRender: 'queryWhether',
  282. },
  283. },
  284. {
  285. title: '查询方式',
  286. dataIndex: 'queryType',
  287. align: 'center',
  288. slots: {
  289. customRender: 'queryType',
  290. },
  291. },
  292. ];
  293. //外键
  294. export const fkFormSchema: FormSchema[] = [
  295. {
  296. field: 'configId',
  297. label: '库定位器',
  298. component: 'ApiSelect',
  299. componentProps: ({ formModel, formActionType }) => {
  300. return {
  301. api: apiDatabaseList,
  302. fieldNames: {
  303. label: 'configId',
  304. value: 'configId',
  305. },
  306. onChange: (e: any, option: any) => {
  307. formModel.tableName = option.tableName;
  308. formModel.dbType = option.dbType;
  309. formModel.connectionString = option.connectionString;
  310. const { updateSchema } = formActionType;
  311. const configId = e;
  312. console.log('dbchange' + configId);
  313. updateSchema([
  314. {
  315. field: 'tableName',
  316. label: '数据库表',
  317. component: 'ApiSelect',
  318. componentProps: ({ formModel, formActionType }) => {
  319. return {
  320. api: apiTableList,
  321. immediate: false,
  322. params: e,
  323. fieldNames: {
  324. label: 'tableName',
  325. value: 'tableName',
  326. },
  327. onChange: (e: any, option: any) => {
  328. formModel.columnName = undefined;
  329. formModel.entityName = option.entityName;
  330. const { updateSchema } = formActionType;
  331. console.log('tableNamechange' + configId);
  332. updateSchema({
  333. field: 'columnName',
  334. componentProps: {
  335. api: apiColumnList,
  336. immediate: false,
  337. fieldNames: {
  338. label: 'columnName',
  339. value: 'columnName',
  340. },
  341. params: { configId, e },
  342. onChange: (e: any, option: any) => {
  343. console.log(e + 'columnNamechange' + configId);
  344. formModel.columnNetType = option.netType;
  345. },
  346. },
  347. });
  348. },
  349. };
  350. },
  351. },
  352. ]);
  353. },
  354. };
  355. },
  356. },
  357. // {
  358. // field: 'tableName',
  359. // label: '数据库表',
  360. // component: 'ApiSelect',
  361. // componentProps: ({ formModel, formActionType }) => {
  362. // return {
  363. // api: apiTableList,
  364. // fieldNames: {
  365. // label: 'tableName',
  366. // value: 'tableName',
  367. // },
  368. // onChange: (e: any, option: any) => {
  369. // formModel.columnName = undefined;
  370. // formModel.entityName = option.entityName;
  371. // const { updateSchema } = formActionType;
  372. // updateSchema({
  373. // field: 'columnName',
  374. // componentProps: {
  375. // api: apiColumnList,
  376. // immediate: false,
  377. // fieldNames: {
  378. // label: 'columnName',
  379. // value: 'columnName',
  380. // },
  381. // params: e,
  382. // onChange: (e: any, option: any) => {
  383. // formModel.columnNetType = option.netType;
  384. // },
  385. // },
  386. // });
  387. // },
  388. // };
  389. // },
  390. // },
  391. {
  392. field: 'tableName',
  393. label: '数据库表',
  394. component: 'ApiSelect',
  395. },
  396. {
  397. field: 'columnName',
  398. label: '显示字段',
  399. component: 'ApiSelect',
  400. },
  401. {
  402. field: 'columnNetType',
  403. label: '字段类型',
  404. component: 'Input',
  405. show: false,
  406. },
  407. {
  408. field: 'entityName',
  409. label: '实体名称',
  410. component: 'Input',
  411. show: false,
  412. },
  413. ];
  414. //树形
  415. export const treeFormSchema: FormSchema[] = [
  416. {
  417. field: 'configId',
  418. label: '库定位器',
  419. component: 'ApiSelect',
  420. componentProps: ({ formModel, formActionType }) => {
  421. return {
  422. api: apiDatabaseList,
  423. fieldNames: {
  424. label: 'configId',
  425. value: 'configId',
  426. },
  427. onChange: (e: any, option: any) => {
  428. formModel.tableName = undefined;
  429. formModel.dbType = option.dbType;
  430. formModel.connectionString = option.connectionString;
  431. const { updateSchema } = formActionType;
  432. const configId = e;
  433. updateSchema([
  434. {
  435. field: 'tableName',
  436. label: '数据库表',
  437. component: 'ApiSelect',
  438. componentProps: ({ formModel, formActionType }) => {
  439. return {
  440. api: apiTableList,
  441. immediate: false,
  442. params: e,
  443. fieldNames: {
  444. label: 'tableName',
  445. value: 'tableName',
  446. },
  447. onChange: (e: any, option: any) => {
  448. formModel.columnName = undefined;
  449. formModel.entityName = option.entityName;
  450. const { updateSchema } = formActionType;
  451. updateSchema([
  452. {
  453. field: 'displayColumn',
  454. componentProps: {
  455. api: apiColumnList,
  456. immediate: false,
  457. params: { configId, e },
  458. fieldNames: {
  459. label: 'columnName',
  460. value: 'columnName',
  461. },
  462. },
  463. },
  464. {
  465. field: 'valueColumn',
  466. componentProps: {
  467. api: apiColumnList,
  468. immediate: false,
  469. params: { configId, e },
  470. fieldNames: {
  471. label: 'columnName',
  472. value: 'columnName',
  473. },
  474. },
  475. },
  476. {
  477. field: 'pidColumn',
  478. componentProps: {
  479. api: apiColumnList,
  480. immediate: false,
  481. params: { configId, e },
  482. fieldNames: {
  483. label: 'columnName',
  484. value: 'columnName',
  485. },
  486. },
  487. },
  488. ]);
  489. },
  490. };
  491. },
  492. },
  493. ]);
  494. },
  495. };
  496. },
  497. },
  498. // {
  499. // field: 'tableName',
  500. // label: '数据库表',
  501. // component: 'ApiSelect',
  502. // componentProps: ({ formModel, formActionType }) => {
  503. // return {
  504. // api: apiTableList,
  505. // fieldNames: {
  506. // label: 'tableName',
  507. // value: 'tableName',
  508. // },
  509. // onChange: (e: any, option: any) => {
  510. // formModel.columnName = undefined;
  511. // formModel.entityName = option.entityName;
  512. // const { updateSchema } = formActionType;
  513. // updateSchema([
  514. // {
  515. // field: 'displayColumn',
  516. // componentProps: {
  517. // api: apiColumnList,
  518. // immediate: false,
  519. // params: e,
  520. // fieldNames: {
  521. // label: 'columnName',
  522. // value: 'columnName',
  523. // },
  524. // },
  525. // },
  526. // {
  527. // field: 'valueColumn',
  528. // componentProps: {
  529. // api: apiColumnList,
  530. // immediate: false,
  531. // params: e,
  532. // fieldNames: {
  533. // label: 'columnName',
  534. // value: 'columnName',
  535. // },
  536. // },
  537. // },
  538. // {
  539. // field: 'pidColumn',
  540. // componentProps: {
  541. // api: apiColumnList,
  542. // immediate: false,
  543. // params: e,
  544. // fieldNames: {
  545. // label: 'columnName',
  546. // value: 'columnName',
  547. // },
  548. // },
  549. // },
  550. // ]);
  551. // },
  552. // };
  553. // },
  554. // },
  555. {
  556. field: 'tableName',
  557. label: '数据库表',
  558. component: 'ApiSelect',
  559. },
  560. {
  561. field: 'displayColumn',
  562. label: '显示文本字段',
  563. component: 'ApiSelect',
  564. },
  565. {
  566. field: 'valueColumn',
  567. label: '选择值字段',
  568. component: 'ApiSelect',
  569. },
  570. {
  571. field: 'pidColumn',
  572. label: '父级字段',
  573. component: 'ApiSelect',
  574. },
  575. {
  576. field: 'entityName',
  577. label: '实体名称',
  578. component: 'Input',
  579. show: false,
  580. },
  581. ];