plotList.js 2.8 KB

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