echartList.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { dataConfig, settingConfig } from '../EchartsRender/settingConfig'
  2. import cloneDeep from 'lodash/cloneDeep'
  3. import sortList from './echartListSort'
  4. // 遍历 当前文件夹下的所有文件,找到中文.js文件,然后导出
  5. const files = require.context('./', true, /[\u4e00-\u9fa5]+.js$/)
  6. const echartsList = getEchartsList(files)
  7. // 获取echarts配置
  8. function getEchartsList (files) {
  9. const configMapList = {}
  10. files.keys().forEach((key) => {
  11. // 取到 "基础折线图"
  12. const configName = key.split('/')[2].replace('.js', '')
  13. configMapList[configName] = files(key).default
  14. })
  15. const echartsList = []
  16. for (const configMapKey in configMapList) {
  17. const index = sortList.findIndex((item) => item === configMapKey)
  18. const config = configMapList[configMapKey]
  19. echartsList[index] = {
  20. version: config.version,
  21. category: configMapKey,
  22. name: config.name,
  23. title: config.title,
  24. border: { type: '', titleHeight: 60, fontSize: 30, color: ['#5B8FF9', '#61DDAA', '#5D7092', '#F6BD16', '#6F5EF9'], padding: [16, 16, 16, 16] },
  25. icon: null,
  26. img: require(`../Echarts/images/${config.title}.png`),
  27. className:
  28. 'com.gccloud.dataroom.core.module.chart.components.CustomComponentChart',
  29. w: config?.option?.width || 450,
  30. h: config?.option?.height || 320,
  31. x: 0,
  32. y: 0,
  33. rotateX: config.rotateX || 0,
  34. rotateY: config.rotateY || 0,
  35. rotateZ: config.rotateZ || 0,
  36. perspective: config.perspective || 0,
  37. skewX: config.skewX || 0,
  38. skewY: config.skewY || 0,
  39. type: 'echartsComponent',
  40. loading: false,
  41. // 把默认右侧配置与自定义右侧配置集合
  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