NewNav.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <div class="New-nav">
  4. <div class="main-title">{{ Title }}</div>
  5. <!-- menu区域 -->
  6. <div class="nav-menu">
  7. <div class="nav-menu-left">
  8. <div v-for="(item, index) in leftMenus" :key="index">
  9. <div :class="activeIndex == index ? 'nav-menu-active' : 'nav-menu-unactive'" :key="index" @click="menuClick({ item, index })">
  10. <div style="color: #ddd">{{ item.name }}</div>
  11. <div v-if="activeIndex == index && isShowMenuItem" class="nav-menu-item">
  12. <div class="nav-menu-content">
  13. <div class="nav-menu-List">
  14. <div
  15. :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"
  16. v-for="(ite, ind) in item.MenuItemList"
  17. :key="ind"
  18. @click.stop="menuItemClick(ind)"
  19. >{{ ite.name }}</div
  20. >
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="nav-menu-right">
  28. <div v-for="(item, index) in rightMenus" :key="index + 4">
  29. <div
  30. :class="activeIndex == index + 4 ? 'nav-menu-active' : 'nav-menu-unactive'"
  31. :key="index + 4"
  32. @click="menuClick({ item, index: index + 4 })"
  33. >
  34. <div style="color: #ddd">{{ item.name }}</div>
  35. <div v-if="activeIndex == index + 4 && isShowMenuItem" class="nav-menu-item">
  36. <div class="nav-menu-content">
  37. <div class="nav-menu-List">
  38. <div
  39. :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"
  40. v-for="(ite, ind) in item.MenuItemList"
  41. :key="ind"
  42. @click.stop="menuItemClick(ind)"
  43. >{{ ite.name }}</div
  44. >
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </template>
  54. <script lang="ts" setup>
  55. import { onMounted, onUnmounted, ref, watch, computed } from 'vue';
  56. import { useRouter, useRoute } from 'vue-router';
  57. let props = defineProps({
  58. Title: {
  59. type: String,
  60. default: '',
  61. },
  62. });
  63. let menuList = ref<any[]>([
  64. {
  65. name: '智能通风',
  66. targatUrl: '/micro-vent-3dModal/configurable/ventNew/home',
  67. },
  68. {
  69. name: '火灾监控',
  70. targatUrl: '/micro-vent-3dModal/configurable/fireNew/home',
  71. },
  72. {
  73. name: '粉尘监控',
  74. targatUrl: '/micro-vent-3dModal/configurable/dustNew/home',
  75. },
  76. {
  77. name: '瓦斯监控',
  78. MenuItemList: [
  79. { name: '多灾融合预警' },
  80. { name: '通风监测预警' },
  81. { name: '火灾监测预警' },
  82. { name: '粉尘监测预警' },
  83. { name: '瓦斯监测预警' },
  84. ],
  85. },
  86. {
  87. name: '灾害预警',
  88. MenuItemList: [
  89. { name: '多灾融合预警' },
  90. { name: '通风监测预警' },
  91. { name: '火灾监测预警' },
  92. { name: '粉尘监测预警' },
  93. { name: '瓦斯监测预警' },
  94. ],
  95. },
  96. ]); //一级菜单列表
  97. let activeIndex = ref(0); //当前激活menu索引
  98. const router = useRouter();
  99. const route = useRoute();
  100. let isShowMenuItem = ref(false); //是否显示menuItem下拉选项菜单
  101. let menuItemActive = ref(0); //menuItem当前激活选项
  102. const leftMenus = computed(() => menuList.value.slice(0, 4));
  103. const rightMenus = computed(() => menuList.value.slice(4));
  104. function menuClick(data) {
  105. activeIndex.value = data.index;
  106. isShowMenuItem.value = !isShowMenuItem.value;
  107. router.push({ path: data.item.targatUrl });
  108. }
  109. function menuItemClick(index) {
  110. menuItemActive.value = index;
  111. isShowMenuItem.value = false;
  112. }
  113. function updateActiveState(path: string) {
  114. menuList.value.forEach((menu, index) => {
  115. // 处理有直接链接的菜单项
  116. if (menu.targatUrl === path) {
  117. activeIndex.value = index;
  118. isShowMenuItem.value = false;
  119. return;
  120. }
  121. // 处理有子菜单的菜单项
  122. if (menu.MenuItemList) {
  123. const itemIndex = menu.MenuItemList.findIndex((item) => item.targatUrl === path);
  124. if (itemIndex !== -1) {
  125. activeIndex.value = index;
  126. menuItemActive.value = itemIndex;
  127. isShowMenuItem.value = true;
  128. }
  129. }
  130. });
  131. }
  132. watch(
  133. () => route.path,
  134. (newPath) => {
  135. updateActiveState(newPath);
  136. }
  137. );
  138. onMounted(() => {
  139. updateActiveState(route.path);
  140. });
  141. </script>
  142. <style lang="less" scoped>
  143. @import '/@/design/theme.less';
  144. @font-face {
  145. font-family: 'douyuFont';
  146. src: url('/@/assets/font/douyuFont.otf');
  147. }
  148. .New-nav {
  149. position: relative;
  150. width: 100%;
  151. height: 100%;
  152. .main-title {
  153. width: 518px;
  154. height: 100%;
  155. display: flex;
  156. align-items: center;
  157. font-family: 'douyuFont';
  158. font-size: 25px;
  159. position: absolute;
  160. left: 50%;
  161. transform: translateX(-50%);
  162. width: auto;
  163. padding: 0;
  164. }
  165. .nav-menu {
  166. position: absolute;
  167. top: 0;
  168. left: 675px;
  169. height: 100%;
  170. display: flex;
  171. position: static; // 移除绝对定位
  172. display: flex;
  173. width: auto;
  174. .nav-menu-left {
  175. display: flex;
  176. flex-direction: row;
  177. align-items: center;
  178. float: left;
  179. }
  180. .nav-menu-right {
  181. display: flex;
  182. flex-direction: row;
  183. align-items: center;
  184. float: left;
  185. margin-left: 40%;
  186. }
  187. .nav-menu-active {
  188. position: relative;
  189. cursor: pointer;
  190. width: 120px;
  191. height: 60px;
  192. margin-top: 20px;
  193. line-height: 45px;
  194. text-align: center;
  195. font-size: 16px;
  196. letter-spacing: 2px;
  197. background: url('@/assets/images/vent/homeNew/Select-btn.png') no-repeat;
  198. background-size: 100% 100%;
  199. }
  200. .nav-menu-unactive {
  201. position: relative;
  202. width: 120px;
  203. height: 60px;
  204. line-height: 65px;
  205. text-align: center;
  206. margin: 0px 10px;
  207. font-size: 16px;
  208. letter-spacing: 2px;
  209. background-size: 100% 100%;
  210. cursor: pointer;
  211. }
  212. .nav-menu-item {
  213. position: absolute;
  214. top: 23px;
  215. width: 130px;
  216. display: flex;
  217. flex-direction: column;
  218. align-items: center;
  219. box-sizing: border-box;
  220. .nav-menu-content {
  221. width: 100%;
  222. height: 100%;
  223. overflow-y: auto;
  224. margin-top: 25%;
  225. .nav-menu-List {
  226. background: url('@/assets/images/vent/homeNew/menuList.png') no-repeat;
  227. background-size: 100% 100%;
  228. }
  229. .menu-item-active {
  230. color: #ddd;
  231. z-index: 999;
  232. width: 100%;
  233. height: 36px;
  234. line-height: 36px;
  235. font-size: 14px;
  236. background: url('@/assets/images/vent/homeNew/selectActive.png') no-repeat;
  237. background-size: 100% 100%;
  238. }
  239. .menu-item-unactive {
  240. color: #ddd;
  241. width: 100%;
  242. height: 40px;
  243. line-height: 40px;
  244. font-size: 14px;
  245. }
  246. }
  247. }
  248. @keyframes fadeIn {
  249. from {
  250. opacity: 0;
  251. }
  252. to {
  253. opacity: 1;
  254. }
  255. }
  256. /* 定义淡出动画 */
  257. @keyframes fadeOut {
  258. from {
  259. opacity: 1;
  260. }
  261. to {
  262. opacity: 0;
  263. }
  264. }
  265. }
  266. .userInfo {
  267. width: 120px;
  268. float: right;
  269. background: url(/src/assets/images/vent/homeNew/user.png) no-repeat;
  270. background-size: 100% 100%;
  271. position: absolute;
  272. top: 14px;
  273. right: 0;
  274. .userName {
  275. margin-left: 40px;
  276. font-size: 20px;
  277. }
  278. }
  279. }
  280. </style>