index.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type { App } from 'vue'
  2. import { ChartList } from '@/packages/components/Charts/index'
  3. import { DecorateList } from '@/packages/components/Decorates/index'
  4. import { InformationList } from '@/packages/components/Informations/index'
  5. import { TableList } from '@/packages/components/Tables/index'
  6. import {
  7. PackagesCategoryEnum,
  8. PackagesType,
  9. ConfigType,
  10. FetchComFlagType
  11. } from '@/packages/index.d'
  12. const configModules = import.meta.globEager("./components/**/config.vue")
  13. const indexModules = import.meta.globEager("./components/**/index.vue")
  14. // * 所有图表
  15. export let packagesList: PackagesType = {
  16. [PackagesCategoryEnum.CHARTS]: ChartList,
  17. [PackagesCategoryEnum.INFORMATION]: InformationList,
  18. [PackagesCategoryEnum.TABLES]: TableList,
  19. [PackagesCategoryEnum.DECORATES]: DecorateList
  20. }
  21. /**
  22. * * 获取目标拖拽组件配置信息
  23. * @param dropData
  24. */
  25. export const createComponent = async (dropData: ConfigType) => {
  26. const { category, key } = dropData
  27. const chart = await import(`./components/${dropData.package}/${category}/${key}/config.ts`)
  28. return new chart.default()
  29. }
  30. /**
  31. * * 获取组件
  32. * @param {string} chartName 名称
  33. * @param {FetchComFlagType} flag 标识 0为展示组件, 1为配置组件
  34. */
  35. const fetchComponent = (chartName: string, flag: FetchComFlagType) => {
  36. const module = flag === FetchComFlagType.VIEW ? indexModules: configModules
  37. for (const key in module) {
  38. const urlSplit = key.split('/')
  39. if(urlSplit[urlSplit.length -2 ] === chartName) {
  40. return module[key]
  41. }
  42. }
  43. }
  44. /**
  45. * * 获取展示组件
  46. * @param {ConfigType} dropData 配置项
  47. */
  48. export const fetchChartComponent = (dropData: ConfigType) => {
  49. const { key } = dropData
  50. return fetchComponent(key, FetchComFlagType.VIEW)?.default
  51. }
  52. /**
  53. * * 获取配置组件
  54. * @param {ConfigType} dropData 配置项
  55. */
  56. export const fetchConfigComponent = (dropData: ConfigType) => {
  57. const { key } = dropData
  58. return fetchComponent(key, FetchComFlagType.CONFIG)?.default
  59. }