CpmdHeader.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <script setup lang="ts">
  2. // import router from '@/router';
  3. import { ref } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. const router = useRouter()
  6. import { menuStatusStore } from '@/stores';
  7. // import url from '../assets/home/trademark.png';
  8. //选中的索引
  9. const menuStatus = menuStatusStore()
  10. const activeIndex = ref<string>()
  11. activeIndex.value = menuStatus.activeIndex
  12. //选中菜单事件
  13. const handleSelect = (key: string, keyPath: []) => {
  14. console.log(key, keyPath)
  15. menuStatus.saveActiveIndex(key)
  16. activeIndex.value = key;
  17. if (key == '1') {
  18. router.push({ name: 'homeView' })
  19. } else if (key == '2') {
  20. router.push({ name: 'popularizationScience' })
  21. } else if (key == '3') {
  22. router.push({ name: 'community', })
  23. } else if (key == '4') {
  24. router.push({ name: 'plan', })
  25. } else if (key == '5') {
  26. router.push({ name: 'testRecord' })
  27. }
  28. // menuStatus.saveActiveIndex(key)
  29. }
  30. //点击登录按钮
  31. const login = () => {
  32. menuStatus.saveActiveIndex('6')
  33. router.push({ name: 'login', params: {} })
  34. }
  35. </script>
  36. <template>
  37. <div class="header_p">
  38. <div class="header_image">
  39. <img style="width: 239px; height: 55px" src="../assets/home/trademark.png"></img>
  40. </div>
  41. <el-menu :default-active="activeIndex" class="el-menu-demo" style="display: flex;" mode="horizontal"
  42. :ellipsis="false" @select="handleSelect">
  43. <el-menu-item index="1">首页</el-menu-item>
  44. <el-menu-item index="2">科普乐园</el-menu-item>
  45. <el-menu-item index="3">留言社区</el-menu-item>
  46. <!-- <el-badge :value="200" :max="99" class="item">
  47. <el-menu-item index="4">测试计划</el-menu-item>
  48. </el-badge> -->
  49. <el-menu-item index="4">
  50. <div class="badge_custom">
  51. 122
  52. </div>
  53. <span>测试计划</span>
  54. </el-menu-item>
  55. <el-menu-item index="5">测试记录</el-menu-item>
  56. </el-menu>
  57. <div class="login_button_bg" @click="login">
  58. <img width="20px" src="../assets/home/button_login.png" />
  59. &nbsp;&nbsp;&nbsp;&nbsp;
  60. <span>登录账号</span>
  61. </div>
  62. <!-- <div class="menu_gen">首页</div>
  63. <div class="menu_gen">科普乐园</div>
  64. <div class="menu_gen">留言社区</div>
  65. <div class="menu_gen">测试计划</div>
  66. <div class="menu_gen">测试记录</div>
  67. <div class="menu_gen">登录账号</div> -->
  68. </div>
  69. </template>
  70. <style lang="scss" scoped>
  71. .el-menu {
  72. background-color: transparent !important
  73. }
  74. .badge_custom {
  75. position: absolute;
  76. background-color: #48D68E;
  77. left: 90px;
  78. top: 0px;
  79. line-height: 18px;
  80. color: 10px;
  81. padding: 0px 8px;
  82. font-weight: 300;
  83. font-size: 10px;
  84. color: #ffffff;
  85. border-top-left-radius: 20px;
  86. border-top-right-radius: 20px;
  87. border-bottom-right-radius: 20px;
  88. }
  89. //整个菜单底部样式
  90. .el-menu--horizontal.el-menu {
  91. border-bottom: 0px solid var(--el-menu-border-color);
  92. display: flex;
  93. align-items: center;
  94. }
  95. .el-menu--horizontal>.el-menu-item {
  96. width: 120px;
  97. height: 40px;
  98. align-items: center;
  99. border-bottom: 0px solid transparent;
  100. color: var(--el-menu-text-color);
  101. display: inline-flex;
  102. // height: 100%;
  103. justify-content: center;
  104. align-items: center;
  105. border-radius: 12px;
  106. margin: 0;
  107. }
  108. .el-menu--horizontal .el-menu-item:not(.is-disabled):focus,
  109. .el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
  110. background-color: #48D68E;
  111. color: #000000 !important;
  112. border-radius: 12px;
  113. }
  114. //激活某个菜单时 底部样式
  115. .el-menu--horizontal>.el-menu-item.is-active {
  116. border-bottom: 0px solid var(--el-menu-active-color);
  117. // color: var(--el-menu-active-color) !important;
  118. color: #000000 !important;
  119. background: #48D68E;
  120. border-radius: 12px;
  121. height: 40px;
  122. font-weight: 700;
  123. }
  124. .header_p {
  125. padding-top: 20px;
  126. display: flex;
  127. flex-direction: row;
  128. align-items: center;
  129. justify-content: space-between;
  130. .header_image {
  131. // flex: 1
  132. margin-right: 100px;
  133. }
  134. .login_button_bg {
  135. background-color: #000000;
  136. border-radius: 12px;
  137. border: 3px solid #48D68E;
  138. color: #ffffff;
  139. padding: 8px 20px;
  140. cursor: pointer;
  141. display: flex;
  142. align-items: center;
  143. }
  144. .flex-grow {
  145. flex: 1;
  146. }
  147. .menu_gen {
  148. width: 80px;
  149. height: 20px;
  150. font-family: Alibaba PuHuiTi 2.0;
  151. font-weight: normal;
  152. font-size: 20px;
  153. color: #333333;
  154. line-height: 26px
  155. }
  156. }
  157. </style>