remoteComponentsList.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // 得到用户自定义的远程组件列表
  2. import { dataConfig, settingConfig } from './settingConfig'
  3. // import _ from 'lodash'
  4. import cloneDeep from 'lodash/cloneDeep'
  5. const files = require.context('./innerComponents/', true, /index.vue$/)
  6. const innerRemoteComponents = []
  7. files.keys().forEach(key => {
  8. const title = key.split('/')[1].replace('.vue', '')
  9. const img = require(`./innerComponents/${title}/component.png`)
  10. const config = require(`./innerComponents/${title}/config.js`).default
  11. innerRemoteComponents.push({
  12. title: config.title || title,
  13. vueSysComponentDirName: 'inner_' + title,
  14. vueFile: files(key).default,
  15. ...config,
  16. img
  17. })
  18. })
  19. // 抛出内置系统组件
  20. export default getRemoteComponents(innerRemoteComponents)
  21. // 抛出外部的用户系统组件
  22. export function getRemoteComponents (comList) {
  23. const customList = (comList || window.BS_CONFIG?.remoteComponents) || []
  24. const list = []
  25. customList.forEach((config) => {
  26. list.push({
  27. name: config.name,
  28. title: config.title,
  29. icon: null,
  30. img: config.img,
  31. className:
  32. 'com.gccloud.dataroom.core.module.chart.components.RemoteComponentChart',
  33. w: 450,
  34. h: 320,
  35. x: 0,
  36. y: 0,
  37. type: 'remoteComponent',
  38. option: {
  39. ...cloneDeep(settingConfig),
  40. ...config.option
  41. },
  42. // 右侧面板自定义配置
  43. setting: config.setting,
  44. ...cloneDeep(dataConfig),
  45. // 自定义配置
  46. customize: {
  47. ...config.customize,
  48. vueSysComponentDirName: config.vueSysComponentDirName,
  49. vueFile: config.vueFile
  50. }
  51. })
  52. })
  53. return list
  54. }
  55. export function getRemoteComponentConfig (code, name) {
  56. const config = {
  57. name,
  58. title: name,
  59. icon: null,
  60. img: null,
  61. className:
  62. 'com.gccloud.dataroom.core.module.chart.components.RemoteComponentChart',
  63. w: 450,
  64. h: 320,
  65. x: 0,
  66. y: 0,
  67. type: 'remoteComponent',
  68. option: {
  69. ...cloneDeep(settingConfig)
  70. },
  71. // 右侧面板自定义配置
  72. setting: [],
  73. ...cloneDeep(dataConfig),
  74. // 自定义配置
  75. customize: {
  76. // 文件路径
  77. vueSysComponentDirName: null,
  78. // 用户上传的vue文件编码,根据此编码获取文件内容
  79. vueBizComponentCode: code,
  80. // vue文本内容
  81. vueFileContent: null
  82. }
  83. }
  84. return config
  85. }