Sidebar.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!-- eslint-disable vue/no-deprecated-slot-attribute -->
  2. <template>
  3. <div id="Sidebar">
  4. <el-row class="sidebar">
  5. <el-col :span="24" class="main">
  6. <el-col :span="24" class="first">
  7. <img :src="siteInfo.logo_url" class="logo-image" />
  8. <span class="logo-title">{{ $t('login.title') }}</span>
  9. </el-col>
  10. <el-col :span="24" class="second">
  11. <el-menu class="sidebar-el-menu" :default-active="onRoutes" unique-opened router background-color="#304156" text-color="#bfcbd9" active-text-color="#409eff">
  12. <menu-item :items="items"></menu-item>
  13. </el-menu>
  14. </el-col>
  15. </el-col>
  16. </el-row>
  17. </div>
  18. </template>
  19. <script setup>
  20. import { siteInfo } from '@/layout/site'
  21. import { UserStore } from '@/store/user'
  22. import menuItem from './sidebar/items.vue'
  23. import { useRoute } from 'vue-router'
  24. const route = useRoute()
  25. const onRoutes = ref(route.path)
  26. const userStore = UserStore()
  27. let items = ref(userStore.menus)
  28. const user = computed(() => userStore.user)
  29. const getMenu = async () => {
  30. const menus = user.value.menus
  31. const newMenus = [...menus]
  32. items.value = newMenus
  33. }
  34. watch(
  35. user,
  36. (newVal) => {
  37. if (newVal && newVal._id) {
  38. if (newVal && newVal._id) getMenu()
  39. else ElMessage({ message: `暂无用户信息,无法获取菜单信息`, type: 'error' })
  40. }
  41. },
  42. {
  43. deep: true
  44. }
  45. )
  46. watch(
  47. route,
  48. (newVal) => {
  49. if (newVal && newVal.path) onRoutes.value = newVal.path
  50. },
  51. {
  52. immediate: true //初始化立即执行
  53. }
  54. )
  55. </script>
  56. <style scoped lang="scss">
  57. .sidebar::-webkit-scrollbar {
  58. width: 0;
  59. }
  60. .sidebar > ul {
  61. height: 100%;
  62. }
  63. .main {
  64. .first {
  65. display: flex;
  66. align-items: center;
  67. justify-content: center;
  68. height: 50px;
  69. background-color: #242f42;
  70. .logo-image {
  71. width: 20px;
  72. height: 20px;
  73. }
  74. .logo-title {
  75. margin-left: 10px;
  76. font-size: 14px;
  77. font-weight: bold;
  78. color: white;
  79. }
  80. }
  81. .second {
  82. padding: 0 2px 0 0;
  83. .el-menu {
  84. border-right: none;
  85. }
  86. .iconfont {
  87. font-size: 18px;
  88. margin: 0 5px 0 0;
  89. }
  90. }
  91. }
  92. </style>