plotList.js 3.2 KB

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