index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import fs from 'fs';
  2. import * as AllColumns from './columns/index.js';
  3. import { getTableColumnsConfigTemplate, getTableDefineTemplate } from './template.js';
  4. const set = new Set()
  5. const errorLog = {}
  6. // AlignType 对齐方式 - 1:居中对齐 2:左对齐 3:右对齐
  7. function getAlignType(val) {
  8. let result = 1
  9. switch(val) {
  10. case 'left':
  11. result = 2
  12. break
  13. case 'right':
  14. result = 3
  15. break
  16. case 'center':
  17. result = 1
  18. break
  19. }
  20. return result
  21. }
  22. function hanldeColum(modules) {
  23. const columNames = Object.keys(modules)
  24. let result = ''
  25. columNames.forEach(key => {
  26. if(set.has(key)) {
  27. errorLog[key] = `重复的key:${key}`
  28. } else {
  29. result += getTableDefineTemplate(key)
  30. // 当前表头key对应的数据
  31. const tableColumn = AllColumns[key]
  32. tableColumn.forEach((column, index) => {
  33. const { title, align, width} = column
  34. const param = {
  35. tableKey: key,
  36. columnField: column.key,
  37. columnTitle: title,
  38. columnWidth: width ? width : 120,
  39. orderIndex: (index + 1) * 10,
  40. IsShow: 1,
  41. alignType: getAlignType(align)
  42. }
  43. result += getTableColumnsConfigTemplate(param)
  44. })
  45. }
  46. })
  47. return result
  48. }
  49. const result = hanldeColum(AllColumns)
  50. fs.writeFileSync("./output/fxgl_v3_pcweb_table_define.sql", result);