remoteComponentsList.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. let img = null
  10. try {
  11. img = require(`./innerComponents/${title}/component.png`)
  12. } catch (error) {
  13. console.log(error)
  14. }
  15. const config = require(`./innerComponents/${title}/config.js`).default
  16. innerRemoteComponents.push({
  17. title: config.title || title,
  18. vueSysComponentDirName: 'inner_' + title,
  19. vueFile: files(key).default,
  20. ...config,
  21. img
  22. })
  23. })
  24. // 抛出内置系统组件
  25. export default getRemoteComponents(innerRemoteComponents)
  26. // 抛出外部的用户系统组件
  27. export function getRemoteComponents (comList) {
  28. const customList = (comList || window.BS_CONFIG?.remoteComponents) || []
  29. const list = []
  30. customList.forEach((config) => {
  31. list.push({
  32. name: config.name,
  33. title: config.title,
  34. icon: null,
  35. img: config.img,
  36. border: { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [16, 16, 16, 16] },
  37. className:
  38. 'com.gccloud.dataroom.core.module.chart.components.RemoteComponentChart',
  39. w: 450,
  40. h: 320,
  41. x: 0,
  42. y: 0,
  43. rotateX: config.rotateX || 0,
  44. rotateY: config.rotateY || 0,
  45. rotateZ: config.rotateZ || 0,
  46. perspective: config.perspective || 500,
  47. skewX: config.skewX || 0,
  48. skewY: config.skewY || 0,
  49. type: 'remoteComponent',
  50. option: {
  51. ...cloneDeep(settingConfig),
  52. ...config.option
  53. },
  54. // 右侧面板自定义配置
  55. setting: config.setting,
  56. ...cloneDeep(dataConfig),
  57. // 自定义配置
  58. customize: {
  59. ...config.customize,
  60. vueSysComponentDirName: config.vueSysComponentDirName,
  61. vueFile: config.vueFile
  62. }
  63. })
  64. })
  65. return list
  66. }
  67. export function getRemoteComponentConfig (code, name) {
  68. const config = {
  69. name,
  70. title: name,
  71. icon: null,
  72. img: null,
  73. border: { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [16, 16, 16, 16] },
  74. className:
  75. 'com.gccloud.dataroom.core.module.chart.components.RemoteComponentChart',
  76. w: 450,
  77. h: 320,
  78. x: 0,
  79. y: 0,
  80. rotateX: 0,
  81. rotateY: 0,
  82. rotateZ: 0,
  83. perspective: 0,
  84. skewX: 0,
  85. skewY: 0,
  86. type: 'remoteComponent',
  87. option: {
  88. ...cloneDeep(settingConfig)
  89. },
  90. // 右侧面板自定义配置
  91. setting: [],
  92. ...cloneDeep(dataConfig),
  93. // 自定义配置
  94. customize: {
  95. // 文件路径
  96. vueSysComponentDirName: null,
  97. // 用户上传的vue文件编码,根据此编码获取文件内容
  98. vueBizComponentCode: code,
  99. // vue文本内容
  100. vueFileContent: null
  101. }
  102. }
  103. return config
  104. }