echartList.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 cloneDeep from 'lodash/cloneDeep'
  8. import sortList from './echartListSort'
  9. // 遍历 当前文件夹下的所有文件,找到中文.js文件,然后导出
  10. const files = require.context('./', true, /[\u4e00-\u9fa5]+.js$/)
  11. const echartsList = getEchartsList(files)
  12. // 获取plot配置
  13. function getEchartsList (files) {
  14. const configMapList = {}
  15. files.keys().forEach((key) => {
  16. // ./折线图/基础折线图.js
  17. // 取到 "基础折线图"
  18. const configName = key.split('/')[2].replace('.js', '')
  19. configMapList[configName] = files(key).default
  20. })
  21. const echartsList = []
  22. for (const configMapKey in configMapList) {
  23. const index = sortList.findIndex((item) => item === configMapKey)
  24. const config = configMapList[configMapKey]
  25. echartsList[index] = {
  26. version: config.version,
  27. category: configMapKey,
  28. name: config.name,
  29. title: config.title,
  30. border: { type: '', titleHeight: 60, fontSize: 30, color: ['#5B8FF9', '#61DDAA', '#5D7092', '#F6BD16', '#6F5EF9'] },
  31. icon: null,
  32. img: require(`../Echarts/images/${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: 'echartsComponent',
  40. chartType: config.chartType,
  41. loading: false,
  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 echartsList
  53. }
  54. export default echartsList