plotList.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 'data-room-ui/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. version: config.version,
  29. category: configMapKey,
  30. name: config.name,
  31. title: config.title,
  32. icon: null,
  33. img: require(`../G2Plots/images/componentLogo/${config.title}.png`),
  34. className:
  35. 'com.gccloud.dataroom.core.module.chart.components.CustomComponentChart',
  36. w: config?.option?.width || 450,
  37. h: config?.option?.height || 320,
  38. x: 0,
  39. y: 0,
  40. type: 'customComponent',
  41. chartType: config.chartType,
  42. option: {
  43. ...config.option,
  44. ..._.cloneDeep(settingConfig)
  45. },
  46. setting: config.setting, // 右侧面板自定义配置
  47. dataHandler: config.dataHandler, // 数据自定义处理js脚本
  48. optionHandler: config.optionHandler, // 配置自定义处理js脚本
  49. ..._.cloneDeep(dataConfig)
  50. }
  51. }
  52. return plotList
  53. }
  54. export function getCustomPlots () {
  55. const customList = window.BS_CONFIG?.customPlots || []
  56. const list = []
  57. customList.forEach((config) => {
  58. list.push({
  59. category: config.category,
  60. name: config.name,
  61. title: config.title,
  62. icon: null,
  63. img: config.img,
  64. className:
  65. 'com.gccloud.dataroom.core.module.chart.components.CustomComponentChart',
  66. w: 450,
  67. h: 320,
  68. x: 0,
  69. y: 0,
  70. type: 'customComponent',
  71. chartType: config.chartType,
  72. option: {
  73. ...config.option,
  74. ..._.cloneDeep(settingConfig)
  75. },
  76. setting: config.setting, // 右侧面板自定义配置
  77. dataHandler: config.dataHandler, // 数据自定义处理js脚本
  78. optionHandler: config.optionHandler, // 配置自定义处理js脚本
  79. ..._.cloneDeep(dataConfig)
  80. })
  81. })
  82. return list
  83. }
  84. const plots = [...plotList, ...customPlots, mapData]
  85. export default plots