石墨仪设备 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.2 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. <template>
  2. <div class="menu flex justify-center">
  3. <van-sidebar v-model="active" :active="activeName" class="sidebar">
  4. <van-sidebar-item v-for="(menu,index) in muneList" :key="menu.id" class="menn_text menn_btn" @click="goPage(menu, index)">
  5. <template #title scoped>
  6. <div class="menn_li">
  7. <div><img :src="active == index ? menu.s_icon : menu.n_icon" class="menu_icon" /></div>
  8. <div>{{ menu.name }}</div>
  9. </div>
  10. </template>
  11. </van-sidebar-item>
  12. </van-sidebar>
  13. </div>
  14. </template>
  15. <script lang="ts" setup>
  16. import { ref, onMounted } from "vue";
  17. import { useRouter, useRoute } from "vue-router";
  18. import { getMenus } from "./menu.ts";
  19. const router = useRouter();
  20. const route = useRoute();
  21. const imageModules: any = import.meta.glob("@/assets/menuIcon/*.svg");
  22. const importedImages: any = {};
  23. const onHeadleIcon = async () => {
  24. for (const path in imageModules) {
  25. let pst = await imageModules[path]();
  26. importedImages[path] = pst.default;
  27. }
  28. };
  29. const active = ref(0);
  30. const activeName = ref('')
  31. interface Menu {
  32. id: number;
  33. name: string;
  34. s_icon: string;
  35. n_icon: string;
  36. path: string;
  37. }
  38. const goPage = (menu: Menu, index:any) => {
  39. active.value = index;
  40. activeName.value = menu.name
  41. router.push(`${menu.path}`);
  42. };
  43. const muneList: any = ref([]);
  44. onMounted(async () => {
  45. await onHeadleIcon();
  46. let path = route.path;
  47. muneList.value = getMenus();
  48. //@ts-ignore
  49. muneList.value.forEach(item => {
  50. if (item.path === path) {
  51. active.value = item.id;
  52. }
  53. });
  54. });
  55. </script>
  56. <style lang="scss" scoped>
  57. .menu {
  58. width: var(--menuAreaWidth);
  59. .sidebar {
  60. width: calc(var(--menuAreaWidth) - 2.5rem);
  61. font-size: 1rem;
  62. }
  63. @media (max-width: 790px) {
  64. .sidebar {
  65. width: 100%;
  66. }
  67. .menn_btn {
  68. border-radius: 0;
  69. }
  70. }
  71. }
  72. .menn_text {
  73. font-size: 1rem;
  74. margin-top: 0.625rem;
  75. }
  76. .van-sidebar {
  77. --van-sidebar-active-color: #0088cc; /* 设置激活项颜色为蓝色 */
  78. /* --van-sidebar-background: red; */
  79. --van-sidebar-selected-background: #1989fa;
  80. }
  81. .menn_btn {
  82. border-radius: 10px;
  83. height: 3.125rem;
  84. display: flex;
  85. align-items: center;
  86. }
  87. .menn_li {
  88. display: flex;
  89. align-items: center;
  90. gap: 5px;
  91. }
  92. .menu_icon {
  93. width: 2.5rem;
  94. height: 2.5rem;
  95. }
  96. </style>