componentImport.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. /* eslint-disable no-useless-escape */
  2. /*
  3. * @description: 批量导入pc端大屏组件
  4. * @Date: 2023-03-13 10:04:58
  5. * @Author: xing.heng
  6. * @LastEditors: xing.heng
  7. * @LastEditTime: 2023-05-17 12:40:25
  8. */
  9. const modules = {}
  10. // 组件名称替换
  11. const replaceName = {}
  12. // 排除的组件
  13. const excludeCommponents = []
  14. function importComponents (files) {
  15. files.keys().forEach(key => {
  16. // 正则,取到./和/之间的字符串
  17. const reg = new RegExp('(.\\/)(.*)(\\/)')
  18. let moduleName = key.match(reg)[0].replace(/(\.\/)|(\/)|(src)/g, '')
  19. // 替换组件名称
  20. if (replaceName[moduleName]) {
  21. moduleName = replaceName[moduleName]
  22. }
  23. if (!excludeCommponents.includes(moduleName)) {
  24. modules[moduleName] = files(key).default
  25. }
  26. })
  27. }
  28. importComponents(require.context('data-room-ui/BasicComponents', true, /\index.vue$/))
  29. importComponents(require.context('data-room-ui/Borders', true, /\index.vue$/))
  30. importComponents(require.context('data-room-ui/Decorations', true, /\index.vue$/))
  31. export default modules