plotList.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * @description: webpack读取当前文件夹下的所有 图表的js文件配置, 生成g2Plot配置列表
  3. * @Date: 2023-03-28 10:40:22
  4. * @Author: xing.heng
  5. */
  6. import { dataConfig, settingConfig } from '../PlotRender/settingConfig'
  7. import { mapData } from 'packages/BasicComponents/Map/settingConfig'
  8. import _ from 'lodash'
  9. import sortList from './plotListSort'
  10. // 遍历 当前文件夹下的所有文件,找到中文.js文件,然后导出
  11. const files = require.context('./', true, /[\u4e00-\u9fa5]+.js$/)
  12. const plotList = getPlotList(files)
  13. const customPlots = getCustomPlots()
  14. // 获取plot配置
  15. function getPlotList (files) {
  16. const configMapList = {}
  17. files.keys().forEach((key) => {
  18. // ./折线图/基础折线图.js
  19. // 取到 "基础折线图"
  20. const configName = key.split('/')[2].replace('.js', '')
  21. configMapList[configName] = files(key).default
  22. })
  23. const plotList = []
  24. for (const configMapKey in configMapList) {
  25. const index = sortList.findIndex((item) => item === configMapKey)
  26. const config = configMapList[configMapKey]
  27. plotList[index] = {
  28. category: configMapKey,
  29. name: config.name,
  30. title: config.title,
  31. icon: null,
  32. img: require(`packages/G2Plots/images/componentLogo/${config.title}.png`),
  33. className:
  34. 'com.gccloud.dataroom.core.module.chart.components.CustomComponentChart',
  35. w: config?.option?.width || 450,
  36. h: config?.option?.height || 320,
  37. x: 0,
  38. y: 0,
  39. type: 'customComponent',
  40. chartType: config.chartType,
  41. option: {
  42. ...config.option,
  43. ..._.cloneDeep(settingConfig)
  44. },
  45. setting: config.setting, // 右侧面板自定义配置
  46. dataHandler: config.dataHandler, // 数据自定义处理js脚本
  47. optionHandler: config.optionHandler, // 配置自定义处理js脚本
  48. ..._.cloneDeep(dataConfig)
  49. }
  50. }
  51. return plotList
  52. }
  53. export function getCustomPlots () {
  54. const customList = window.BS_CONFIG?.customPlots || []
  55. const list = []
  56. customList.forEach((config) => {
  57. list.push({
  58. category: config.category,
  59. name: config.name,
  60. title: config.title,
  61. icon: null,
  62. img: config.img,
  63. className:
  64. 'com.gccloud.dataroom.core.module.chart.components.CustomComponentChart',
  65. w: 450,
  66. h: 320,
  67. x: 0,
  68. y: 0,
  69. type: 'customComponent',
  70. chartType: config.chartType,
  71. option: {
  72. ...config.option,
  73. ..._.cloneDeep(settingConfig)
  74. },
  75. setting: config.setting, // 右侧面板自定义配置
  76. dataHandler: config.dataHandler, // 数据自定义处理js脚本
  77. optionHandler: config.optionHandler, // 配置自定义处理js脚本
  78. ..._.cloneDeep(dataConfig)
  79. })
  80. })
  81. return list
  82. }
  83. const plots = [...plotList, ...customPlots, mapData]
  84. export default plots