index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <component :is="menuComponent" v-if="!item.meta.hidden" :item-or-menu="item">
  3. <template v-if="item.children && item.children.length">
  4. <el-scrollbar
  5. v-if="
  6. (layout === 'horizontal' && item.children.length > 18) ||
  7. (layout !== 'horizontal' && collapse && item.children.length > 18)
  8. "
  9. class="vab-menu-children-height"
  10. >
  11. <vab-menu
  12. v-for="route in item.children"
  13. :key="route.path"
  14. :item="route"
  15. />
  16. </el-scrollbar>
  17. <template v-else>
  18. <vab-menu
  19. v-for="route in item.children"
  20. :key="route.path"
  21. :item="route"
  22. />
  23. </template>
  24. </template>
  25. </component>
  26. </template>
  27. <script lang="ts">
  28. /* 防止偶发性自动导入失败 */
  29. import { computed, defineComponent } from 'vue'
  30. import { storeToRefs } from 'pinia'
  31. import { useSettingsStore } from '@/store/modules/settings'
  32. const imports = require.context('./components', true, /\.vue$/)
  33. const Components: {
  34. [key: string]: any
  35. } = {}
  36. imports.keys().forEach((key) => {
  37. Components[key.replace(/(\/|\.|vue)/g, '')] = imports(key).default
  38. })
  39. export default defineComponent({
  40. name: 'VabMenu',
  41. components: Components,
  42. props: {
  43. item: {
  44. type: Object,
  45. required: true,
  46. },
  47. layout: {
  48. type: String,
  49. default: '',
  50. },
  51. },
  52. setup(props) {
  53. const settingsStore = useSettingsStore()
  54. const { collapse } = storeToRefs(settingsStore)
  55. const menuComponent = computed(() =>
  56. props.item.children &&
  57. props.item.children.some((_route: any) => {
  58. return _route.meta.hidden !== true
  59. })
  60. ? 'VabSubMenu'
  61. : 'VabMenuItem'
  62. )
  63. return {
  64. collapse,
  65. menuComponent,
  66. }
  67. },
  68. })
  69. </script>
  70. <style lang="scss" scoped>
  71. .vab-menu-children-height {
  72. height: 60vh !important;
  73. overflow-y: auto;
  74. &::-webkit-scrollbar {
  75. width: 0;
  76. height: 0;
  77. }
  78. }
  79. </style>
  80. <!--由于element-plus
  81. bug使用popper-append-to-body=false会导致多级路由无法显示,故所有菜单必须生成至body下,样式必须放到body下-->
  82. <style lang="scss">
  83. .el-popper.is-light {
  84. border: 0 !important;
  85. }
  86. </style>