index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <a-button
  3. v-if="isMobile"
  4. class="open-icon"
  5. type="primary"
  6. @click="openDrawer"
  7. >
  8. <right-outlined />
  9. </a-button>
  10. <a-drawer
  11. placement="left"
  12. :closable="false"
  13. :open="drawerVisible"
  14. :get-container="false"
  15. :style="{ position: 'absolute' }"
  16. width="240px"
  17. @close="drawerVisible = false"
  18. >
  19. <a-layout-sider
  20. :trigger="null"
  21. v-model:collapsed="collapsed"
  22. collapsible
  23. :style="{backgroundColor: bgColor, overflow: 'hidden'}"
  24. >
  25. <a-menu
  26. v-model:selectedKeys="selectedKeys"
  27. :openKeys="openKeys"
  28. mode="inline"
  29. :style="{ borderRight: 0 }"
  30. >
  31. <sidebar-item
  32. :item="route"
  33. v-for="route in sidebarRoute"
  34. :key="route.path"
  35. :base-path="route.path"
  36. />
  37. </a-menu>
  38. </a-layout-sider>
  39. </a-drawer>
  40. <a-layout-sider
  41. v-if="!isMobile"
  42. v-model:collapsed="collapsed"
  43. collapsible
  44. :style="{backgroundColor: bgColor, overflow: 'hidden', overflowY: 'scroll'}"
  45. breakpoint="lg"
  46. >
  47. <div class="logo" >
  48. <img :src="logoPng" alt="">
  49. </div>
  50. <a-menu
  51. v-model:selectedKeys="selectedKeys"
  52. :openKeys="openKeys"
  53. mode="inline"
  54. :style="{ borderRight: 0 }"
  55. >
  56. <sidebar-item
  57. :item="route"
  58. v-for="route in sidebarRoute"
  59. :key="route.path"
  60. :base-path="route.path"
  61. />
  62. </a-menu>
  63. </a-layout-sider>
  64. </template>
  65. <script lang="ts" setup >
  66. import { ref, computed, watch } from 'vue'
  67. import SidebarItem from './SidebarItem.vue'
  68. import { useRouter, useRoute } from 'vue-router'
  69. import { useDesignStore } from '@/store'
  70. import { useDeviceType } from '@/hooks'
  71. import { RightOutlined } from '@ant-design/icons-vue'
  72. import { routes } from '@/router/index'
  73. const logoPng = require('@/assets/logo.png')
  74. const designStore = useDesignStore()
  75. const isMobile = useDeviceType()
  76. const bgColor = computed(() => designStore.theme ? '#141414' : '#fff')
  77. const route = useRoute()
  78. const router = useRouter()
  79. const collapsed = ref<boolean>(true)
  80. const sidebarRoute = ref<any>()
  81. const selectedKeys = ref<string[]>()
  82. const openKeys = ref<string[]>()
  83. const drawerVisible = ref<boolean>(false)
  84. watch(
  85. () => route.path,
  86. () => {
  87. sidebarRoute.value = isMobile ? routes : router.getRoutes().find(item => item.path === route.matched[0].path)?.children
  88. selectedKeys.value = [route.path]
  89. openKeys.value = [route.matched[1].path]
  90. },
  91. {
  92. immediate: true
  93. }
  94. )
  95. const openDrawer = () => drawerVisible.value = true
  96. </script>
  97. <style lang="less" scoped >
  98. /deep/ .ant-layout-sider-children {
  99. margin-top: -4px;
  100. }
  101. .ant-layout-sider::-webkit-scrollbar {
  102. width: 0;
  103. }
  104. .logo {
  105. width: 100%;
  106. height: 64px;
  107. margin: 20px 0px;
  108. margin-top: 0px;
  109. display: flex;
  110. justify-content: center;
  111. align-items: center;
  112. background-color: transparent;
  113. img {
  114. width: 150px;
  115. height: 50px;
  116. }
  117. }
  118. .mobile-sider {
  119. width: 100vw;
  120. height: 100vh;
  121. background-color: rgba(0, 0, 0, 0.5);
  122. pointer-events: none;
  123. }
  124. .open-icon {
  125. width: 50px;
  126. height: 50px;
  127. position: fixed;
  128. top: 200px;
  129. left: 0px;
  130. z-index: 999;
  131. display: flex;
  132. justify-content: center;
  133. align-items: center;
  134. border-top-left-radius: 0px;
  135. border-bottom-left-radius: 0px;
  136. }
  137. </style>