remoteComponentsList.js 2.9 KB

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