SideMenu.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div>
  3. <div class="bigBox">
  4. <template v-for="(item, index) in menuList">
  5. <div class="menuBox" @click="routeBoxClick(item)">
  6. <img :style="{ 'background': item.isChosen ? 'linear-gradient(138deg, #F1F3F9 0%, #F1F3F9 100%)' : 'none' }"
  7. :src="item.isChosen ? item.isChoose : item.noChoose" class="rImg" alt="">
  8. <p class="rp">{{ item.name }}</p>
  9. </div>
  10. </template>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. import { ref, onMounted } from 'vue'
  16. import { useRouter, useRoute } from 'vue-router'
  17. import allImg from "../../../src/utils/allImg.js"
  18. export default {
  19. setup() {
  20. let menuList = ref([
  21. {
  22. name: "检测任务",
  23. route: "/home/mission",
  24. id: 1,
  25. noChoose: allImg.searchGray,
  26. isChoose: allImg.searchBlue,
  27. isChosen: true
  28. },
  29. {
  30. name: "报告结果",
  31. route: "/home/report",
  32. id: 2,
  33. noChoose: allImg.reportGray,
  34. isChoose: allImg.reportBlue,
  35. isChosen: false
  36. },
  37. {
  38. name: "基础设置",
  39. route: "/home/setting",
  40. id: 3,
  41. noChoose: allImg.settingGray,
  42. isChoose: allImg.settingBlue,
  43. isChosen: false
  44. },
  45. {
  46. name: "系统管理",
  47. route: "/home/system",
  48. id: 4,
  49. noChoose: allImg.systemGray,
  50. isChoose: allImg.systemBlue,
  51. isChosen: false
  52. },
  53. ])//路由菜单
  54. let router = useRouter()//初始化路由实例
  55. let route = useRoute()//获取路由信息
  56. // 路由盒子
  57. function routeBoxClick(row) {
  58. // 设置所有菜单项的 isChosen 为 false
  59. menuList.value.forEach((item) => {
  60. item.isChosen = false;
  61. });
  62. // 设置当前点击的菜单项为 isChosen
  63. row.isChosen = true;
  64. router.push(row.route)
  65. }
  66. // 拿到路由信息
  67. function getRoute() {
  68. let path = route.path
  69. menuList.value.forEach(item => {
  70. item.isChosen = item.route === path;
  71. });
  72. }
  73. onMounted(() => {
  74. getRoute()
  75. })
  76. return {
  77. menuList,//路由菜单
  78. routeBoxClick,//路由盒子点击事件
  79. getRoute,//拿到路由信息
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped>
  85. p {
  86. margin: 0;
  87. padding: 0;
  88. }
  89. .bigBox {
  90. width: 95px;
  91. height: auto;
  92. margin: 0 auto;
  93. margin-top: 25px;
  94. overflow-y: hidden;
  95. }
  96. .menuBox {
  97. width: 80px;
  98. height: 60px;
  99. text-align: center;
  100. line-height: 25px;
  101. cursor: pointer;
  102. margin-bottom: 10px;
  103. }
  104. .rImg {
  105. display: block;
  106. width: 40px;
  107. height: 40px;
  108. border-radius: 5px;
  109. margin: 0 auto;
  110. /* border-image: linear-gradient(171deg, rgba(215, 237, 255, 1), rgba(158, 210, 253, 1)) 0 0; */
  111. }
  112. .rp {
  113. width: 80px;
  114. height: 30px;
  115. font-size: 14px;
  116. font-family: Source Han Sans CN, Source Han Sans CN;
  117. font-weight: 400;
  118. color: #1A2447;
  119. line-height: 22px;
  120. -webkit-background-clip: text;
  121. /* -webkit-text-fill-color: transparent; */
  122. }
  123. </style>