remoteComponentsList.js 2.3 KB

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