remoteComponentsList.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. border:{type:''},
  32. className:
  33. 'com.gccloud.dataroom.core.module.chart.components.RemoteComponentChart',
  34. w: 450,
  35. h: 320,
  36. x: 0,
  37. y: 0,
  38. type: 'remoteComponent',
  39. option: {
  40. ...cloneDeep(settingConfig),
  41. ...config.option
  42. },
  43. // 右侧面板自定义配置
  44. setting: config.setting,
  45. ...cloneDeep(dataConfig),
  46. // 自定义配置
  47. customize: {
  48. ...config.customize,
  49. vueSysComponentDirName: config.vueSysComponentDirName,
  50. vueFile: config.vueFile
  51. }
  52. })
  53. })
  54. return list
  55. }
  56. export function getRemoteComponentConfig (code, name) {
  57. const config = {
  58. name,
  59. title: name,
  60. icon: null,
  61. img: null,
  62. border:{type:''},
  63. className:
  64. 'com.gccloud.dataroom.core.module.chart.components.RemoteComponentChart',
  65. w: 450,
  66. h: 320,
  67. x: 0,
  68. y: 0,
  69. type: 'remoteComponent',
  70. option: {
  71. ...cloneDeep(settingConfig)
  72. },
  73. // 右侧面板自定义配置
  74. setting: [],
  75. ...cloneDeep(dataConfig),
  76. // 自定义配置
  77. customize: {
  78. // 文件路径
  79. vueSysComponentDirName: null,
  80. // 用户上传的vue文件编码,根据此编码获取文件内容
  81. vueBizComponentCode: code,
  82. // vue文本内容
  83. vueFileContent: null
  84. }
  85. }
  86. return config
  87. }