index.vue 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <component :is="menuComponent" :item-or-menu="item">
  3. <template v-if="item.children && item.children.length > 0">
  4. <vab-menu v-for="route in item.children" :key="route.path" :item="route" />
  5. </template>
  6. </component>
  7. </template>
  8. <script lang="ts" setup>
  9. defineOptions({
  10. name: 'VabMenu',
  11. })
  12. interface ComponentType {
  13. default: Component
  14. }
  15. const imports = import.meta.glob<ComponentType>('./**/*.vue', { eager: true })
  16. const Components: Record<string, Component> = {}
  17. Object.getOwnPropertyNames(imports).forEach((key) => {
  18. Components[key.replaceAll(/(\/|components|\.|vue)/g, '')] = imports[key].default
  19. })
  20. const props = defineProps({
  21. item: {
  22. type: Object,
  23. required: true,
  24. },
  25. layout: {
  26. type: String,
  27. default: '',
  28. },
  29. })
  30. const menuComponent = computed(() =>
  31. props.item.children &&
  32. props.item.children.some((route: any) => {
  33. return route.meta && route.meta.hidden !== true
  34. })
  35. ? Components['VabSubMenu']
  36. : Components['VabMenuItem']
  37. )
  38. </script>